blob: 1f85f0d499b863ebe529d333051b9785202f67eb [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
394 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000851 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000855 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Douglas Gregor71dc5092009-08-06 06:41:21 +00001049 /// \brief Build a new template name given a nested name specifier, a flag
1050 /// indicating whether the "template" keyword was provided, and the template
1051 /// that the template name refers to.
1052 ///
1053 /// By default, builds the new template name directly. Subclasses may override
1054 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001056 bool TemplateKW,
1057 TemplateDecl *Template);
1058
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 /// \brief Build a new template name given a nested name specifier and the
1060 /// name that is referred to as a template.
1061 ///
1062 /// By default, performs semantic analysis to determine whether the name can
1063 /// be resolved to a specific template, then builds the appropriate kind of
1064 /// template name. Subclasses may override this routine to provide different
1065 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001066 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1067 const IdentifierInfo &Name,
1068 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001069 QualType ObjectType,
1070 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor71395fa2009-11-04 00:56:37 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// overloaded operator name that is referred to as a template.
1074 ///
1075 /// By default, performs semantic analysis to determine whether the name can
1076 /// be resolved to a specific template, then builds the appropriate kind of
1077 /// template name. Subclasses may override this routine to provide different
1078 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001079 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001080 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001082 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001083
1084 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001085 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
1091 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1092 const TemplateArgument &ArgPack) {
1093 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1094 }
1095
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 /// \brief Build a new compound statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 MultiStmtArg Statements,
1102 SourceLocation RBraceLoc,
1103 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 IsStmtExpr);
1106 }
1107
1108 /// \brief Build a new case statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 ColonLoc);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Attach the body to a new case statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001126 getSema().ActOnCaseStmtBody(S, Body);
1127 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 /// \brief Build a new default statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Stmt *SubStmt) {
1137 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001138 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new label statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1146 SourceLocation ColonLoc, Stmt *SubStmt) {
1147 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Richard Smithc202b282012-04-14 00:33:13 +00001150 /// \brief Build a new label statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001154 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1155 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001156 Stmt *SubStmt) {
1157 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1158 }
1159
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 /// \brief Build a new "if" statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001167 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Start building a new switch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001175 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001176 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001177 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 }
Mike Stump11289f42009-09-09 15:08:12 +00001179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Attach the body to the switch statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001185 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001186 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new while statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001193 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1194 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001195 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new do-while statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001203 SourceLocation WhileLoc, SourceLocation LParenLoc,
1204 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001205 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1206 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new for statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001214 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 VarDecl *CondVar, Sema::FullExprArg Inc,
1216 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new goto statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1226 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001227 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new indirect goto statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001235 SourceLocation StarLoc,
1236 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 /// \brief Build a new return statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001244 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001245 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 /// \brief Build a new declaration statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001252 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001253 SourceLocation StartLoc, SourceLocation EndLoc) {
1254 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001255 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Anders Carlssonaaeef072010-01-24 05:50:09 +00001258 /// \brief Build a new inline asm statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001262 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1263 bool IsVolatile, unsigned NumOutputs,
1264 unsigned NumInputs, IdentifierInfo **Names,
1265 MultiExprArg Constraints, MultiExprArg Exprs,
1266 Expr *AsmString, MultiExprArg Clobbers,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1269 NumInputs, Names, Constraints, Exprs,
1270 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001271 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272
Chad Rosier32503022012-06-11 20:47:18 +00001273 /// \brief Build a new MS style inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001278 ArrayRef<Token> AsmToks,
1279 StringRef AsmString,
1280 unsigned NumOutputs, unsigned NumInputs,
1281 ArrayRef<StringRef> Constraints,
1282 ArrayRef<StringRef> Clobbers,
1283 ArrayRef<Expr*> Exprs,
1284 SourceLocation EndLoc) {
1285 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1286 NumOutputs, NumInputs,
1287 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001288 }
1289
Richard Smith9f690bd2015-10-27 06:02:45 +00001290 /// \brief Build a new co_return statement.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1295 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1296 }
1297
1298 /// \brief Build a new co_await expression.
1299 ///
1300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1303 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1304 }
1305
1306 /// \brief Build a new co_yield expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
1310 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1311 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1312 }
1313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001320 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001322 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001323 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001324 }
1325
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001326 /// \brief Rebuild an Objective-C exception declaration.
1327 ///
1328 /// By default, performs semantic analysis to build the new declaration.
1329 /// Subclasses may override this routine to provide different behavior.
1330 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1331 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001332 return getSema().BuildObjCExceptionDecl(TInfo, T,
1333 ExceptionDecl->getInnerLocStart(),
1334 ExceptionDecl->getLocation(),
1335 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001337
James Dennett2a4d13c2012-06-15 07:13:21 +00001338 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001342 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001343 SourceLocation RParenLoc,
1344 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001345 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001346 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001347 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001349
James Dennett2a4d13c2012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001355 Stmt *Body) {
1356 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001358
James Dennett2a4d13c2012-06-15 07:13:21 +00001359 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001363 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Expr *Operand) {
1365 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001367
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001368 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001372 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001373 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001374 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001375 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001376 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001377 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001378 return getSema().ActOnOpenMPExecutableDirective(
1379 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 }
1381
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001382 /// \brief Build a new OpenMP 'if' clause.
1383 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001384 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001385 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001386 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1387 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001388 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001389 SourceLocation NameModifierLoc,
1390 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001391 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001392 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1393 LParenLoc, NameModifierLoc, ColonLoc,
1394 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001395 }
1396
Alexey Bataev3778b602014-07-17 07:32:53 +00001397 /// \brief Build a new OpenMP 'final' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new OpenMP clause.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1402 SourceLocation LParenLoc,
1403 SourceLocation EndLoc) {
1404 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1405 EndLoc);
1406 }
1407
Alexey Bataev568a8332014-03-06 06:15:19 +00001408 /// \brief Build a new OpenMP 'num_threads' clause.
1409 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001410 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001411 /// Subclasses may override this routine to provide different behavior.
1412 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1413 SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1417 LParenLoc, EndLoc);
1418 }
1419
Alexey Bataev62c87d22014-03-21 04:51:18 +00001420 /// \brief Build a new OpenMP 'safelen' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1428 }
1429
Alexey Bataev66b15b52015-08-21 11:14:16 +00001430 /// \brief Build a new OpenMP 'simdlen' clause.
1431 ///
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexander Musman8bd31e62014-05-27 15:12:19 +00001440 /// \brief Build a new OpenMP 'collapse' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1445 SourceLocation LParenLoc,
1446 SourceLocation EndLoc) {
1447 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1448 EndLoc);
1449 }
1450
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001451 /// \brief Build a new OpenMP 'default' clause.
1452 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001453 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1456 SourceLocation KindKwLoc,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1461 StartLoc, LParenLoc, EndLoc);
1462 }
1463
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001464 /// \brief Build a new OpenMP 'proc_bind' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001467 /// Subclasses may override this routine to provide different behavior.
1468 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1469 SourceLocation KindKwLoc,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation EndLoc) {
1473 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1474 StartLoc, LParenLoc, EndLoc);
1475 }
1476
Alexey Bataev56dafe82014-06-20 07:16:17 +00001477 /// \brief Build a new OpenMP 'schedule' clause.
1478 ///
1479 /// By default, performs semantic analysis to build the new OpenMP clause.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1482 Expr *ChunkSize,
1483 SourceLocation StartLoc,
1484 SourceLocation LParenLoc,
1485 SourceLocation KindLoc,
1486 SourceLocation CommaLoc,
1487 SourceLocation EndLoc) {
1488 return getSema().ActOnOpenMPScheduleClause(
1489 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1490 }
1491
Alexey Bataev10e775f2015-07-30 11:36:16 +00001492 /// \brief Build a new OpenMP 'ordered' clause.
1493 ///
1494 /// By default, performs semantic analysis to build the new OpenMP clause.
1495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1497 SourceLocation EndLoc,
1498 SourceLocation LParenLoc, Expr *Num) {
1499 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1500 }
1501
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001502 /// \brief Build a new OpenMP 'private' clause.
1503 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001504 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1507 SourceLocation StartLoc,
1508 SourceLocation LParenLoc,
1509 SourceLocation EndLoc) {
1510 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1511 EndLoc);
1512 }
1513
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001514 /// \brief Build a new OpenMP 'firstprivate' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001517 /// Subclasses may override this routine to provide different behavior.
1518 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Alexander Musman1bb328c2014-06-04 13:06:39 +00001526 /// \brief Build a new OpenMP 'lastprivate' clause.
1527 ///
1528 /// By default, performs semantic analysis to build the new OpenMP clause.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation EndLoc) {
1534 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1535 EndLoc);
1536 }
1537
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001538 /// \brief Build a new OpenMP 'shared' clause.
1539 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001540 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001541 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001542 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1543 SourceLocation StartLoc,
1544 SourceLocation LParenLoc,
1545 SourceLocation EndLoc) {
1546 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1547 EndLoc);
1548 }
1549
Alexey Bataevc5e02582014-06-16 07:08:35 +00001550 /// \brief Build a new OpenMP 'reduction' clause.
1551 ///
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1555 SourceLocation StartLoc,
1556 SourceLocation LParenLoc,
1557 SourceLocation ColonLoc,
1558 SourceLocation EndLoc,
1559 CXXScopeSpec &ReductionIdScopeSpec,
1560 const DeclarationNameInfo &ReductionId) {
1561 return getSema().ActOnOpenMPReductionClause(
1562 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1563 ReductionId);
1564 }
1565
Alexander Musman8dba6642014-04-22 13:09:42 +00001566 /// \brief Build a new OpenMP 'linear' clause.
1567 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001568 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001569 /// Subclasses may override this routine to provide different behavior.
1570 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1571 SourceLocation StartLoc,
1572 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001573 OpenMPLinearClauseKind Modifier,
1574 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001575 SourceLocation ColonLoc,
1576 SourceLocation EndLoc) {
1577 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001578 Modifier, ModifierLoc, ColonLoc,
1579 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001580 }
1581
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001582 /// \brief Build a new OpenMP 'aligned' clause.
1583 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001584 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001585 /// Subclasses may override this routine to provide different behavior.
1586 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1587 SourceLocation StartLoc,
1588 SourceLocation LParenLoc,
1589 SourceLocation ColonLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1592 LParenLoc, ColonLoc, EndLoc);
1593 }
1594
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001595 /// \brief Build a new OpenMP 'copyin' clause.
1596 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001597 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1604 EndLoc);
1605 }
1606
Alexey Bataevbae9a792014-06-27 10:37:06 +00001607 /// \brief Build a new OpenMP 'copyprivate' clause.
1608 ///
1609 /// By default, performs semantic analysis to build the new OpenMP clause.
1610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
Alexey Bataev6125da92014-07-21 11:26:11 +00001619 /// \brief Build a new OpenMP 'flush' pseudo clause.
1620 ///
1621 /// By default, performs semantic analysis to build the new OpenMP clause.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001631 /// \brief Build a new OpenMP 'depend' pseudo clause.
1632 ///
1633 /// By default, performs semantic analysis to build the new OpenMP clause.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OMPClause *
1636 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1637 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1638 SourceLocation StartLoc, SourceLocation LParenLoc,
1639 SourceLocation EndLoc) {
1640 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1641 StartLoc, LParenLoc, EndLoc);
1642 }
1643
Michael Wonge710d542015-08-07 16:16:36 +00001644 /// \brief Build a new OpenMP 'device' clause.
1645 ///
1646 /// By default, performs semantic analysis to build the new statement.
1647 /// Subclasses may override this routine to provide different behavior.
1648 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1649 SourceLocation LParenLoc,
1650 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001651 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001652 EndLoc);
1653 }
1654
Kelvin Li0bff7af2015-11-23 05:32:03 +00001655 /// \brief Build a new OpenMP 'map' clause.
1656 ///
1657 /// By default, performs semantic analysis to build the new OpenMP clause.
1658 /// Subclasses may override this routine to provide different behavior.
1659 OMPClause *RebuildOMPMapClause(
1660 OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
1661 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1662 SourceLocation StartLoc, SourceLocation LParenLoc,
1663 SourceLocation EndLoc) {
1664 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc,
1665 ColonLoc, VarList,StartLoc,
1666 LParenLoc, EndLoc);
1667 }
1668
Kelvin Li099bb8c2015-11-24 20:50:12 +00001669 /// \brief Build a new OpenMP 'num_teams' clause.
1670 ///
1671 /// By default, performs semantic analysis to build the new statement.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1674 SourceLocation LParenLoc,
1675 SourceLocation EndLoc) {
1676 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1677 EndLoc);
1678 }
1679
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001680 /// \brief Build a new OpenMP 'thread_limit' clause.
1681 ///
1682 /// By default, performs semantic analysis to build the new statement.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1685 SourceLocation StartLoc,
1686 SourceLocation LParenLoc,
1687 SourceLocation EndLoc) {
1688 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1689 LParenLoc, EndLoc);
1690 }
1691
Alexey Bataeva0569352015-12-01 10:17:31 +00001692 /// \brief Build a new OpenMP 'priority' clause.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1697 SourceLocation LParenLoc,
1698 SourceLocation EndLoc) {
1699 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1700 EndLoc);
1701 }
1702
James Dennett2a4d13c2012-06-15 07:13:21 +00001703 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001704 ///
1705 /// By default, performs semantic analysis to build the new statement.
1706 /// Subclasses may override this routine to provide different behavior.
1707 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1708 Expr *object) {
1709 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1710 }
1711
James Dennett2a4d13c2012-06-15 07:13:21 +00001712 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001713 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001714 /// By default, performs semantic analysis to build the new statement.
1715 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001716 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001717 Expr *Object, Stmt *Body) {
1718 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001719 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001720
James Dennett2a4d13c2012-06-15 07:13:21 +00001721 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001722 ///
1723 /// By default, performs semantic analysis to build the new statement.
1724 /// Subclasses may override this routine to provide different behavior.
1725 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1726 Stmt *Body) {
1727 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1728 }
John McCall53848232011-07-27 01:07:15 +00001729
Douglas Gregorf68a5082010-04-22 23:10:45 +00001730 /// \brief Build a new Objective-C fast enumeration statement.
1731 ///
1732 /// By default, performs semantic analysis to build the new statement.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001735 Stmt *Element,
1736 Expr *Collection,
1737 SourceLocation RParenLoc,
1738 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001739 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001740 Element,
John McCallb268a282010-08-23 23:25:46 +00001741 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001742 RParenLoc);
1743 if (ForEachStmt.isInvalid())
1744 return StmtError();
1745
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001746 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001747 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001748
Douglas Gregorebe10102009-08-20 07:17:43 +00001749 /// \brief Build a new C++ exception declaration.
1750 ///
1751 /// By default, performs semantic analysis to build the new decaration.
1752 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001753 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001754 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001755 SourceLocation StartLoc,
1756 SourceLocation IdLoc,
1757 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001758 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001759 StartLoc, IdLoc, Id);
1760 if (Var)
1761 getSema().CurContext->addDecl(Var);
1762 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001763 }
1764
1765 /// \brief Build a new C++ catch statement.
1766 ///
1767 /// By default, performs semantic analysis to build the new statement.
1768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001769 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001770 VarDecl *ExceptionDecl,
1771 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001772 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1773 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001774 }
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregorebe10102009-08-20 07:17:43 +00001776 /// \brief Build a new C++ try statement.
1777 ///
1778 /// By default, performs semantic analysis to build the new statement.
1779 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001780 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1781 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001782 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001783 }
Mike Stump11289f42009-09-09 15:08:12 +00001784
Richard Smith02e85f32011-04-14 22:09:26 +00001785 /// \brief Build a new C++0x range-based for statement.
1786 ///
1787 /// By default, performs semantic analysis to build the new statement.
1788 /// Subclasses may override this routine to provide different behavior.
1789 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001790 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001791 SourceLocation ColonLoc,
1792 Stmt *Range, Stmt *BeginEnd,
1793 Expr *Cond, Expr *Inc,
1794 Stmt *LoopVar,
1795 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001796 // If we've just learned that the range is actually an Objective-C
1797 // collection, treat this as an Objective-C fast enumeration loop.
1798 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1799 if (RangeStmt->isSingleDecl()) {
1800 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001801 if (RangeVar->isInvalidDecl())
1802 return StmtError();
1803
Douglas Gregorf7106af2013-04-08 18:40:13 +00001804 Expr *RangeExpr = RangeVar->getInit();
1805 if (!RangeExpr->isTypeDependent() &&
1806 RangeExpr->getType()->isObjCObjectPointerType())
1807 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1808 RParenLoc);
1809 }
1810 }
1811 }
1812
Richard Smithcfd53b42015-10-22 06:13:50 +00001813 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1814 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001815 Cond, Inc, LoopVar, RParenLoc,
1816 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001817 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001818
1819 /// \brief Build a new C++0x range-based for statement.
1820 ///
1821 /// By default, performs semantic analysis to build the new statement.
1822 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001823 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001824 bool IsIfExists,
1825 NestedNameSpecifierLoc QualifierLoc,
1826 DeclarationNameInfo NameInfo,
1827 Stmt *Nested) {
1828 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1829 QualifierLoc, NameInfo, Nested);
1830 }
1831
Richard Smith02e85f32011-04-14 22:09:26 +00001832 /// \brief Attach body to a C++0x range-based for statement.
1833 ///
1834 /// By default, performs semantic analysis to finish the new statement.
1835 /// Subclasses may override this routine to provide different behavior.
1836 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1837 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001839
David Majnemerfad8f482013-10-15 09:33:02 +00001840 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001841 Stmt *TryBlock, Stmt *Handler) {
1842 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001843 }
1844
David Majnemerfad8f482013-10-15 09:33:02 +00001845 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001846 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001847 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001848 }
1849
David Majnemerfad8f482013-10-15 09:33:02 +00001850 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001851 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001852 }
1853
Alexey Bataevec474782014-10-09 08:45:04 +00001854 /// \brief Build a new predefined expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
1858 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1859 PredefinedExpr::IdentType IT) {
1860 return getSema().BuildPredefinedExpr(Loc, IT);
1861 }
1862
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// \brief Build a new expression that references a declaration.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001868 LookupResult &R,
1869 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001870 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1871 }
1872
1873
1874 /// \brief Build a new expression that references a declaration.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001878 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001879 ValueDecl *VD,
1880 const DeclarationNameInfo &NameInfo,
1881 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001882 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001883 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001884
1885 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001886
1887 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 }
Mike Stump11289f42009-09-09 15:08:12 +00001889
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001891 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001896 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 }
1898
Douglas Gregorad8a3362009-09-04 17:36:40 +00001899 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001900 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001903 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001904 SourceLocation OperatorLoc,
1905 bool isArrow,
1906 CXXScopeSpec &SS,
1907 TypeSourceInfo *ScopeType,
1908 SourceLocation CCLoc,
1909 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001910 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001911
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001913 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001916 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001917 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001918 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001919 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 }
Mike Stump11289f42009-09-09 15:08:12 +00001921
Douglas Gregor882211c2010-04-28 22:16:22 +00001922 /// \brief Build a new builtin offsetof expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001927 TypeSourceInfo *Type,
1928 ArrayRef<Sema::OffsetOfComponent> Components,
1929 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001930 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001931 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001933
1934 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001935 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001936 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001939 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1940 SourceLocation OpLoc,
1941 UnaryExprOrTypeTrait ExprKind,
1942 SourceRange R) {
1943 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 }
1945
Peter Collingbournee190dee2011-03-11 19:24:49 +00001946 /// \brief Build a new sizeof, alignof or vec step expression with an
1947 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001948 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001951 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1952 UnaryExprOrTypeTrait ExprKind,
1953 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001955 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001958
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001959 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 }
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001963 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001968 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001970 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001971 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 RBracketLoc);
1973 }
1974
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001975 /// \brief Build a new array section expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
1979 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1980 Expr *LowerBound,
1981 SourceLocation ColonLoc, Expr *Length,
1982 SourceLocation RBracketLoc) {
1983 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1984 ColonLoc, Length, RBracketLoc);
1985 }
1986
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001988 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001991 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001993 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001994 Expr *ExecConfig = nullptr) {
1995 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001996 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 }
1998
1999 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002000 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002003 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002004 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002005 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002006 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002007 const DeclarationNameInfo &MemberNameInfo,
2008 ValueDecl *Member,
2009 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002010 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002011 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002012 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2013 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002014 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002015 // We have a reference to an unnamed field. This is always the
2016 // base of an anonymous struct/union member access, i.e. the
2017 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002018 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002019 assert(Member->getType()->isRecordType() &&
2020 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002021
Richard Smithcab9a7d2011-10-26 19:06:56 +00002022 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002023 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002024 QualifierLoc.getNestedNameSpecifier(),
2025 FoundDecl, Member);
2026 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002027 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002028 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002029 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002030 MemberExpr *ME = new (getSema().Context)
2031 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2032 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002033 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002034 }
Mike Stump11289f42009-09-09 15:08:12 +00002035
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002036 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002037 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002038
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002039 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002040 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002041
John McCall16df1e52010-03-30 21:47:33 +00002042 // FIXME: this involves duplicating earlier analysis in a lot of
2043 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002044 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002045 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002046 R.resolveKind();
2047
John McCallb268a282010-08-23 23:25:46 +00002048 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002049 SS, TemplateKWLoc,
2050 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002051 R, ExplicitTemplateArgs,
2052 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 }
Mike Stump11289f42009-09-09 15:08:12 +00002054
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002056 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002059 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002060 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002061 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002062 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 }
2064
2065 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002066 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002069 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002070 SourceLocation QuestionLoc,
2071 Expr *LHS,
2072 SourceLocation ColonLoc,
2073 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002074 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2075 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 }
2077
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002079 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002082 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002083 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002085 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002086 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002087 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 }
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002091 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// By default, performs semantic analysis to build the new expression.
2093 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002094 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002095 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002097 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002098 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002099 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 }
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 SourceLocation OpLoc,
2108 SourceLocation AccessorLoc,
2109 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002110
John McCall10eae182009-11-30 22:42:35 +00002111 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002112 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002113 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002114 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002115 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002116 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002117 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002118 /* TemplateArgs */ nullptr,
2119 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 }
Mike Stump11289f42009-09-09 15:08:12 +00002121
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002123 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002126 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002127 MultiExprArg Inits,
2128 SourceLocation RBraceLoc,
2129 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002130 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002131 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002132 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002133 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002134
Douglas Gregord3d93062009-11-09 17:16:50 +00002135 // Patch in the result type we were given, which may have been computed
2136 // when the initial InitListExpr was built.
2137 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2138 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002139 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002143 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002146 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 MultiExprArg ArrayExprs,
2148 SourceLocation EqualOrColonLoc,
2149 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002150 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002151 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002153 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002156
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002157 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 }
Mike Stump11289f42009-09-09 15:08:12 +00002159
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002161 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 /// By default, builds the implicit value initialization without performing
2163 /// any semantic analysis. Subclasses may override this routine to provide
2164 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002165 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002166 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002170 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002174 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002175 SourceLocation RParenLoc) {
2176 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002177 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002178 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 }
2180
2181 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002182 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// By default, performs semantic analysis to build the new expression.
2184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002185 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002186 MultiExprArg SubExprs,
2187 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002188 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
Mike Stump11289f42009-09-09 15:08:12 +00002190
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002192 ///
2193 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 /// rather than attempting to map the label statement itself.
2195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002197 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002198 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002202 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002206 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002208 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 /// \brief Build a new __builtin_choose_expr expression.
2212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002216 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 SourceLocation RParenLoc) {
2218 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002219 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 RParenLoc);
2221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Peter Collingbourne91147592011-04-15 00:35:48 +00002223 /// \brief Build a new generic selection expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
2227 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2228 SourceLocation DefaultLoc,
2229 SourceLocation RParenLoc,
2230 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002231 ArrayRef<TypeSourceInfo *> Types,
2232 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002233 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002234 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002235 }
2236
Douglas Gregora16548e2009-08-11 05:31:07 +00002237 /// \brief Build a new overloaded operator call expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// The semantic analysis provides the behavior of template instantiation,
2241 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002242 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 /// argument-dependent lookup, etc. Subclasses may override this routine to
2244 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002245 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002247 Expr *Callee,
2248 Expr *First,
2249 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002250
2251 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// reinterpret_cast.
2253 ///
2254 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002255 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002257 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 Stmt::StmtClass Class,
2259 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002260 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 SourceLocation RAngleLoc,
2262 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002263 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 SourceLocation RParenLoc) {
2265 switch (Class) {
2266 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002267 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002268 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002269 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002270
2271 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002272 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002273 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002274 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002277 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002278 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002279 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002283 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002284 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002285 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002286
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002288 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 }
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 /// \brief Build a new C++ static_cast expression.
2293 ///
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002298 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 SourceLocation RAngleLoc,
2300 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002301 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002303 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002304 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002305 SourceRange(LAngleLoc, RAngleLoc),
2306 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 }
2308
2309 /// \brief Build a new C++ dynamic_cast expression.
2310 ///
2311 /// By default, performs semantic analysis to build the new expression.
2312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002313 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002315 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 SourceLocation RAngleLoc,
2317 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002318 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002320 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002321 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002322 SourceRange(LAngleLoc, RAngleLoc),
2323 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 }
2325
2326 /// \brief Build a new C++ reinterpret_cast expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002330 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002332 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 SourceLocation RAngleLoc,
2334 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002335 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002337 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002338 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002339 SourceRange(LAngleLoc, RAngleLoc),
2340 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 }
2342
2343 /// \brief Build a new C++ const_cast expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002347 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002349 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 SourceLocation RAngleLoc,
2351 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002352 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002354 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002355 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002356 SourceRange(LAngleLoc, RAngleLoc),
2357 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 }
Mike Stump11289f42009-09-09 15:08:12 +00002359
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 /// \brief Build a new C++ functional-style cast expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002364 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2365 SourceLocation LParenLoc,
2366 Expr *Sub,
2367 SourceLocation RParenLoc) {
2368 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002369 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 RParenLoc);
2371 }
Mike Stump11289f42009-09-09 15:08:12 +00002372
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 /// \brief Build a new C++ typeid(type) expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002378 SourceLocation TypeidLoc,
2379 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002381 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002382 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 }
Mike Stump11289f42009-09-09 15:08:12 +00002384
Francois Pichet9f4f2072010-09-08 12:20:18 +00002385
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 /// \brief Build a new C++ typeid(expr) expression.
2387 ///
2388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002390 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002391 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002392 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002394 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002395 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002396 }
2397
Francois Pichet9f4f2072010-09-08 12:20:18 +00002398 /// \brief Build a new C++ __uuidof(type) expression.
2399 ///
2400 /// By default, performs semantic analysis to build the new expression.
2401 /// Subclasses may override this routine to provide different behavior.
2402 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2403 SourceLocation TypeidLoc,
2404 TypeSourceInfo *Operand,
2405 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002406 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002407 RParenLoc);
2408 }
2409
2410 /// \brief Build a new C++ __uuidof(expr) expression.
2411 ///
2412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
2414 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2415 SourceLocation TypeidLoc,
2416 Expr *Operand,
2417 SourceLocation RParenLoc) {
2418 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2419 RParenLoc);
2420 }
2421
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 /// \brief Build a new C++ "this" expression.
2423 ///
2424 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002425 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002427 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002428 QualType ThisType,
2429 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002430 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002431 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 }
2433
2434 /// \brief Build a new C++ throw expression.
2435 ///
2436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002438 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2439 bool IsThrownVariableInScope) {
2440 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 }
2442
2443 /// \brief Build a new C++ default-argument expression.
2444 ///
2445 /// By default, builds a new default-argument expression, which does not
2446 /// require any semantic analysis. Subclasses may override this routine to
2447 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002448 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002449 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002450 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 }
2452
Richard Smith852c9db2013-04-20 22:23:05 +00002453 /// \brief Build a new C++11 default-initialization expression.
2454 ///
2455 /// By default, builds a new default field initialization expression, which
2456 /// does not require any semantic analysis. Subclasses may override this
2457 /// routine to provide different behavior.
2458 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2459 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002460 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002461 }
2462
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 /// \brief Build a new C++ zero-initialization expression.
2464 ///
2465 /// By default, performs semantic analysis to build the new expression.
2466 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002467 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2468 SourceLocation LParenLoc,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002471 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002472 }
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregora16548e2009-08-11 05:31:07 +00002474 /// \brief Build a new C++ "new" expression.
2475 ///
2476 /// By default, performs semantic analysis to build the new expression.
2477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002478 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002479 bool UseGlobal,
2480 SourceLocation PlacementLParen,
2481 MultiExprArg PlacementArgs,
2482 SourceLocation PlacementRParen,
2483 SourceRange TypeIdParens,
2484 QualType AllocatedType,
2485 TypeSourceInfo *AllocatedTypeInfo,
2486 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002487 SourceRange DirectInitRange,
2488 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002489 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002491 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002492 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002493 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002494 AllocatedType,
2495 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002496 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002497 DirectInitRange,
2498 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002499 }
Mike Stump11289f42009-09-09 15:08:12 +00002500
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 /// \brief Build a new C++ "delete" expression.
2502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002505 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 bool IsGlobalDelete,
2507 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002508 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002509 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002510 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002511 }
Mike Stump11289f42009-09-09 15:08:12 +00002512
Douglas Gregor29c42f22012-02-24 07:38:34 +00002513 /// \brief Build a new type trait expression.
2514 ///
2515 /// By default, performs semantic analysis to build the new expression.
2516 /// Subclasses may override this routine to provide different behavior.
2517 ExprResult RebuildTypeTrait(TypeTrait Trait,
2518 SourceLocation StartLoc,
2519 ArrayRef<TypeSourceInfo *> Args,
2520 SourceLocation RParenLoc) {
2521 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002523
John Wiegley6242b6a2011-04-28 00:16:57 +00002524 /// \brief Build a new array type trait expression.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
2528 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2529 SourceLocation StartLoc,
2530 TypeSourceInfo *TSInfo,
2531 Expr *DimExpr,
2532 SourceLocation RParenLoc) {
2533 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2534 }
2535
John Wiegleyf9f65842011-04-25 06:54:41 +00002536 /// \brief Build a new expression trait expression.
2537 ///
2538 /// By default, performs semantic analysis to build the new expression.
2539 /// Subclasses may override this routine to provide different behavior.
2540 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2541 SourceLocation StartLoc,
2542 Expr *Queried,
2543 SourceLocation RParenLoc) {
2544 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2545 }
2546
Mike Stump11289f42009-09-09 15:08:12 +00002547 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 /// expression.
2549 ///
2550 /// By default, performs semantic analysis to build the new expression.
2551 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002552 ExprResult RebuildDependentScopeDeclRefExpr(
2553 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002554 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002555 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002556 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002557 bool IsAddressOfOperand,
2558 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002560 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002561
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002562 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002563 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2564 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002565
Reid Kleckner32506ed2014-06-12 23:03:48 +00002566 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002567 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 }
2569
2570 /// \brief Build a new template-id expression.
2571 ///
2572 /// By default, performs semantic analysis to build the new expression.
2573 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002574 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002575 SourceLocation TemplateKWLoc,
2576 LookupResult &R,
2577 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002578 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002579 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2580 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 }
2582
2583 /// \brief Build a new object-construction expression.
2584 ///
2585 /// By default, performs semantic analysis to build the new expression.
2586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002587 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002588 SourceLocation Loc,
2589 CXXConstructorDecl *Constructor,
2590 bool IsElidable,
2591 MultiExprArg Args,
2592 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002593 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002594 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002595 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002596 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002597 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002598 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002599 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002600 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002601 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002602
Douglas Gregordb121ba2009-12-14 16:27:04 +00002603 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002604 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002605 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002606 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002607 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002608 RequiresZeroInit, ConstructKind,
2609 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002610 }
2611
2612 /// \brief Build a new object-construction expression.
2613 ///
2614 /// By default, performs semantic analysis to build the new expression.
2615 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002616 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2617 SourceLocation LParenLoc,
2618 MultiExprArg Args,
2619 SourceLocation RParenLoc) {
2620 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002621 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002622 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002623 RParenLoc);
2624 }
2625
2626 /// \brief Build a new object-construction expression.
2627 ///
2628 /// By default, performs semantic analysis to build the new expression.
2629 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002630 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2631 SourceLocation LParenLoc,
2632 MultiExprArg Args,
2633 SourceLocation RParenLoc) {
2634 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002635 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002636 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002637 RParenLoc);
2638 }
Mike Stump11289f42009-09-09 15:08:12 +00002639
Douglas Gregora16548e2009-08-11 05:31:07 +00002640 /// \brief Build a new member reference expression.
2641 ///
2642 /// By default, performs semantic analysis to build the new expression.
2643 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002644 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002645 QualType BaseType,
2646 bool IsArrow,
2647 SourceLocation OperatorLoc,
2648 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002649 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002650 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002651 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002652 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002654 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002655
John McCallb268a282010-08-23 23:25:46 +00002656 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002657 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002658 SS, TemplateKWLoc,
2659 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002660 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002661 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 }
2663
John McCall10eae182009-11-30 22:42:35 +00002664 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002665 ///
2666 /// By default, performs semantic analysis to build the new expression.
2667 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002668 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2669 SourceLocation OperatorLoc,
2670 bool IsArrow,
2671 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002672 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002673 NamedDecl *FirstQualifierInScope,
2674 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002675 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002676 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002677 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002678
John McCallb268a282010-08-23 23:25:46 +00002679 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002680 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002681 SS, TemplateKWLoc,
2682 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002683 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002684 }
Mike Stump11289f42009-09-09 15:08:12 +00002685
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002686 /// \brief Build a new noexcept expression.
2687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
2690 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2691 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2692 }
2693
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002694 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002695 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2696 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002697 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002698 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002699 Optional<unsigned> Length,
2700 ArrayRef<TemplateArgument> PartialArgs) {
2701 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2702 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002703 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002704
Patrick Beard0caa3942012-04-19 00:25:12 +00002705 /// \brief Build a new Objective-C boxed expression.
2706 ///
2707 /// By default, performs semantic analysis to build the new expression.
2708 /// Subclasses may override this routine to provide different behavior.
2709 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2710 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2711 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002712
Ted Kremeneke65b0862012-03-06 20:05:56 +00002713 /// \brief Build a new Objective-C array literal.
2714 ///
2715 /// By default, performs semantic analysis to build the new expression.
2716 /// Subclasses may override this routine to provide different behavior.
2717 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2718 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002719 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002720 MultiExprArg(Elements, NumElements));
2721 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002722
2723 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002724 Expr *Base, Expr *Key,
2725 ObjCMethodDecl *getterMethod,
2726 ObjCMethodDecl *setterMethod) {
2727 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2728 getterMethod, setterMethod);
2729 }
2730
2731 /// \brief Build a new Objective-C dictionary literal.
2732 ///
2733 /// By default, performs semantic analysis to build the new expression.
2734 /// Subclasses may override this routine to provide different behavior.
2735 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2736 ObjCDictionaryElement *Elements,
2737 unsigned NumElements) {
2738 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2739 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002740
James Dennett2a4d13c2012-06-15 07:13:21 +00002741 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 ///
2743 /// By default, performs semantic analysis to build the new expression.
2744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002745 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002746 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002747 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002748 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002749 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002750
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002751 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002752 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002753 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002754 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002755 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002756 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002757 MultiExprArg Args,
2758 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002759 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2760 ReceiverTypeInfo->getType(),
2761 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002762 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002763 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002764 }
2765
2766 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002767 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002768 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002769 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002770 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002771 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002772 MultiExprArg Args,
2773 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002774 return SemaRef.BuildInstanceMessage(Receiver,
2775 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002776 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002777 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002778 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002779 }
2780
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002781 /// \brief Build a new Objective-C instance/class message to 'super'.
2782 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2783 Selector Sel,
2784 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002785 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002786 ObjCMethodDecl *Method,
2787 SourceLocation LBracLoc,
2788 MultiExprArg Args,
2789 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002790 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002791 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002792 SuperLoc,
2793 Sel, Method, LBracLoc, SelectorLocs,
2794 RBracLoc, Args)
2795 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002796 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002797 SuperLoc,
2798 Sel, Method, LBracLoc, SelectorLocs,
2799 RBracLoc, Args);
2800
2801
2802 }
2803
Douglas Gregord51d90d2010-04-26 20:11:03 +00002804 /// \brief Build a new Objective-C ivar reference expression.
2805 ///
2806 /// By default, performs semantic analysis to build the new expression.
2807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002808 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002809 SourceLocation IvarLoc,
2810 bool IsArrow, bool IsFreeIvar) {
2811 // FIXME: We lose track of the IsFreeIvar bit.
2812 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002813 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2814 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002815 /*FIXME:*/IvarLoc, IsArrow,
2816 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002817 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002818 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002819 /*TemplateArgs=*/nullptr,
2820 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002821 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002822
2823 /// \brief Build a new Objective-C property reference expression.
2824 ///
2825 /// By default, performs semantic analysis to build the new expression.
2826 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002827 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002828 ObjCPropertyDecl *Property,
2829 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002830 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002831 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2832 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2833 /*FIXME:*/PropertyLoc,
2834 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002835 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002836 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002837 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002838 /*TemplateArgs=*/nullptr,
2839 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002841
John McCallb7bd14f2010-12-02 01:19:52 +00002842 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002843 ///
2844 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002845 /// Subclasses may override this routine to provide different behavior.
2846 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2847 ObjCMethodDecl *Getter,
2848 ObjCMethodDecl *Setter,
2849 SourceLocation PropertyLoc) {
2850 // Since these expressions can only be value-dependent, we do not
2851 // need to perform semantic analysis again.
2852 return Owned(
2853 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2854 VK_LValue, OK_ObjCProperty,
2855 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002856 }
2857
Douglas Gregord51d90d2010-04-26 20:11:03 +00002858 /// \brief Build a new Objective-C "isa" expression.
2859 ///
2860 /// By default, performs semantic analysis to build the new expression.
2861 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002862 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002863 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002864 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002865 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2866 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002867 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002868 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002869 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002870 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002871 /*TemplateArgs=*/nullptr,
2872 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002874
Douglas Gregora16548e2009-08-11 05:31:07 +00002875 /// \brief Build a new shuffle vector expression.
2876 ///
2877 /// By default, performs semantic analysis to build the new expression.
2878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002879 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002880 MultiExprArg SubExprs,
2881 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002882 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002883 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002884 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2885 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2886 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002887 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002888
Douglas Gregora16548e2009-08-11 05:31:07 +00002889 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002890 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002891 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2892 SemaRef.Context.BuiltinFnTy,
2893 VK_RValue, BuiltinLoc);
2894 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2895 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002896 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002897
2898 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002899 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002900 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002901 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002902
Douglas Gregora16548e2009-08-11 05:31:07 +00002903 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002904 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002905 }
John McCall31f82722010-11-12 08:19:04 +00002906
Hal Finkelc4d7c822013-09-18 03:29:45 +00002907 /// \brief Build a new convert vector expression.
2908 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2909 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2910 SourceLocation RParenLoc) {
2911 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2912 BuiltinLoc, RParenLoc);
2913 }
2914
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002915 /// \brief Build a new template argument pack expansion.
2916 ///
2917 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002918 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002919 /// different behavior.
2920 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002921 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002922 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002923 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002924 case TemplateArgument::Expression: {
2925 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002926 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2927 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002928 if (Result.isInvalid())
2929 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Douglas Gregor98318c22011-01-03 21:37:45 +00002931 return TemplateArgumentLoc(Result.get(), Result.get());
2932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002933
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002934 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002935 return TemplateArgumentLoc(TemplateArgument(
2936 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002937 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002938 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002939 Pattern.getTemplateNameLoc(),
2940 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002941
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002942 case TemplateArgument::Null:
2943 case TemplateArgument::Integral:
2944 case TemplateArgument::Declaration:
2945 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002946 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002947 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002948 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002949
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002950 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002951 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002952 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002953 EllipsisLoc,
2954 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002955 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2956 Expansion);
2957 break;
2958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002959
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002960 return TemplateArgumentLoc();
2961 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002962
Douglas Gregor968f23a2011-01-03 19:31:53 +00002963 /// \brief Build a new expression pack expansion.
2964 ///
2965 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002966 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002967 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002968 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002969 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002970 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002971 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002972
Richard Smith0f0af192014-11-08 05:07:16 +00002973 /// \brief Build a new C++1z fold-expression.
2974 ///
2975 /// By default, performs semantic analysis in order to build a new fold
2976 /// expression.
2977 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2978 BinaryOperatorKind Operator,
2979 SourceLocation EllipsisLoc, Expr *RHS,
2980 SourceLocation RParenLoc) {
2981 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2982 RHS, RParenLoc);
2983 }
2984
2985 /// \brief Build an empty C++1z fold-expression with the given operator.
2986 ///
2987 /// By default, produces the fallback value for the fold-expression, or
2988 /// produce an error if there is no fallback value.
2989 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2990 BinaryOperatorKind Operator) {
2991 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2992 }
2993
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002994 /// \brief Build a new atomic operation expression.
2995 ///
2996 /// By default, performs semantic analysis to build the new expression.
2997 /// Subclasses may override this routine to provide different behavior.
2998 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2999 MultiExprArg SubExprs,
3000 QualType RetTy,
3001 AtomicExpr::AtomicOp Op,
3002 SourceLocation RParenLoc) {
3003 // Just create the expression; there is not any interesting semantic
3004 // analysis here because we can't actually build an AtomicExpr until
3005 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003006 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003007 RParenLoc);
3008 }
3009
John McCall31f82722010-11-12 08:19:04 +00003010private:
Douglas Gregor14454802011-02-25 02:25:35 +00003011 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3012 QualType ObjectType,
3013 NamedDecl *FirstQualifierInScope,
3014 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003015
3016 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3017 QualType ObjectType,
3018 NamedDecl *FirstQualifierInScope,
3019 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003020
3021 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3022 NamedDecl *FirstQualifierInScope,
3023 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024};
Douglas Gregora16548e2009-08-11 05:31:07 +00003025
Douglas Gregorebe10102009-08-20 07:17:43 +00003026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003027StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003028 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003029 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003030
Douglas Gregorebe10102009-08-20 07:17:43 +00003031 switch (S->getStmtClass()) {
3032 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003033
Douglas Gregorebe10102009-08-20 07:17:43 +00003034 // Transform individual statement nodes
3035#define STMT(Node, Parent) \
3036 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003037#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003038#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003039#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003040
Douglas Gregorebe10102009-08-20 07:17:43 +00003041 // Transform expressions by calling TransformExpr.
3042#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003043#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003044#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003045#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003046 {
John McCalldadc5752010-08-24 06:29:42 +00003047 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003048 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003049 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003050
Richard Smith945f8d32013-01-14 22:39:08 +00003051 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003052 }
Mike Stump11289f42009-09-09 15:08:12 +00003053 }
3054
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003055 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003056}
Mike Stump11289f42009-09-09 15:08:12 +00003057
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003058template<typename Derived>
3059OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3060 if (!S)
3061 return S;
3062
3063 switch (S->getClauseKind()) {
3064 default: break;
3065 // Transform individual clause nodes
3066#define OPENMP_CLAUSE(Name, Class) \
3067 case OMPC_ ## Name : \
3068 return getDerived().Transform ## Class(cast<Class>(S));
3069#include "clang/Basic/OpenMPKinds.def"
3070 }
3071
3072 return S;
3073}
3074
Mike Stump11289f42009-09-09 15:08:12 +00003075
Douglas Gregore922c772009-08-04 22:27:00 +00003076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003077ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003078 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003079 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003080
3081 switch (E->getStmtClass()) {
3082 case Stmt::NoStmtClass: break;
3083#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003084#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003085#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003086 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003087#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003088 }
3089
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003090 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003091}
3092
3093template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003094ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003095 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003096 // Initializers are instantiated like expressions, except that various outer
3097 // layers are stripped.
3098 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003099 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003100
3101 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3102 Init = ExprTemp->getSubExpr();
3103
Richard Smithe6ca4752013-05-30 22:40:16 +00003104 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3105 Init = MTE->GetTemporaryExpr();
3106
Richard Smithd59b8322012-12-19 01:39:02 +00003107 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3108 Init = Binder->getSubExpr();
3109
3110 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3111 Init = ICE->getSubExprAsWritten();
3112
Richard Smithcc1b96d2013-06-12 22:31:48 +00003113 if (CXXStdInitializerListExpr *ILE =
3114 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003115 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003116
Richard Smithc6abd962014-07-25 01:12:44 +00003117 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003118 // InitListExprs. Other forms of copy-initialization will be a no-op if
3119 // the initializer is already the right type.
3120 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003121 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003122 return getDerived().TransformExpr(Init);
3123
3124 // Revert value-initialization back to empty parens.
3125 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3126 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003127 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003128 Parens.getEnd());
3129 }
3130
3131 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3132 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003133 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003134 SourceLocation());
3135
3136 // Revert initialization by constructor back to a parenthesized or braced list
3137 // of expressions. Any other form of initializer can just be reused directly.
3138 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003139 return getDerived().TransformExpr(Init);
3140
Richard Smithf8adcdc2014-07-17 05:12:35 +00003141 // If the initialization implicitly converted an initializer list to a
3142 // std::initializer_list object, unwrap the std::initializer_list too.
3143 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003144 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003145
Richard Smithd59b8322012-12-19 01:39:02 +00003146 SmallVector<Expr*, 8> NewArgs;
3147 bool ArgChanged = false;
3148 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003149 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003150 return ExprError();
3151
3152 // If this was list initialization, revert to list form.
3153 if (Construct->isListInitialization())
3154 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3155 Construct->getLocEnd(),
3156 Construct->getType());
3157
Richard Smithd59b8322012-12-19 01:39:02 +00003158 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003159 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003160 if (Parens.isInvalid()) {
3161 // This was a variable declaration's initialization for which no initializer
3162 // was specified.
3163 assert(NewArgs.empty() &&
3164 "no parens or braces but have direct init with arguments?");
3165 return ExprEmpty();
3166 }
Richard Smithd59b8322012-12-19 01:39:02 +00003167 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3168 Parens.getEnd());
3169}
3170
3171template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003172bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3173 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003174 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003175 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003176 bool *ArgChanged) {
3177 for (unsigned I = 0; I != NumInputs; ++I) {
3178 // If requested, drop call arguments that need to be dropped.
3179 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3180 if (ArgChanged)
3181 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregora3efea12011-01-03 19:04:46 +00003183 break;
3184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003185
Douglas Gregor968f23a2011-01-03 19:31:53 +00003186 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3187 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003188
Chris Lattner01cf8db2011-07-20 06:58:45 +00003189 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003190 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3191 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003192
Douglas Gregor968f23a2011-01-03 19:31:53 +00003193 // Determine whether the set of unexpanded parameter packs can and should
3194 // be expanded.
3195 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003196 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003197 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3198 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003199 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3200 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003201 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003202 Expand, RetainExpansion,
3203 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003204 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
Douglas Gregor968f23a2011-01-03 19:31:53 +00003206 if (!Expand) {
3207 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003208 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003209 // expansion.
3210 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3211 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3212 if (OutPattern.isInvalid())
3213 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003214
3215 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003216 Expansion->getEllipsisLoc(),
3217 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003218 if (Out.isInvalid())
3219 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003220
Douglas Gregor968f23a2011-01-03 19:31:53 +00003221 if (ArgChanged)
3222 *ArgChanged = true;
3223 Outputs.push_back(Out.get());
3224 continue;
3225 }
John McCall542e7c62011-07-06 07:30:07 +00003226
3227 // Record right away that the argument was changed. This needs
3228 // to happen even if the array expands to nothing.
3229 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregor968f23a2011-01-03 19:31:53 +00003231 // The transform has determined that we should perform an elementwise
3232 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003233 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003234 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3235 ExprResult Out = getDerived().TransformExpr(Pattern);
3236 if (Out.isInvalid())
3237 return true;
3238
Richard Smith9467be42014-06-06 17:33:35 +00003239 // FIXME: Can this happen? We should not try to expand the pack
3240 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003241 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003242 Out = getDerived().RebuildPackExpansion(
3243 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003244 if (Out.isInvalid())
3245 return true;
3246 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003247
Douglas Gregor968f23a2011-01-03 19:31:53 +00003248 Outputs.push_back(Out.get());
3249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Richard Smith9467be42014-06-06 17:33:35 +00003251 // If we're supposed to retain a pack expansion, do so by temporarily
3252 // forgetting the partially-substituted parameter pack.
3253 if (RetainExpansion) {
3254 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3255
3256 ExprResult Out = getDerived().TransformExpr(Pattern);
3257 if (Out.isInvalid())
3258 return true;
3259
3260 Out = getDerived().RebuildPackExpansion(
3261 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3262 if (Out.isInvalid())
3263 return true;
3264
3265 Outputs.push_back(Out.get());
3266 }
3267
Douglas Gregor968f23a2011-01-03 19:31:53 +00003268 continue;
3269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003270
Richard Smithd59b8322012-12-19 01:39:02 +00003271 ExprResult Result =
3272 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3273 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003274 if (Result.isInvalid())
3275 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregora3efea12011-01-03 19:04:46 +00003277 if (Result.get() != Inputs[I] && ArgChanged)
3278 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
3280 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregora3efea12011-01-03 19:04:46 +00003283 return false;
3284}
3285
3286template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003287NestedNameSpecifierLoc
3288TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3289 NestedNameSpecifierLoc NNS,
3290 QualType ObjectType,
3291 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003292 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003293 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003294 Qualifier = Qualifier.getPrefix())
3295 Qualifiers.push_back(Qualifier);
3296
3297 CXXScopeSpec SS;
3298 while (!Qualifiers.empty()) {
3299 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3300 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
Douglas Gregor14454802011-02-25 02:25:35 +00003302 switch (QNNS->getKind()) {
3303 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003304 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003305 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003306 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003307 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003308 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003309 FirstQualifierInScope, false))
3310 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregor14454802011-02-25 02:25:35 +00003312 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor14454802011-02-25 02:25:35 +00003314 case NestedNameSpecifier::Namespace: {
3315 NamespaceDecl *NS
3316 = cast_or_null<NamespaceDecl>(
3317 getDerived().TransformDecl(
3318 Q.getLocalBeginLoc(),
3319 QNNS->getAsNamespace()));
3320 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3321 break;
3322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregor14454802011-02-25 02:25:35 +00003324 case NestedNameSpecifier::NamespaceAlias: {
3325 NamespaceAliasDecl *Alias
3326 = cast_or_null<NamespaceAliasDecl>(
3327 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3328 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003329 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003330 Q.getLocalEndLoc());
3331 break;
3332 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003333
Douglas Gregor14454802011-02-25 02:25:35 +00003334 case NestedNameSpecifier::Global:
3335 // There is no meaningful transformation that one could perform on the
3336 // global scope.
3337 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3338 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Nikola Smiljanic67860242014-09-26 00:28:20 +00003340 case NestedNameSpecifier::Super: {
3341 CXXRecordDecl *RD =
3342 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3343 SourceLocation(), QNNS->getAsRecordDecl()));
3344 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3345 break;
3346 }
3347
Douglas Gregor14454802011-02-25 02:25:35 +00003348 case NestedNameSpecifier::TypeSpecWithTemplate:
3349 case NestedNameSpecifier::TypeSpec: {
3350 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3351 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregor14454802011-02-25 02:25:35 +00003353 if (!TL)
3354 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003355
Douglas Gregor14454802011-02-25 02:25:35 +00003356 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003357 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003358 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003359 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003360 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003361 if (TL.getType()->isEnumeralType())
3362 SemaRef.Diag(TL.getBeginLoc(),
3363 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003364 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3365 Q.getLocalEndLoc());
3366 break;
3367 }
Richard Trieude756fb2011-05-07 01:36:37 +00003368 // If the nested-name-specifier is an invalid type def, don't emit an
3369 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003370 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3371 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003372 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003373 << TL.getType() << SS.getRange();
3374 }
Douglas Gregor14454802011-02-25 02:25:35 +00003375 return NestedNameSpecifierLoc();
3376 }
Douglas Gregore16af532011-02-28 18:50:33 +00003377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
Douglas Gregore16af532011-02-28 18:50:33 +00003379 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003380 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003381 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003383
Douglas Gregor14454802011-02-25 02:25:35 +00003384 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003385 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003386 !getDerived().AlwaysRebuild())
3387 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
3389 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003390 // nested-name-specifier, do so.
3391 if (SS.location_size() == NNS.getDataLength() &&
3392 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3393 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3394
3395 // Allocate new nested-name-specifier location information.
3396 return SS.getWithLocInContext(SemaRef.Context);
3397}
3398
3399template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003400DeclarationNameInfo
3401TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003402::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003403 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003404 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003405 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003406
3407 switch (Name.getNameKind()) {
3408 case DeclarationName::Identifier:
3409 case DeclarationName::ObjCZeroArgSelector:
3410 case DeclarationName::ObjCOneArgSelector:
3411 case DeclarationName::ObjCMultiArgSelector:
3412 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003413 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003414 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003415 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003416
Douglas Gregorf816bd72009-09-03 22:13:48 +00003417 case DeclarationName::CXXConstructorName:
3418 case DeclarationName::CXXDestructorName:
3419 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003420 TypeSourceInfo *NewTInfo;
3421 CanQualType NewCanTy;
3422 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003423 NewTInfo = getDerived().TransformType(OldTInfo);
3424 if (!NewTInfo)
3425 return DeclarationNameInfo();
3426 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003427 }
3428 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003429 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003430 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003431 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003432 if (NewT.isNull())
3433 return DeclarationNameInfo();
3434 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3435 }
Mike Stump11289f42009-09-09 15:08:12 +00003436
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003437 DeclarationName NewName
3438 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3439 NewCanTy);
3440 DeclarationNameInfo NewNameInfo(NameInfo);
3441 NewNameInfo.setName(NewName);
3442 NewNameInfo.setNamedTypeInfo(NewTInfo);
3443 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003444 }
Mike Stump11289f42009-09-09 15:08:12 +00003445 }
3446
David Blaikie83d382b2011-09-23 05:06:16 +00003447 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003448}
3449
3450template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003451TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003452TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3453 TemplateName Name,
3454 SourceLocation NameLoc,
3455 QualType ObjectType,
3456 NamedDecl *FirstQualifierInScope) {
3457 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3458 TemplateDecl *Template = QTN->getTemplateDecl();
3459 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregor9db53502011-03-02 18:07:45 +00003461 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003462 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003463 Template));
3464 if (!TransTemplate)
3465 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor9db53502011-03-02 18:07:45 +00003467 if (!getDerived().AlwaysRebuild() &&
3468 SS.getScopeRep() == QTN->getQualifier() &&
3469 TransTemplate == Template)
3470 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003471
Douglas Gregor9db53502011-03-02 18:07:45 +00003472 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3473 TransTemplate);
3474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003475
Douglas Gregor9db53502011-03-02 18:07:45 +00003476 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3477 if (SS.getScopeRep()) {
3478 // These apply to the scope specifier, not the template.
3479 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003480 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003481 }
3482
Douglas Gregor9db53502011-03-02 18:07:45 +00003483 if (!getDerived().AlwaysRebuild() &&
3484 SS.getScopeRep() == DTN->getQualifier() &&
3485 ObjectType.isNull())
3486 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003487
Douglas Gregor9db53502011-03-02 18:07:45 +00003488 if (DTN->isIdentifier()) {
3489 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003490 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003491 NameLoc,
3492 ObjectType,
3493 FirstQualifierInScope);
3494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003495
Douglas Gregor9db53502011-03-02 18:07:45 +00003496 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3497 ObjectType);
3498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003499
Douglas Gregor9db53502011-03-02 18:07:45 +00003500 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3501 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003502 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003503 Template));
3504 if (!TransTemplate)
3505 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Douglas Gregor9db53502011-03-02 18:07:45 +00003507 if (!getDerived().AlwaysRebuild() &&
3508 TransTemplate == Template)
3509 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
Douglas Gregor9db53502011-03-02 18:07:45 +00003511 return TemplateName(TransTemplate);
3512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregor9db53502011-03-02 18:07:45 +00003514 if (SubstTemplateTemplateParmPackStorage *SubstPack
3515 = Name.getAsSubstTemplateTemplateParmPack()) {
3516 TemplateTemplateParmDecl *TransParam
3517 = cast_or_null<TemplateTemplateParmDecl>(
3518 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3519 if (!TransParam)
3520 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor9db53502011-03-02 18:07:45 +00003522 if (!getDerived().AlwaysRebuild() &&
3523 TransParam == SubstPack->getParameterPack())
3524 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
3526 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003527 SubstPack->getArgumentPack());
3528 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
Douglas Gregor9db53502011-03-02 18:07:45 +00003530 // These should be getting filtered out before they reach the AST.
3531 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003532}
3533
3534template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003535void TreeTransform<Derived>::InventTemplateArgumentLoc(
3536 const TemplateArgument &Arg,
3537 TemplateArgumentLoc &Output) {
3538 SourceLocation Loc = getDerived().getBaseLocation();
3539 switch (Arg.getKind()) {
3540 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003541 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003542 break;
3543
3544 case TemplateArgument::Type:
3545 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003546 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003547
John McCall0ad16662009-10-29 08:12:44 +00003548 break;
3549
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003550 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003551 case TemplateArgument::TemplateExpansion: {
3552 NestedNameSpecifierLocBuilder Builder;
3553 TemplateName Template = Arg.getAsTemplate();
3554 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3555 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3556 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3557 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003558
Douglas Gregor9d802122011-03-02 17:09:35 +00003559 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003560 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003561 Builder.getWithLocInContext(SemaRef.Context),
3562 Loc);
3563 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003564 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003565 Builder.getWithLocInContext(SemaRef.Context),
3566 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003567
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003568 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003569 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003570
John McCall0ad16662009-10-29 08:12:44 +00003571 case TemplateArgument::Expression:
3572 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3573 break;
3574
3575 case TemplateArgument::Declaration:
3576 case TemplateArgument::Integral:
3577 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003578 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003579 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003580 break;
3581 }
3582}
3583
3584template<typename Derived>
3585bool TreeTransform<Derived>::TransformTemplateArgument(
3586 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003587 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003588 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003589 switch (Arg.getKind()) {
3590 case TemplateArgument::Null:
3591 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003592 case TemplateArgument::Pack:
3593 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003594 case TemplateArgument::NullPtr:
3595 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003596
Douglas Gregore922c772009-08-04 22:27:00 +00003597 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003598 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003599 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003600 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003601
3602 DI = getDerived().TransformType(DI);
3603 if (!DI) return true;
3604
3605 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3606 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003607 }
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003609 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003610 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3611 if (QualifierLoc) {
3612 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3613 if (!QualifierLoc)
3614 return true;
3615 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003616
Douglas Gregordf846d12011-03-02 18:46:51 +00003617 CXXScopeSpec SS;
3618 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003619 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003620 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3621 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003622 if (Template.isNull())
3623 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003624
Douglas Gregor9d802122011-03-02 17:09:35 +00003625 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003626 Input.getTemplateNameLoc());
3627 return false;
3628 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003629
3630 case TemplateArgument::TemplateExpansion:
3631 llvm_unreachable("Caller should expand pack expansions");
3632
Douglas Gregore922c772009-08-04 22:27:00 +00003633 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003634 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003635 EnterExpressionEvaluationContext Unevaluated(
3636 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003637
John McCall0ad16662009-10-29 08:12:44 +00003638 Expr *InputExpr = Input.getSourceExpression();
3639 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3640
Chris Lattnercdb591a2011-04-25 20:37:58 +00003641 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003642 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003643 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003644 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003645 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003646 }
Douglas Gregore922c772009-08-04 22:27:00 +00003647 }
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregore922c772009-08-04 22:27:00 +00003649 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003650 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003651}
3652
Douglas Gregorfe921a72010-12-20 23:36:19 +00003653/// \brief Iterator adaptor that invents template argument location information
3654/// for each of the template arguments in its underlying iterator.
3655template<typename Derived, typename InputIterator>
3656class TemplateArgumentLocInventIterator {
3657 TreeTransform<Derived> &Self;
3658 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
Douglas Gregorfe921a72010-12-20 23:36:19 +00003660public:
3661 typedef TemplateArgumentLoc value_type;
3662 typedef TemplateArgumentLoc reference;
3663 typedef typename std::iterator_traits<InputIterator>::difference_type
3664 difference_type;
3665 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
Douglas Gregorfe921a72010-12-20 23:36:19 +00003667 class pointer {
3668 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregorfe921a72010-12-20 23:36:19 +00003670 public:
3671 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregorfe921a72010-12-20 23:36:19 +00003673 const TemplateArgumentLoc *operator->() const { return &Arg; }
3674 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003675
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003676 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregorfe921a72010-12-20 23:36:19 +00003678 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3679 InputIterator Iter)
3680 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003681
Douglas Gregorfe921a72010-12-20 23:36:19 +00003682 TemplateArgumentLocInventIterator &operator++() {
3683 ++Iter;
3684 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003686
Douglas Gregorfe921a72010-12-20 23:36:19 +00003687 TemplateArgumentLocInventIterator operator++(int) {
3688 TemplateArgumentLocInventIterator Old(*this);
3689 ++(*this);
3690 return Old;
3691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregorfe921a72010-12-20 23:36:19 +00003693 reference operator*() const {
3694 TemplateArgumentLoc Result;
3695 Self.InventTemplateArgumentLoc(*Iter, Result);
3696 return Result;
3697 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregorfe921a72010-12-20 23:36:19 +00003699 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003700
Douglas Gregorfe921a72010-12-20 23:36:19 +00003701 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3702 const TemplateArgumentLocInventIterator &Y) {
3703 return X.Iter == Y.Iter;
3704 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003705
Douglas Gregorfe921a72010-12-20 23:36:19 +00003706 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3707 const TemplateArgumentLocInventIterator &Y) {
3708 return X.Iter != Y.Iter;
3709 }
3710};
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
Douglas Gregor42cafa82010-12-20 17:42:22 +00003712template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003713template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003714bool TreeTransform<Derived>::TransformTemplateArguments(
3715 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3716 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003717 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003718 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003719 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003721 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3722 // Unpack argument packs, which we translate them into separate
3723 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003724 // FIXME: We could do much better if we could guarantee that the
3725 // TemplateArgumentLocInfo for the pack expansion would be usable for
3726 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003727 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003728 TemplateArgument::pack_iterator>
3729 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003730 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003731 In.getArgument().pack_begin()),
3732 PackLocIterator(*this,
3733 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003734 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003735 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003736
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003737 continue;
3738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003739
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003740 if (In.getArgument().isPackExpansion()) {
3741 // We have a pack expansion, for which we will be substituting into
3742 // the pattern.
3743 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003744 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003745 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003746 = getSema().getTemplateArgumentPackExpansionPattern(
3747 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
Chris Lattner01cf8db2011-07-20 06:58:45 +00003749 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003750 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3751 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003752
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003753 // Determine whether the set of unexpanded parameter packs can and should
3754 // be expanded.
3755 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003756 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003757 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003758 if (getDerived().TryExpandParameterPacks(Ellipsis,
3759 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003760 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003761 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003762 RetainExpansion,
3763 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003764 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003765
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003766 if (!Expand) {
3767 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003768 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003769 // expansion.
3770 TemplateArgumentLoc OutPattern;
3771 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003772 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003773 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003775 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3776 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003777 if (Out.getArgument().isNull())
3778 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003779
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003780 Outputs.addArgument(Out);
3781 continue;
3782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003783
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003784 // The transform has determined that we should perform an elementwise
3785 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003786 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003787 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3788
Richard Smithd784e682015-09-23 21:41:42 +00003789 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003790 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003792 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003793 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3794 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003795 if (Out.getArgument().isNull())
3796 return true;
3797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003799 Outputs.addArgument(Out);
3800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003801
Douglas Gregor48d24112011-01-10 20:53:55 +00003802 // If we're supposed to retain a pack expansion, do so by temporarily
3803 // forgetting the partially-substituted parameter pack.
3804 if (RetainExpansion) {
3805 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003806
Richard Smithd784e682015-09-23 21:41:42 +00003807 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003808 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003809
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003810 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3811 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003812 if (Out.getArgument().isNull())
3813 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Douglas Gregor48d24112011-01-10 20:53:55 +00003815 Outputs.addArgument(Out);
3816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003817
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003818 continue;
3819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
3821 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003822 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003823 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003824
Douglas Gregor42cafa82010-12-20 17:42:22 +00003825 Outputs.addArgument(Out);
3826 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003827
Douglas Gregor42cafa82010-12-20 17:42:22 +00003828 return false;
3829
3830}
3831
Douglas Gregord6ff3322009-08-04 16:50:30 +00003832//===----------------------------------------------------------------------===//
3833// Type transformation
3834//===----------------------------------------------------------------------===//
3835
3836template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003837QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003838 if (getDerived().AlreadyTransformed(T))
3839 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003840
John McCall550e0c22009-10-21 00:40:46 +00003841 // Temporary workaround. All of these transformations should
3842 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003843 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3844 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003845
John McCall31f82722010-11-12 08:19:04 +00003846 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003847
John McCall550e0c22009-10-21 00:40:46 +00003848 if (!NewDI)
3849 return QualType();
3850
3851 return NewDI->getType();
3852}
3853
3854template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003855TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003856 // Refine the base location to the type's location.
3857 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3858 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003859 if (getDerived().AlreadyTransformed(DI->getType()))
3860 return DI;
3861
3862 TypeLocBuilder TLB;
3863
3864 TypeLoc TL = DI->getTypeLoc();
3865 TLB.reserve(TL.getFullDataSize());
3866
John McCall31f82722010-11-12 08:19:04 +00003867 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003868 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003869 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003870
John McCallbcd03502009-12-07 02:54:59 +00003871 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003872}
3873
3874template<typename Derived>
3875QualType
John McCall31f82722010-11-12 08:19:04 +00003876TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003877 switch (T.getTypeLocClass()) {
3878#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003879#define TYPELOC(CLASS, PARENT) \
3880 case TypeLoc::CLASS: \
3881 return getDerived().Transform##CLASS##Type(TLB, \
3882 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003883#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003884 }
Mike Stump11289f42009-09-09 15:08:12 +00003885
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003886 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003887}
3888
3889/// FIXME: By default, this routine adds type qualifiers only to types
3890/// that can have qualifiers, and silently suppresses those qualifiers
3891/// that are not permitted (e.g., qualifiers on reference or function
3892/// types). This is the right thing for template instantiation, but
3893/// probably not for other clients.
3894template<typename Derived>
3895QualType
3896TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003897 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003898 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003899
John McCall31f82722010-11-12 08:19:04 +00003900 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003901 if (Result.isNull())
3902 return QualType();
3903
3904 // Silently suppress qualifiers if the result type can't be qualified.
3905 // FIXME: this is the right thing for template instantiation, but
3906 // probably not for other clients.
3907 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003908 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003909
John McCall31168b02011-06-15 23:02:42 +00003910 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003911 // resulting type.
3912 if (Quals.hasObjCLifetime()) {
3913 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3914 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003915 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003916 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003917 // A lifetime qualifier applied to a substituted template parameter
3918 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003919 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003920 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003921 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3922 QualType Replacement = SubstTypeParam->getReplacementType();
3923 Qualifiers Qs = Replacement.getQualifiers();
3924 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003925 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003926 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3927 Qs);
3928 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003929 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003930 Replacement);
3931 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003932 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3933 // 'auto' types behave the same way as template parameters.
3934 QualType Deduced = AutoTy->getDeducedType();
3935 Qualifiers Qs = Deduced.getQualifiers();
3936 Qs.removeObjCLifetime();
3937 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3938 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00003939 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00003940 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003941 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003942 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003943 // Otherwise, complain about the addition of a qualifier to an
3944 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003945 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003946 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003947 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003948
Douglas Gregore46db902011-06-17 22:11:49 +00003949 Quals.removeObjCLifetime();
3950 }
3951 }
3952 }
John McCallcb0f89a2010-06-05 06:41:15 +00003953 if (!Quals.empty()) {
3954 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003955 // BuildQualifiedType might not add qualifiers if they are invalid.
3956 if (Result.hasLocalQualifiers())
3957 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003958 // No location information to preserve.
3959 }
John McCall550e0c22009-10-21 00:40:46 +00003960
3961 return Result;
3962}
3963
Douglas Gregor14454802011-02-25 02:25:35 +00003964template<typename Derived>
3965TypeLoc
3966TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3967 QualType ObjectType,
3968 NamedDecl *UnqualLookup,
3969 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003970 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003971 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003972
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003973 TypeSourceInfo *TSI =
3974 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3975 if (TSI)
3976 return TSI->getTypeLoc();
3977 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003978}
3979
Douglas Gregor579c15f2011-03-02 18:32:08 +00003980template<typename Derived>
3981TypeSourceInfo *
3982TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3983 QualType ObjectType,
3984 NamedDecl *UnqualLookup,
3985 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003986 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003987 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003988
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003989 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3990 UnqualLookup, SS);
3991}
3992
3993template <typename Derived>
3994TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3995 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3996 CXXScopeSpec &SS) {
3997 QualType T = TL.getType();
3998 assert(!getDerived().AlreadyTransformed(T));
3999
Douglas Gregor579c15f2011-03-02 18:32:08 +00004000 TypeLocBuilder TLB;
4001 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004002
Douglas Gregor579c15f2011-03-02 18:32:08 +00004003 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004004 TemplateSpecializationTypeLoc SpecTL =
4005 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004006
Douglas Gregor579c15f2011-03-02 18:32:08 +00004007 TemplateName Template
4008 = getDerived().TransformTemplateName(SS,
4009 SpecTL.getTypePtr()->getTemplateName(),
4010 SpecTL.getTemplateNameLoc(),
4011 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004012 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004013 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004014
4015 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004016 Template);
4017 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004018 DependentTemplateSpecializationTypeLoc SpecTL =
4019 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004020
Douglas Gregor579c15f2011-03-02 18:32:08 +00004021 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004022 = getDerived().RebuildTemplateName(SS,
4023 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004024 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004025 ObjectType, UnqualLookup);
4026 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004027 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004028
4029 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004030 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004031 Template,
4032 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004033 } else {
4034 // Nothing special needs to be done for these.
4035 Result = getDerived().TransformType(TLB, TL);
4036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004037
4038 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004039 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004040
Douglas Gregor579c15f2011-03-02 18:32:08 +00004041 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4042}
4043
John McCall550e0c22009-10-21 00:40:46 +00004044template <class TyLoc> static inline
4045QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4046 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4047 NewT.setNameLoc(T.getNameLoc());
4048 return T.getType();
4049}
4050
John McCall550e0c22009-10-21 00:40:46 +00004051template<typename Derived>
4052QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004053 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004054 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4055 NewT.setBuiltinLoc(T.getBuiltinLoc());
4056 if (T.needsExtraLocalData())
4057 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4058 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059}
Mike Stump11289f42009-09-09 15:08:12 +00004060
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004062QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004063 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004064 // FIXME: recurse?
4065 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
Reid Kleckner0503a872013-12-05 01:23:43 +00004068template <typename Derived>
4069QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4070 AdjustedTypeLoc TL) {
4071 // Adjustments applied during transformation are handled elsewhere.
4072 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4073}
4074
Douglas Gregord6ff3322009-08-04 16:50:30 +00004075template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004076QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4077 DecayedTypeLoc TL) {
4078 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4079 if (OriginalType.isNull())
4080 return QualType();
4081
4082 QualType Result = TL.getType();
4083 if (getDerived().AlwaysRebuild() ||
4084 OriginalType != TL.getOriginalLoc().getType())
4085 Result = SemaRef.Context.getDecayedType(OriginalType);
4086 TLB.push<DecayedTypeLoc>(Result);
4087 // Nothing to set for DecayedTypeLoc.
4088 return Result;
4089}
4090
4091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004092QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004094 QualType PointeeType
4095 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004096 if (PointeeType.isNull())
4097 return QualType();
4098
4099 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004100 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004101 // A dependent pointer type 'T *' has is being transformed such
4102 // that an Objective-C class type is being replaced for 'T'. The
4103 // resulting pointer type is an ObjCObjectPointerType, not a
4104 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004105 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004106
John McCall8b07ec22010-05-15 11:32:37 +00004107 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4108 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004109 return Result;
4110 }
John McCall31f82722010-11-12 08:19:04 +00004111
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004112 if (getDerived().AlwaysRebuild() ||
4113 PointeeType != TL.getPointeeLoc().getType()) {
4114 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4115 if (Result.isNull())
4116 return QualType();
4117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004118
John McCall31168b02011-06-15 23:02:42 +00004119 // Objective-C ARC can add lifetime qualifiers to the type that we're
4120 // pointing to.
4121 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004122
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004123 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4124 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004125 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126}
Mike Stump11289f42009-09-09 15:08:12 +00004127
4128template<typename Derived>
4129QualType
John McCall550e0c22009-10-21 00:40:46 +00004130TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004131 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004132 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004133 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4134 if (PointeeType.isNull())
4135 return QualType();
4136
4137 QualType Result = TL.getType();
4138 if (getDerived().AlwaysRebuild() ||
4139 PointeeType != TL.getPointeeLoc().getType()) {
4140 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004141 TL.getSigilLoc());
4142 if (Result.isNull())
4143 return QualType();
4144 }
4145
Douglas Gregor049211a2010-04-22 16:50:51 +00004146 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004147 NewT.setSigilLoc(TL.getSigilLoc());
4148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
4150
John McCall70dd5f62009-10-30 00:06:24 +00004151/// Transforms a reference type. Note that somewhat paradoxically we
4152/// don't care whether the type itself is an l-value type or an r-value
4153/// type; we only care if the type was *written* as an l-value type
4154/// or an r-value type.
4155template<typename Derived>
4156QualType
4157TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004158 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004159 const ReferenceType *T = TL.getTypePtr();
4160
4161 // Note that this works with the pointee-as-written.
4162 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4163 if (PointeeType.isNull())
4164 return QualType();
4165
4166 QualType Result = TL.getType();
4167 if (getDerived().AlwaysRebuild() ||
4168 PointeeType != T->getPointeeTypeAsWritten()) {
4169 Result = getDerived().RebuildReferenceType(PointeeType,
4170 T->isSpelledAsLValue(),
4171 TL.getSigilLoc());
4172 if (Result.isNull())
4173 return QualType();
4174 }
4175
John McCall31168b02011-06-15 23:02:42 +00004176 // Objective-C ARC can add lifetime qualifiers to the type that we're
4177 // referring to.
4178 TLB.TypeWasModifiedSafely(
4179 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4180
John McCall70dd5f62009-10-30 00:06:24 +00004181 // r-value references can be rebuilt as l-value references.
4182 ReferenceTypeLoc NewTL;
4183 if (isa<LValueReferenceType>(Result))
4184 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4185 else
4186 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4187 NewTL.setSigilLoc(TL.getSigilLoc());
4188
4189 return Result;
4190}
4191
Mike Stump11289f42009-09-09 15:08:12 +00004192template<typename Derived>
4193QualType
John McCall550e0c22009-10-21 00:40:46 +00004194TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004195 LValueReferenceTypeLoc TL) {
4196 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004197}
4198
Mike Stump11289f42009-09-09 15:08:12 +00004199template<typename Derived>
4200QualType
John McCall550e0c22009-10-21 00:40:46 +00004201TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004202 RValueReferenceTypeLoc TL) {
4203 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004207QualType
John McCall550e0c22009-10-21 00:40:46 +00004208TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004209 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004210 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004211 if (PointeeType.isNull())
4212 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004213
Abramo Bagnara509357842011-03-05 14:42:21 +00004214 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004215 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004216 if (OldClsTInfo) {
4217 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4218 if (!NewClsTInfo)
4219 return QualType();
4220 }
4221
4222 const MemberPointerType *T = TL.getTypePtr();
4223 QualType OldClsType = QualType(T->getClass(), 0);
4224 QualType NewClsType;
4225 if (NewClsTInfo)
4226 NewClsType = NewClsTInfo->getType();
4227 else {
4228 NewClsType = getDerived().TransformType(OldClsType);
4229 if (NewClsType.isNull())
4230 return QualType();
4231 }
Mike Stump11289f42009-09-09 15:08:12 +00004232
John McCall550e0c22009-10-21 00:40:46 +00004233 QualType Result = TL.getType();
4234 if (getDerived().AlwaysRebuild() ||
4235 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004236 NewClsType != OldClsType) {
4237 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004238 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004239 if (Result.isNull())
4240 return QualType();
4241 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242
Reid Kleckner0503a872013-12-05 01:23:43 +00004243 // If we had to adjust the pointee type when building a member pointer, make
4244 // sure to push TypeLoc info for it.
4245 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4246 if (MPT && PointeeType != MPT->getPointeeType()) {
4247 assert(isa<AdjustedType>(MPT->getPointeeType()));
4248 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4249 }
4250
John McCall550e0c22009-10-21 00:40:46 +00004251 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4252 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004253 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004254
4255 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004256}
4257
Mike Stump11289f42009-09-09 15:08:12 +00004258template<typename Derived>
4259QualType
John McCall550e0c22009-10-21 00:40:46 +00004260TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004261 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004262 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004263 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004264 if (ElementType.isNull())
4265 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004266
John McCall550e0c22009-10-21 00:40:46 +00004267 QualType Result = TL.getType();
4268 if (getDerived().AlwaysRebuild() ||
4269 ElementType != T->getElementType()) {
4270 Result = getDerived().RebuildConstantArrayType(ElementType,
4271 T->getSizeModifier(),
4272 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004273 T->getIndexTypeCVRQualifiers(),
4274 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004275 if (Result.isNull())
4276 return QualType();
4277 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004278
4279 // We might have either a ConstantArrayType or a VariableArrayType now:
4280 // a ConstantArrayType is allowed to have an element type which is a
4281 // VariableArrayType if the type is dependent. Fortunately, all array
4282 // types have the same location layout.
4283 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004284 NewTL.setLBracketLoc(TL.getLBracketLoc());
4285 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004286
John McCall550e0c22009-10-21 00:40:46 +00004287 Expr *Size = TL.getSizeExpr();
4288 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004289 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4290 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004291 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4292 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004293 }
4294 NewTL.setSizeExpr(Size);
4295
4296 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004297}
Mike Stump11289f42009-09-09 15:08:12 +00004298
Douglas Gregord6ff3322009-08-04 16:50:30 +00004299template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004300QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004301 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004302 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004303 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004304 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004305 if (ElementType.isNull())
4306 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004307
John McCall550e0c22009-10-21 00:40:46 +00004308 QualType Result = TL.getType();
4309 if (getDerived().AlwaysRebuild() ||
4310 ElementType != T->getElementType()) {
4311 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004312 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004313 T->getIndexTypeCVRQualifiers(),
4314 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004315 if (Result.isNull())
4316 return QualType();
4317 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004318
John McCall550e0c22009-10-21 00:40:46 +00004319 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4320 NewTL.setLBracketLoc(TL.getLBracketLoc());
4321 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004322 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004323
4324 return Result;
4325}
4326
4327template<typename Derived>
4328QualType
4329TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004330 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004331 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004332 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4333 if (ElementType.isNull())
4334 return QualType();
4335
John McCalldadc5752010-08-24 06:29:42 +00004336 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004337 = getDerived().TransformExpr(T->getSizeExpr());
4338 if (SizeResult.isInvalid())
4339 return QualType();
4340
Nikola Smiljanic01a75982014-05-29 10:55:11 +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() ||
4346 Size != T->getSizeExpr()) {
4347 Result = getDerived().RebuildVariableArrayType(ElementType,
4348 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +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 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004355
Serge Pavlov774c6d02014-02-06 03:49:11 +00004356 // We might have constant size array now, but fortunately it has the same
4357 // location layout.
4358 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004359 NewTL.setLBracketLoc(TL.getLBracketLoc());
4360 NewTL.setRBracketLoc(TL.getRBracketLoc());
4361 NewTL.setSizeExpr(Size);
4362
4363 return Result;
4364}
4365
4366template<typename Derived>
4367QualType
4368TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004369 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004370 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004371 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4372 if (ElementType.isNull())
4373 return QualType();
4374
Richard Smith764d2fe2011-12-20 02:08:33 +00004375 // Array bounds are constant expressions.
4376 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4377 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004378
John McCall33ddac02011-01-19 10:06:00 +00004379 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4380 Expr *origSize = TL.getSizeExpr();
4381 if (!origSize) origSize = T->getSizeExpr();
4382
4383 ExprResult sizeResult
4384 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004385 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004386 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004387 return QualType();
4388
John McCall33ddac02011-01-19 10:06:00 +00004389 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004390
4391 QualType Result = TL.getType();
4392 if (getDerived().AlwaysRebuild() ||
4393 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004394 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004395 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4396 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004397 size,
John McCall550e0c22009-10-21 00:40:46 +00004398 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004399 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004400 if (Result.isNull())
4401 return QualType();
4402 }
John McCall550e0c22009-10-21 00:40:46 +00004403
4404 // We might have any sort of array type now, but fortunately they
4405 // all have the same location layout.
4406 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4407 NewTL.setLBracketLoc(TL.getLBracketLoc());
4408 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004409 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004410
4411 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004412}
Mike Stump11289f42009-09-09 15:08:12 +00004413
4414template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004415QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004416 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004417 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004418 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004419
4420 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004421 QualType ElementType = getDerived().TransformType(T->getElementType());
4422 if (ElementType.isNull())
4423 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004424
Richard Smith764d2fe2011-12-20 02:08:33 +00004425 // Vector sizes are constant expressions.
4426 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4427 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004428
John McCalldadc5752010-08-24 06:29:42 +00004429 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004430 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004431 if (Size.isInvalid())
4432 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004433
John McCall550e0c22009-10-21 00:40:46 +00004434 QualType Result = TL.getType();
4435 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004436 ElementType != T->getElementType() ||
4437 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004438 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004439 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004440 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004441 if (Result.isNull())
4442 return QualType();
4443 }
John McCall550e0c22009-10-21 00:40:46 +00004444
4445 // Result might be dependent or not.
4446 if (isa<DependentSizedExtVectorType>(Result)) {
4447 DependentSizedExtVectorTypeLoc NewTL
4448 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4449 NewTL.setNameLoc(TL.getNameLoc());
4450 } else {
4451 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4452 NewTL.setNameLoc(TL.getNameLoc());
4453 }
4454
4455 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004456}
Mike Stump11289f42009-09-09 15:08:12 +00004457
4458template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004459QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004460 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004461 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004462 QualType ElementType = getDerived().TransformType(T->getElementType());
4463 if (ElementType.isNull())
4464 return QualType();
4465
John McCall550e0c22009-10-21 00:40:46 +00004466 QualType Result = TL.getType();
4467 if (getDerived().AlwaysRebuild() ||
4468 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004469 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004470 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004471 if (Result.isNull())
4472 return QualType();
4473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004474
John McCall550e0c22009-10-21 00:40:46 +00004475 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4476 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004477
John McCall550e0c22009-10-21 00:40:46 +00004478 return Result;
4479}
4480
4481template<typename Derived>
4482QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004483 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004484 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004485 QualType ElementType = getDerived().TransformType(T->getElementType());
4486 if (ElementType.isNull())
4487 return QualType();
4488
4489 QualType Result = TL.getType();
4490 if (getDerived().AlwaysRebuild() ||
4491 ElementType != T->getElementType()) {
4492 Result = getDerived().RebuildExtVectorType(ElementType,
4493 T->getNumElements(),
4494 /*FIXME*/ SourceLocation());
4495 if (Result.isNull())
4496 return QualType();
4497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004498
John McCall550e0c22009-10-21 00:40:46 +00004499 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4500 NewTL.setNameLoc(TL.getNameLoc());
4501
4502 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004503}
Mike Stump11289f42009-09-09 15:08:12 +00004504
David Blaikie05785d12013-02-20 22:23:23 +00004505template <typename Derived>
4506ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4507 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4508 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004509 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004510 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004511
Douglas Gregor715e4612011-01-14 22:40:04 +00004512 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004513 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004514 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004515 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004516 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004517
Douglas Gregor715e4612011-01-14 22:40:04 +00004518 TypeLocBuilder TLB;
4519 TypeLoc NewTL = OldDI->getTypeLoc();
4520 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004521
4522 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004523 OldExpansionTL.getPatternLoc());
4524 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004525 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004526
4527 Result = RebuildPackExpansionType(Result,
4528 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004529 OldExpansionTL.getEllipsisLoc(),
4530 NumExpansions);
4531 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004532 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004533
Douglas Gregor715e4612011-01-14 22:40:04 +00004534 PackExpansionTypeLoc NewExpansionTL
4535 = TLB.push<PackExpansionTypeLoc>(Result);
4536 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4537 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4538 } else
4539 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004540 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004541 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004542
John McCall8fb0d9d2011-05-01 22:35:37 +00004543 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004544 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004545
4546 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4547 OldParm->getDeclContext(),
4548 OldParm->getInnerLocStart(),
4549 OldParm->getLocation(),
4550 OldParm->getIdentifier(),
4551 NewDI->getType(),
4552 NewDI,
4553 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004554 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004555 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4556 OldParm->getFunctionScopeIndex() + indexAdjustment);
4557 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004558}
4559
4560template<typename Derived>
4561bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004562 TransformFunctionTypeParams(SourceLocation Loc,
4563 ParmVarDecl **Params, unsigned NumParams,
4564 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004565 SmallVectorImpl<QualType> &OutParamTypes,
4566 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004567 int indexAdjustment = 0;
4568
Douglas Gregordd472162011-01-07 00:20:55 +00004569 for (unsigned i = 0; i != NumParams; ++i) {
4570 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004571 assert(OldParm->getFunctionScopeIndex() == i);
4572
David Blaikie05785d12013-02-20 22:23:23 +00004573 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004574 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004575 if (OldParm->isParameterPack()) {
4576 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004577 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004578
Douglas Gregor5499af42011-01-05 23:12:31 +00004579 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004580 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004581 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004582 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4583 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004584 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4585
Douglas Gregor5499af42011-01-05 23:12:31 +00004586 // Determine whether we should expand the parameter packs.
4587 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004588 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004589 Optional<unsigned> OrigNumExpansions =
4590 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004591 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004592 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4593 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004594 Unexpanded,
4595 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004596 RetainExpansion,
4597 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004598 return true;
4599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004600
Douglas Gregor5499af42011-01-05 23:12:31 +00004601 if (ShouldExpand) {
4602 // Expand the function parameter pack into multiple, separate
4603 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004604 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004605 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004606 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004607 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004608 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004609 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004610 OrigNumExpansions,
4611 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004612 if (!NewParm)
4613 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004614
Douglas Gregordd472162011-01-07 00:20:55 +00004615 OutParamTypes.push_back(NewParm->getType());
4616 if (PVars)
4617 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004618 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004619
4620 // If we're supposed to retain a pack expansion, do so by temporarily
4621 // forgetting the partially-substituted parameter pack.
4622 if (RetainExpansion) {
4623 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004624 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004625 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004626 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004627 OrigNumExpansions,
4628 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004629 if (!NewParm)
4630 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004631
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004632 OutParamTypes.push_back(NewParm->getType());
4633 if (PVars)
4634 PVars->push_back(NewParm);
4635 }
4636
John McCall8fb0d9d2011-05-01 22:35:37 +00004637 // The next parameter should have the same adjustment as the
4638 // last thing we pushed, but we post-incremented indexAdjustment
4639 // on every push. Also, if we push nothing, the adjustment should
4640 // go down by one.
4641 indexAdjustment--;
4642
Douglas Gregor5499af42011-01-05 23:12:31 +00004643 // We're done with the pack expansion.
4644 continue;
4645 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004646
4647 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004648 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004649 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4650 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004651 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004652 NumExpansions,
4653 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004654 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004655 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004656 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004657 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004658
John McCall58f10c32010-03-11 09:03:00 +00004659 if (!NewParm)
4660 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004661
Douglas Gregordd472162011-01-07 00:20:55 +00004662 OutParamTypes.push_back(NewParm->getType());
4663 if (PVars)
4664 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004665 continue;
4666 }
John McCall58f10c32010-03-11 09:03:00 +00004667
4668 // Deal with the possibility that we don't have a parameter
4669 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004670 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004671 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004672 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004673 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004674 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004675 = dyn_cast<PackExpansionType>(OldType)) {
4676 // We have a function parameter pack that may need to be expanded.
4677 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004678 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004679 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004680
Douglas Gregor5499af42011-01-05 23:12:31 +00004681 // Determine whether we should expand the parameter packs.
4682 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004683 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004684 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004685 Unexpanded,
4686 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004687 RetainExpansion,
4688 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004689 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004690 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004691
Douglas Gregor5499af42011-01-05 23:12:31 +00004692 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004693 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004694 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004695 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004696 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4697 QualType NewType = getDerived().TransformType(Pattern);
4698 if (NewType.isNull())
4699 return true;
John McCall58f10c32010-03-11 09:03:00 +00004700
Douglas Gregordd472162011-01-07 00:20:55 +00004701 OutParamTypes.push_back(NewType);
4702 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004703 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004704 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004705
Douglas Gregor5499af42011-01-05 23:12:31 +00004706 // We're done with the pack expansion.
4707 continue;
4708 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004709
Douglas Gregor48d24112011-01-10 20:53:55 +00004710 // If we're supposed to retain a pack expansion, do so by temporarily
4711 // forgetting the partially-substituted parameter pack.
4712 if (RetainExpansion) {
4713 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4714 QualType NewType = getDerived().TransformType(Pattern);
4715 if (NewType.isNull())
4716 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004717
Douglas Gregor48d24112011-01-10 20:53:55 +00004718 OutParamTypes.push_back(NewType);
4719 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004720 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004721 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004722
Chad Rosier1dcde962012-08-08 18:46:20 +00004723 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004724 // expansion.
4725 OldType = Expansion->getPattern();
4726 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004727 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4728 NewType = getDerived().TransformType(OldType);
4729 } else {
4730 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004731 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004732
Douglas Gregor5499af42011-01-05 23:12:31 +00004733 if (NewType.isNull())
4734 return true;
4735
4736 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004737 NewType = getSema().Context.getPackExpansionType(NewType,
4738 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004739
Douglas Gregordd472162011-01-07 00:20:55 +00004740 OutParamTypes.push_back(NewType);
4741 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004742 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004743 }
4744
John McCall8fb0d9d2011-05-01 22:35:37 +00004745#ifndef NDEBUG
4746 if (PVars) {
4747 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4748 if (ParmVarDecl *parm = (*PVars)[i])
4749 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004750 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004751#endif
4752
4753 return false;
4754}
John McCall58f10c32010-03-11 09:03:00 +00004755
4756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004757QualType
John McCall550e0c22009-10-21 00:40:46 +00004758TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004759 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004760 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004761 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004762 return getDerived().TransformFunctionProtoType(
4763 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004764 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4765 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4766 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004767 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004768}
4769
Richard Smith2e321552014-11-12 02:00:47 +00004770template<typename Derived> template<typename Fn>
4771QualType TreeTransform<Derived>::TransformFunctionProtoType(
4772 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4773 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004774 // Transform the parameters and return type.
4775 //
Richard Smithf623c962012-04-17 00:58:00 +00004776 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004777 // When the function has a trailing return type, we instantiate the
4778 // parameters before the return type, since the return type can then refer
4779 // to the parameters themselves (via decltype, sizeof, etc.).
4780 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004781 SmallVector<QualType, 4> ParamTypes;
4782 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004783 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004784
Douglas Gregor7fb25412010-10-01 18:44:50 +00004785 QualType ResultType;
4786
Richard Smith1226c602012-08-14 22:51:13 +00004787 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004788 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004789 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004790 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004791 return QualType();
4792
Douglas Gregor3024f072012-04-16 07:05:22 +00004793 {
4794 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004795 // If a declaration declares a member function or member function
4796 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004797 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004798 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004799 // declarator.
4800 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004801
Alp Toker42a16a62014-01-25 23:51:36 +00004802 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004803 if (ResultType.isNull())
4804 return QualType();
4805 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004806 }
4807 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004808 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004809 if (ResultType.isNull())
4810 return QualType();
4811
Alp Toker9cacbab2014-01-20 20:26:09 +00004812 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004813 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004814 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004815 return QualType();
4816 }
4817
Richard Smith2e321552014-11-12 02:00:47 +00004818 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4819
4820 bool EPIChanged = false;
4821 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4822 return QualType();
4823
4824 // FIXME: Need to transform ConsumedParameters for variadic template
4825 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004826
John McCall550e0c22009-10-21 00:40:46 +00004827 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004828 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004829 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004830 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004831 if (Result.isNull())
4832 return QualType();
4833 }
Mike Stump11289f42009-09-09 15:08:12 +00004834
John McCall550e0c22009-10-21 00:40:46 +00004835 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004836 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004837 NewTL.setLParenLoc(TL.getLParenLoc());
4838 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004839 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004840 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4841 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004842
4843 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004844}
Mike Stump11289f42009-09-09 15:08:12 +00004845
Douglas Gregord6ff3322009-08-04 16:50:30 +00004846template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004847bool TreeTransform<Derived>::TransformExceptionSpec(
4848 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4849 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4850 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4851
4852 // Instantiate a dynamic noexcept expression, if any.
4853 if (ESI.Type == EST_ComputedNoexcept) {
4854 EnterExpressionEvaluationContext Unevaluated(getSema(),
4855 Sema::ConstantEvaluated);
4856 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4857 if (NoexceptExpr.isInvalid())
4858 return true;
4859
4860 NoexceptExpr = getSema().CheckBooleanCondition(
4861 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4862 if (NoexceptExpr.isInvalid())
4863 return true;
4864
4865 if (!NoexceptExpr.get()->isValueDependent()) {
4866 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4867 NoexceptExpr.get(), nullptr,
4868 diag::err_noexcept_needs_constant_expression,
4869 /*AllowFold*/false);
4870 if (NoexceptExpr.isInvalid())
4871 return true;
4872 }
4873
4874 if (ESI.NoexceptExpr != NoexceptExpr.get())
4875 Changed = true;
4876 ESI.NoexceptExpr = NoexceptExpr.get();
4877 }
4878
4879 if (ESI.Type != EST_Dynamic)
4880 return false;
4881
4882 // Instantiate a dynamic exception specification's type.
4883 for (QualType T : ESI.Exceptions) {
4884 if (const PackExpansionType *PackExpansion =
4885 T->getAs<PackExpansionType>()) {
4886 Changed = true;
4887
4888 // We have a pack expansion. Instantiate it.
4889 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4890 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4891 Unexpanded);
4892 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4893
4894 // Determine whether the set of unexpanded parameter packs can and
4895 // should
4896 // be expanded.
4897 bool Expand = false;
4898 bool RetainExpansion = false;
4899 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4900 // FIXME: Track the location of the ellipsis (and track source location
4901 // information for the types in the exception specification in general).
4902 if (getDerived().TryExpandParameterPacks(
4903 Loc, SourceRange(), Unexpanded, Expand,
4904 RetainExpansion, NumExpansions))
4905 return true;
4906
4907 if (!Expand) {
4908 // We can't expand this pack expansion into separate arguments yet;
4909 // just substitute into the pattern and create a new pack expansion
4910 // type.
4911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4912 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4913 if (U.isNull())
4914 return true;
4915
4916 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4917 Exceptions.push_back(U);
4918 continue;
4919 }
4920
4921 // Substitute into the pack expansion pattern for each slice of the
4922 // pack.
4923 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4924 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4925
4926 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4927 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4928 return true;
4929
4930 Exceptions.push_back(U);
4931 }
4932 } else {
4933 QualType U = getDerived().TransformType(T);
4934 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4935 return true;
4936 if (T != U)
4937 Changed = true;
4938
4939 Exceptions.push_back(U);
4940 }
4941 }
4942
4943 ESI.Exceptions = Exceptions;
4944 return false;
4945}
4946
4947template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004948QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004949 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004950 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004951 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004952 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004953 if (ResultType.isNull())
4954 return QualType();
4955
4956 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004957 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004958 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4959
4960 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004961 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004962 NewTL.setLParenLoc(TL.getLParenLoc());
4963 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004964 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004965
4966 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004967}
Mike Stump11289f42009-09-09 15:08:12 +00004968
John McCallb96ec562009-12-04 22:46:56 +00004969template<typename Derived> QualType
4970TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004971 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004972 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004973 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004974 if (!D)
4975 return QualType();
4976
4977 QualType Result = TL.getType();
4978 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4979 Result = getDerived().RebuildUnresolvedUsingType(D);
4980 if (Result.isNull())
4981 return QualType();
4982 }
4983
4984 // We might get an arbitrary type spec type back. We should at
4985 // least always get a type spec type, though.
4986 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4987 NewTL.setNameLoc(TL.getNameLoc());
4988
4989 return Result;
4990}
4991
Douglas Gregord6ff3322009-08-04 16:50:30 +00004992template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004993QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004994 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004995 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004996 TypedefNameDecl *Typedef
4997 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4998 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004999 if (!Typedef)
5000 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005001
John McCall550e0c22009-10-21 00:40:46 +00005002 QualType Result = TL.getType();
5003 if (getDerived().AlwaysRebuild() ||
5004 Typedef != T->getDecl()) {
5005 Result = getDerived().RebuildTypedefType(Typedef);
5006 if (Result.isNull())
5007 return QualType();
5008 }
Mike Stump11289f42009-09-09 15:08:12 +00005009
John McCall550e0c22009-10-21 00:40:46 +00005010 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5011 NewTL.setNameLoc(TL.getNameLoc());
5012
5013 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005014}
Mike Stump11289f42009-09-09 15:08:12 +00005015
Douglas Gregord6ff3322009-08-04 16:50:30 +00005016template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005017QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005018 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005019 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5021 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005022
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005024 if (E.isInvalid())
5025 return QualType();
5026
Eli Friedmane4f22df2012-02-29 04:03:55 +00005027 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5028 if (E.isInvalid())
5029 return QualType();
5030
John McCall550e0c22009-10-21 00:40:46 +00005031 QualType Result = TL.getType();
5032 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005033 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005034 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005035 if (Result.isNull())
5036 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005037 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005038 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005039
John McCall550e0c22009-10-21 00:40:46 +00005040 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005041 NewTL.setTypeofLoc(TL.getTypeofLoc());
5042 NewTL.setLParenLoc(TL.getLParenLoc());
5043 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005044
5045 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005046}
Mike Stump11289f42009-09-09 15:08:12 +00005047
5048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005049QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005050 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005051 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5052 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5053 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005054 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005055
John McCall550e0c22009-10-21 00:40:46 +00005056 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005057 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5058 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005059 if (Result.isNull())
5060 return QualType();
5061 }
Mike Stump11289f42009-09-09 15:08:12 +00005062
John McCall550e0c22009-10-21 00:40:46 +00005063 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005064 NewTL.setTypeofLoc(TL.getTypeofLoc());
5065 NewTL.setLParenLoc(TL.getLParenLoc());
5066 NewTL.setRParenLoc(TL.getRParenLoc());
5067 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005068
5069 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005070}
Mike Stump11289f42009-09-09 15:08:12 +00005071
5072template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005073QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005074 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005075 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005076
Douglas Gregore922c772009-08-04 22:27:00 +00005077 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005078 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5079 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005080
John McCalldadc5752010-08-24 06:29:42 +00005081 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005082 if (E.isInvalid())
5083 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005084
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005085 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005086 if (E.isInvalid())
5087 return QualType();
5088
John McCall550e0c22009-10-21 00:40:46 +00005089 QualType Result = TL.getType();
5090 if (getDerived().AlwaysRebuild() ||
5091 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005092 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005093 if (Result.isNull())
5094 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005095 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005096 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005097
John McCall550e0c22009-10-21 00:40:46 +00005098 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5099 NewTL.setNameLoc(TL.getNameLoc());
5100
5101 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005102}
5103
5104template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005105QualType TreeTransform<Derived>::TransformUnaryTransformType(
5106 TypeLocBuilder &TLB,
5107 UnaryTransformTypeLoc TL) {
5108 QualType Result = TL.getType();
5109 if (Result->isDependentType()) {
5110 const UnaryTransformType *T = TL.getTypePtr();
5111 QualType NewBase =
5112 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5113 Result = getDerived().RebuildUnaryTransformType(NewBase,
5114 T->getUTTKind(),
5115 TL.getKWLoc());
5116 if (Result.isNull())
5117 return QualType();
5118 }
5119
5120 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5121 NewTL.setKWLoc(TL.getKWLoc());
5122 NewTL.setParensRange(TL.getParensRange());
5123 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5124 return Result;
5125}
5126
5127template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005128QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5129 AutoTypeLoc TL) {
5130 const AutoType *T = TL.getTypePtr();
5131 QualType OldDeduced = T->getDeducedType();
5132 QualType NewDeduced;
5133 if (!OldDeduced.isNull()) {
5134 NewDeduced = getDerived().TransformType(OldDeduced);
5135 if (NewDeduced.isNull())
5136 return QualType();
5137 }
5138
5139 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005140 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5141 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005142 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005143 if (Result.isNull())
5144 return QualType();
5145 }
5146
5147 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5148 NewTL.setNameLoc(TL.getNameLoc());
5149
5150 return Result;
5151}
5152
5153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005154QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005155 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005156 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005157 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005158 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5159 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005160 if (!Record)
5161 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005162
John McCall550e0c22009-10-21 00:40:46 +00005163 QualType Result = TL.getType();
5164 if (getDerived().AlwaysRebuild() ||
5165 Record != T->getDecl()) {
5166 Result = getDerived().RebuildRecordType(Record);
5167 if (Result.isNull())
5168 return QualType();
5169 }
Mike Stump11289f42009-09-09 15:08:12 +00005170
John McCall550e0c22009-10-21 00:40:46 +00005171 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5172 NewTL.setNameLoc(TL.getNameLoc());
5173
5174 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005175}
Mike Stump11289f42009-09-09 15:08:12 +00005176
5177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005178QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005179 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005180 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005181 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005182 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5183 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005184 if (!Enum)
5185 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005186
John McCall550e0c22009-10-21 00:40:46 +00005187 QualType Result = TL.getType();
5188 if (getDerived().AlwaysRebuild() ||
5189 Enum != T->getDecl()) {
5190 Result = getDerived().RebuildEnumType(Enum);
5191 if (Result.isNull())
5192 return QualType();
5193 }
Mike Stump11289f42009-09-09 15:08:12 +00005194
John McCall550e0c22009-10-21 00:40:46 +00005195 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5196 NewTL.setNameLoc(TL.getNameLoc());
5197
5198 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005199}
John McCallfcc33b02009-09-05 00:15:47 +00005200
John McCalle78aac42010-03-10 03:28:59 +00005201template<typename Derived>
5202QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5203 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005204 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005205 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5206 TL.getTypePtr()->getDecl());
5207 if (!D) return QualType();
5208
5209 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5210 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5211 return T;
5212}
5213
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214template<typename Derived>
5215QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005216 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005217 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005218 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005219}
5220
Mike Stump11289f42009-09-09 15:08:12 +00005221template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005222QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005223 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005224 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005225 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005226
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005227 // Substitute into the replacement type, which itself might involve something
5228 // that needs to be transformed. This only tends to occur with default
5229 // template arguments of template template parameters.
5230 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5231 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5232 if (Replacement.isNull())
5233 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005234
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005235 // Always canonicalize the replacement type.
5236 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5237 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005238 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005239 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005240
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005241 // Propagate type-source information.
5242 SubstTemplateTypeParmTypeLoc NewTL
5243 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5244 NewTL.setNameLoc(TL.getNameLoc());
5245 return Result;
5246
John McCallcebee162009-10-18 09:09:24 +00005247}
5248
5249template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005250QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5251 TypeLocBuilder &TLB,
5252 SubstTemplateTypeParmPackTypeLoc TL) {
5253 return TransformTypeSpecType(TLB, TL);
5254}
5255
5256template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005257QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005258 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005259 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005260 const TemplateSpecializationType *T = TL.getTypePtr();
5261
Douglas Gregordf846d12011-03-02 18:46:51 +00005262 // The nested-name-specifier never matters in a TemplateSpecializationType,
5263 // because we can't have a dependent nested-name-specifier anyway.
5264 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005265 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005266 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5267 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268 if (Template.isNull())
5269 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005270
John McCall31f82722010-11-12 08:19:04 +00005271 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5272}
5273
Eli Friedman0dfb8892011-10-06 23:00:33 +00005274template<typename Derived>
5275QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5276 AtomicTypeLoc TL) {
5277 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5278 if (ValueType.isNull())
5279 return QualType();
5280
5281 QualType Result = TL.getType();
5282 if (getDerived().AlwaysRebuild() ||
5283 ValueType != TL.getValueLoc().getType()) {
5284 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5285 if (Result.isNull())
5286 return QualType();
5287 }
5288
5289 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5290 NewTL.setKWLoc(TL.getKWLoc());
5291 NewTL.setLParenLoc(TL.getLParenLoc());
5292 NewTL.setRParenLoc(TL.getRParenLoc());
5293
5294 return Result;
5295}
5296
Chad Rosier1dcde962012-08-08 18:46:20 +00005297 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005298 /// container that provides a \c getArgLoc() member function.
5299 ///
5300 /// This iterator is intended to be used with the iterator form of
5301 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5302 template<typename ArgLocContainer>
5303 class TemplateArgumentLocContainerIterator {
5304 ArgLocContainer *Container;
5305 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005306
Douglas Gregorfe921a72010-12-20 23:36:19 +00005307 public:
5308 typedef TemplateArgumentLoc value_type;
5309 typedef TemplateArgumentLoc reference;
5310 typedef int difference_type;
5311 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
Douglas Gregorfe921a72010-12-20 23:36:19 +00005313 class pointer {
5314 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005315
Douglas Gregorfe921a72010-12-20 23:36:19 +00005316 public:
5317 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005318
Douglas Gregorfe921a72010-12-20 23:36:19 +00005319 const TemplateArgumentLoc *operator->() const {
5320 return &Arg;
5321 }
5322 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005323
5324
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005325 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregorfe921a72010-12-20 23:36:19 +00005327 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5328 unsigned Index)
5329 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005330
Douglas Gregorfe921a72010-12-20 23:36:19 +00005331 TemplateArgumentLocContainerIterator &operator++() {
5332 ++Index;
5333 return *this;
5334 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005335
Douglas Gregorfe921a72010-12-20 23:36:19 +00005336 TemplateArgumentLocContainerIterator operator++(int) {
5337 TemplateArgumentLocContainerIterator Old(*this);
5338 ++(*this);
5339 return Old;
5340 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005341
Douglas Gregorfe921a72010-12-20 23:36:19 +00005342 TemplateArgumentLoc operator*() const {
5343 return Container->getArgLoc(Index);
5344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005345
Douglas Gregorfe921a72010-12-20 23:36:19 +00005346 pointer operator->() const {
5347 return pointer(Container->getArgLoc(Index));
5348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005349
Douglas Gregorfe921a72010-12-20 23:36:19 +00005350 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005351 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005352 return X.Container == Y.Container && X.Index == Y.Index;
5353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005354
Douglas Gregorfe921a72010-12-20 23:36:19 +00005355 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005356 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005357 return !(X == Y);
5358 }
5359 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005360
5361
John McCall31f82722010-11-12 08:19:04 +00005362template <typename Derived>
5363QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5364 TypeLocBuilder &TLB,
5365 TemplateSpecializationTypeLoc TL,
5366 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005367 TemplateArgumentListInfo NewTemplateArgs;
5368 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5369 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005370 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5371 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005372 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005373 ArgIterator(TL, TL.getNumArgs()),
5374 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005375 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005376
John McCall0ad16662009-10-29 08:12:44 +00005377 // FIXME: maybe don't rebuild if all the template arguments are the same.
5378
5379 QualType Result =
5380 getDerived().RebuildTemplateSpecializationType(Template,
5381 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005382 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005383
5384 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005385 // Specializations of template template parameters are represented as
5386 // TemplateSpecializationTypes, and substitution of type alias templates
5387 // within a dependent context can transform them into
5388 // DependentTemplateSpecializationTypes.
5389 if (isa<DependentTemplateSpecializationType>(Result)) {
5390 DependentTemplateSpecializationTypeLoc NewTL
5391 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005392 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005393 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005394 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005395 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005396 NewTL.setLAngleLoc(TL.getLAngleLoc());
5397 NewTL.setRAngleLoc(TL.getRAngleLoc());
5398 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5399 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5400 return Result;
5401 }
5402
John McCall0ad16662009-10-29 08:12:44 +00005403 TemplateSpecializationTypeLoc NewTL
5404 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005405 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005406 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5407 NewTL.setLAngleLoc(TL.getLAngleLoc());
5408 NewTL.setRAngleLoc(TL.getRAngleLoc());
5409 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5410 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005411 }
Mike Stump11289f42009-09-09 15:08:12 +00005412
John McCall0ad16662009-10-29 08:12:44 +00005413 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005414}
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregor5a064722011-02-28 17:23:35 +00005416template <typename Derived>
5417QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5418 TypeLocBuilder &TLB,
5419 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005420 TemplateName Template,
5421 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005422 TemplateArgumentListInfo NewTemplateArgs;
5423 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5424 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5425 typedef TemplateArgumentLocContainerIterator<
5426 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005427 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005428 ArgIterator(TL, TL.getNumArgs()),
5429 NewTemplateArgs))
5430 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005431
Douglas Gregor5a064722011-02-28 17:23:35 +00005432 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005433
Douglas Gregor5a064722011-02-28 17:23:35 +00005434 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5435 QualType Result
5436 = getSema().Context.getDependentTemplateSpecializationType(
5437 TL.getTypePtr()->getKeyword(),
5438 DTN->getQualifier(),
5439 DTN->getIdentifier(),
5440 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005441
Douglas Gregor5a064722011-02-28 17:23:35 +00005442 DependentTemplateSpecializationTypeLoc NewTL
5443 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005444 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005445 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005446 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005447 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005448 NewTL.setLAngleLoc(TL.getLAngleLoc());
5449 NewTL.setRAngleLoc(TL.getRAngleLoc());
5450 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5451 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5452 return Result;
5453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005454
5455 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005456 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005457 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005458 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005459
Douglas Gregor5a064722011-02-28 17:23:35 +00005460 if (!Result.isNull()) {
5461 /// FIXME: Wrap this in an elaborated-type-specifier?
5462 TemplateSpecializationTypeLoc NewTL
5463 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005464 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005465 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005466 NewTL.setLAngleLoc(TL.getLAngleLoc());
5467 NewTL.setRAngleLoc(TL.getRAngleLoc());
5468 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5469 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005471
Douglas Gregor5a064722011-02-28 17:23:35 +00005472 return Result;
5473}
5474
Mike Stump11289f42009-09-09 15:08:12 +00005475template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005476QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005477TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005478 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005479 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005480
Douglas Gregor844cb502011-03-01 18:12:44 +00005481 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005482 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005483 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005484 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005485 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5486 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005487 return QualType();
5488 }
Mike Stump11289f42009-09-09 15:08:12 +00005489
John McCall31f82722010-11-12 08:19:04 +00005490 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5491 if (NamedT.isNull())
5492 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005493
Richard Smith3f1b5d02011-05-05 21:57:07 +00005494 // C++0x [dcl.type.elab]p2:
5495 // If the identifier resolves to a typedef-name or the simple-template-id
5496 // resolves to an alias template specialization, the
5497 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005498 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5499 if (const TemplateSpecializationType *TST =
5500 NamedT->getAs<TemplateSpecializationType>()) {
5501 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005502 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5503 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005504 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5505 diag::err_tag_reference_non_tag) << 4;
5506 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5507 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005508 }
5509 }
5510
John McCall550e0c22009-10-21 00:40:46 +00005511 QualType Result = TL.getType();
5512 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005513 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005514 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005515 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005516 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005517 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005518 if (Result.isNull())
5519 return QualType();
5520 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005521
Abramo Bagnara6150c882010-05-11 21:36:43 +00005522 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005523 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005524 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005526}
Mike Stump11289f42009-09-09 15:08:12 +00005527
5528template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005529QualType TreeTransform<Derived>::TransformAttributedType(
5530 TypeLocBuilder &TLB,
5531 AttributedTypeLoc TL) {
5532 const AttributedType *oldType = TL.getTypePtr();
5533 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5534 if (modifiedType.isNull())
5535 return QualType();
5536
5537 QualType result = TL.getType();
5538
5539 // FIXME: dependent operand expressions?
5540 if (getDerived().AlwaysRebuild() ||
5541 modifiedType != oldType->getModifiedType()) {
5542 // TODO: this is really lame; we should really be rebuilding the
5543 // equivalent type from first principles.
5544 QualType equivalentType
5545 = getDerived().TransformType(oldType->getEquivalentType());
5546 if (equivalentType.isNull())
5547 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005548
5549 // Check whether we can add nullability; it is only represented as
5550 // type sugar, and therefore cannot be diagnosed in any other way.
5551 if (auto nullability = oldType->getImmediateNullability()) {
5552 if (!modifiedType->canHaveNullability()) {
5553 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005554 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005555 return QualType();
5556 }
5557 }
5558
John McCall81904512011-01-06 01:58:22 +00005559 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5560 modifiedType,
5561 equivalentType);
5562 }
5563
5564 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5565 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5566 if (TL.hasAttrOperand())
5567 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5568 if (TL.hasAttrExprOperand())
5569 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5570 else if (TL.hasAttrEnumOperand())
5571 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5572
5573 return result;
5574}
5575
5576template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005577QualType
5578TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5579 ParenTypeLoc TL) {
5580 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5581 if (Inner.isNull())
5582 return QualType();
5583
5584 QualType Result = TL.getType();
5585 if (getDerived().AlwaysRebuild() ||
5586 Inner != TL.getInnerLoc().getType()) {
5587 Result = getDerived().RebuildParenType(Inner);
5588 if (Result.isNull())
5589 return QualType();
5590 }
5591
5592 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5593 NewTL.setLParenLoc(TL.getLParenLoc());
5594 NewTL.setRParenLoc(TL.getRParenLoc());
5595 return Result;
5596}
5597
5598template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005599QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005600 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005601 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005602
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005603 NestedNameSpecifierLoc QualifierLoc
5604 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5605 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005606 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005607
John McCallc392f372010-06-11 00:33:02 +00005608 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005609 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005610 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005611 QualifierLoc,
5612 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005613 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005614 if (Result.isNull())
5615 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005616
Abramo Bagnarad7548482010-05-19 21:37:53 +00005617 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5618 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005619 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5620
Abramo Bagnarad7548482010-05-19 21:37:53 +00005621 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005622 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005623 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005624 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005625 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005626 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005627 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005628 NewTL.setNameLoc(TL.getNameLoc());
5629 }
John McCall550e0c22009-10-21 00:40:46 +00005630 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005631}
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregord6ff3322009-08-04 16:50:30 +00005633template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005634QualType TreeTransform<Derived>::
5635 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005636 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005637 NestedNameSpecifierLoc QualifierLoc;
5638 if (TL.getQualifierLoc()) {
5639 QualifierLoc
5640 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5641 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005642 return QualType();
5643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005644
John McCall31f82722010-11-12 08:19:04 +00005645 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005646 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005647}
5648
5649template<typename Derived>
5650QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005651TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5652 DependentTemplateSpecializationTypeLoc TL,
5653 NestedNameSpecifierLoc QualifierLoc) {
5654 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005655
Douglas Gregora7a795b2011-03-01 20:11:18 +00005656 TemplateArgumentListInfo NewTemplateArgs;
5657 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5658 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005659
Douglas Gregora7a795b2011-03-01 20:11:18 +00005660 typedef TemplateArgumentLocContainerIterator<
5661 DependentTemplateSpecializationTypeLoc> ArgIterator;
5662 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5663 ArgIterator(TL, TL.getNumArgs()),
5664 NewTemplateArgs))
5665 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005666
Douglas Gregora7a795b2011-03-01 20:11:18 +00005667 QualType Result
5668 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5669 QualifierLoc,
5670 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005671 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005672 NewTemplateArgs);
5673 if (Result.isNull())
5674 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005675
Douglas Gregora7a795b2011-03-01 20:11:18 +00005676 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5677 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005678
Douglas Gregora7a795b2011-03-01 20:11:18 +00005679 // Copy information relevant to the template specialization.
5680 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005681 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005682 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005683 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005684 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5685 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005686 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005687 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005688
Douglas Gregora7a795b2011-03-01 20:11:18 +00005689 // Copy information relevant to the elaborated type.
5690 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005691 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005692 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005693 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5694 DependentTemplateSpecializationTypeLoc SpecTL
5695 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005696 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005697 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005698 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005699 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005700 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5701 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005702 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005703 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005704 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005705 TemplateSpecializationTypeLoc SpecTL
5706 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005707 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005708 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005709 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5710 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005711 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005712 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005713 }
5714 return Result;
5715}
5716
5717template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005718QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5719 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005720 QualType Pattern
5721 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005722 if (Pattern.isNull())
5723 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005724
5725 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005726 if (getDerived().AlwaysRebuild() ||
5727 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005728 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005729 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005730 TL.getEllipsisLoc(),
5731 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005732 if (Result.isNull())
5733 return QualType();
5734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005735
Douglas Gregor822d0302011-01-12 17:07:58 +00005736 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5737 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5738 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005739}
5740
5741template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005742QualType
5743TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005744 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005745 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005746 TLB.pushFullCopy(TL);
5747 return TL.getType();
5748}
5749
5750template<typename Derived>
5751QualType
5752TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005753 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005754 // Transform base type.
5755 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5756 if (BaseType.isNull())
5757 return QualType();
5758
5759 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5760
5761 // Transform type arguments.
5762 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5763 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5764 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5765 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5766 QualType TypeArg = TypeArgInfo->getType();
5767 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5768 AnyChanged = true;
5769
5770 // We have a pack expansion. Instantiate it.
5771 const auto *PackExpansion = PackExpansionLoc.getType()
5772 ->castAs<PackExpansionType>();
5773 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5774 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5775 Unexpanded);
5776 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5777
5778 // Determine whether the set of unexpanded parameter packs can
5779 // and should be expanded.
5780 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5781 bool Expand = false;
5782 bool RetainExpansion = false;
5783 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5784 if (getDerived().TryExpandParameterPacks(
5785 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5786 Unexpanded, Expand, RetainExpansion, NumExpansions))
5787 return QualType();
5788
5789 if (!Expand) {
5790 // We can't expand this pack expansion into separate arguments yet;
5791 // just substitute into the pattern and create a new pack expansion
5792 // type.
5793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5794
5795 TypeLocBuilder TypeArgBuilder;
5796 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5797 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5798 PatternLoc);
5799 if (NewPatternType.isNull())
5800 return QualType();
5801
5802 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5803 NewPatternType, NumExpansions);
5804 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5805 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5806 NewTypeArgInfos.push_back(
5807 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5808 continue;
5809 }
5810
5811 // Substitute into the pack expansion pattern for each slice of the
5812 // pack.
5813 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5814 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5815
5816 TypeLocBuilder TypeArgBuilder;
5817 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5818
5819 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5820 PatternLoc);
5821 if (NewTypeArg.isNull())
5822 return QualType();
5823
5824 NewTypeArgInfos.push_back(
5825 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5826 }
5827
5828 continue;
5829 }
5830
5831 TypeLocBuilder TypeArgBuilder;
5832 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5833 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5834 if (NewTypeArg.isNull())
5835 return QualType();
5836
5837 // If nothing changed, just keep the old TypeSourceInfo.
5838 if (NewTypeArg == TypeArg) {
5839 NewTypeArgInfos.push_back(TypeArgInfo);
5840 continue;
5841 }
5842
5843 NewTypeArgInfos.push_back(
5844 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5845 AnyChanged = true;
5846 }
5847
5848 QualType Result = TL.getType();
5849 if (getDerived().AlwaysRebuild() || AnyChanged) {
5850 // Rebuild the type.
5851 Result = getDerived().RebuildObjCObjectType(
5852 BaseType,
5853 TL.getLocStart(),
5854 TL.getTypeArgsLAngleLoc(),
5855 NewTypeArgInfos,
5856 TL.getTypeArgsRAngleLoc(),
5857 TL.getProtocolLAngleLoc(),
5858 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5859 TL.getNumProtocols()),
5860 TL.getProtocolLocs(),
5861 TL.getProtocolRAngleLoc());
5862
5863 if (Result.isNull())
5864 return QualType();
5865 }
5866
5867 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5868 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5869 NewT.setHasBaseTypeAsWritten(true);
5870 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5871 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5872 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5873 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5874 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5875 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5876 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5877 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5878 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005879}
Mike Stump11289f42009-09-09 15:08:12 +00005880
5881template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005882QualType
5883TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005884 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005885 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5886 if (PointeeType.isNull())
5887 return QualType();
5888
5889 QualType Result = TL.getType();
5890 if (getDerived().AlwaysRebuild() ||
5891 PointeeType != TL.getPointeeLoc().getType()) {
5892 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5893 TL.getStarLoc());
5894 if (Result.isNull())
5895 return QualType();
5896 }
5897
5898 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5899 NewT.setStarLoc(TL.getStarLoc());
5900 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005901}
5902
Douglas Gregord6ff3322009-08-04 16:50:30 +00005903//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005904// Statement transformation
5905//===----------------------------------------------------------------------===//
5906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005907StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005908TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005909 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005910}
5911
5912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005913StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005914TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5915 return getDerived().TransformCompoundStmt(S, false);
5916}
5917
5918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005919StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005920TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005921 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005922 Sema::CompoundScopeRAII CompoundScope(getSema());
5923
John McCall1ababa62010-08-27 19:56:05 +00005924 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005925 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005926 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005927 for (auto *B : S->body()) {
5928 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005929 if (Result.isInvalid()) {
5930 // Immediately fail if this was a DeclStmt, since it's very
5931 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005932 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005933 return StmtError();
5934
5935 // Otherwise, just keep processing substatements and fail later.
5936 SubStmtInvalid = true;
5937 continue;
5938 }
Mike Stump11289f42009-09-09 15:08:12 +00005939
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005940 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005941 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005942 }
Mike Stump11289f42009-09-09 15:08:12 +00005943
John McCall1ababa62010-08-27 19:56:05 +00005944 if (SubStmtInvalid)
5945 return StmtError();
5946
Douglas Gregorebe10102009-08-20 07:17:43 +00005947 if (!getDerived().AlwaysRebuild() &&
5948 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005949 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005950
5951 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005952 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005953 S->getRBracLoc(),
5954 IsStmtExpr);
5955}
Mike Stump11289f42009-09-09 15:08:12 +00005956
Douglas Gregorebe10102009-08-20 07:17:43 +00005957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005958StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005959TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005960 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005961 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005962 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5963 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005964
Eli Friedman06577382009-11-19 03:14:00 +00005965 // Transform the left-hand case value.
5966 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005967 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005968 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005970
Eli Friedman06577382009-11-19 03:14:00 +00005971 // Transform the right-hand case value (for the GNU case-range extension).
5972 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005973 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005974 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005976 }
Mike Stump11289f42009-09-09 15:08:12 +00005977
Douglas Gregorebe10102009-08-20 07:17:43 +00005978 // Build the case statement.
5979 // Case statements are always rebuilt so that they will attached to their
5980 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005981 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005982 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005983 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005984 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005985 S->getColonLoc());
5986 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005988
Douglas Gregorebe10102009-08-20 07:17:43 +00005989 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005990 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005991 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005992 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregorebe10102009-08-20 07:17:43 +00005994 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005995 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005996}
5997
5998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005999StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006000TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006001 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006002 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006003 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006004 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregorebe10102009-08-20 07:17:43 +00006006 // Default statements are always rebuilt
6007 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006008 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006009}
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregorebe10102009-08-20 07:17:43 +00006011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006012StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006013TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006014 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006017
Chris Lattnercab02a62011-02-17 20:34:02 +00006018 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6019 S->getDecl());
6020 if (!LD)
6021 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006022
6023
Douglas Gregorebe10102009-08-20 07:17:43 +00006024 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006025 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006026 cast<LabelDecl>(LD), SourceLocation(),
6027 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006028}
Mike Stump11289f42009-09-09 15:08:12 +00006029
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006030template <typename Derived>
6031const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6032 if (!R)
6033 return R;
6034
6035 switch (R->getKind()) {
6036// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6037#define ATTR(X)
6038#define PRAGMA_SPELLING_ATTR(X) \
6039 case attr::X: \
6040 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6041#include "clang/Basic/AttrList.inc"
6042 default:
6043 return R;
6044 }
6045}
6046
6047template <typename Derived>
6048StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6049 bool AttrsChanged = false;
6050 SmallVector<const Attr *, 1> Attrs;
6051
6052 // Visit attributes and keep track if any are transformed.
6053 for (const auto *I : S->getAttrs()) {
6054 const Attr *R = getDerived().TransformAttr(I);
6055 AttrsChanged |= (I != R);
6056 Attrs.push_back(R);
6057 }
6058
Richard Smithc202b282012-04-14 00:33:13 +00006059 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6060 if (SubStmt.isInvalid())
6061 return StmtError();
6062
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006063 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006064 return S;
6065
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006066 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006067 SubStmt.get());
6068}
6069
6070template<typename Derived>
6071StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006072TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006073 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006074 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006075 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006076 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006077 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006078 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006079 getDerived().TransformDefinition(
6080 S->getConditionVariable()->getLocation(),
6081 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006082 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006083 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006084 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006085 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006086
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006087 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006089
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006090 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006091 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006092 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006093 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006094 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006096
John McCallb268a282010-08-23 23:25:46 +00006097 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006098 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006100
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006101 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006102 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006103 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006104
Douglas Gregorebe10102009-08-20 07:17:43 +00006105 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006106 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006107 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006108 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregorebe10102009-08-20 07:17:43 +00006110 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006111 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006112 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006114
Douglas Gregorebe10102009-08-20 07:17:43 +00006115 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006116 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006117 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006118 Then.get() == S->getThen() &&
6119 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006120 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006122 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006123 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006124 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006125}
6126
6127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006128StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006129TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006130 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006131 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006132 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006133 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006134 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006135 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006136 getDerived().TransformDefinition(
6137 S->getConditionVariable()->getLocation(),
6138 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006139 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006141 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006142 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006143
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006144 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006146 }
Mike Stump11289f42009-09-09 15:08:12 +00006147
Douglas Gregorebe10102009-08-20 07:17:43 +00006148 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006149 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006150 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006151 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregorebe10102009-08-20 07:17:43 +00006155 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006156 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006158 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006159
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006161 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6162 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006163}
Mike Stump11289f42009-09-09 15:08:12 +00006164
Douglas Gregorebe10102009-08-20 07:17:43 +00006165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006166StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006167TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006168 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006169 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006170 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006171 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006172 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006173 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006174 getDerived().TransformDefinition(
6175 S->getConditionVariable()->getLocation(),
6176 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006177 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006179 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006180 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006181
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006182 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006184
6185 if (S->getCond()) {
6186 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006187 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6188 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006189 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006190 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006192 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006193 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006194 }
Mike Stump11289f42009-09-09 15:08:12 +00006195
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006196 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006197 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006199
Douglas Gregorebe10102009-08-20 07:17:43 +00006200 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006201 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006202 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006204
Douglas Gregorebe10102009-08-20 07:17:43 +00006205 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006206 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006207 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006208 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006209 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006210
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006211 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006212 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006213}
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregorebe10102009-08-20 07:17:43 +00006215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006216StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006217TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006218 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006219 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006220 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006221 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006222
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006223 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006224 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006225 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006226 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006227
Douglas Gregorebe10102009-08-20 07:17:43 +00006228 if (!getDerived().AlwaysRebuild() &&
6229 Cond.get() == S->getCond() &&
6230 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006231 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006232
John McCallb268a282010-08-23 23:25:46 +00006233 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6234 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006235 S->getRParenLoc());
6236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregorebe10102009-08-20 07:17:43 +00006238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006239StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006240TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006241 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006242 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006243 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006244 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006245
Douglas Gregorebe10102009-08-20 07:17:43 +00006246 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006247 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006248 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006249 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006250 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006251 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006252 getDerived().TransformDefinition(
6253 S->getConditionVariable()->getLocation(),
6254 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006255 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006256 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006257 } else {
6258 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006260 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006261 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006262
6263 if (S->getCond()) {
6264 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006265 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6266 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006267 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006268 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006269 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006270
John McCallb268a282010-08-23 23:25:46 +00006271 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006272 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006273 }
Mike Stump11289f42009-09-09 15:08:12 +00006274
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006275 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006276 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006277 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006278
Douglas Gregorebe10102009-08-20 07:17:43 +00006279 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006280 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006281 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006282 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006283
Richard Smith945f8d32013-01-14 22:39:08 +00006284 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006285 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006286 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006287
Douglas Gregorebe10102009-08-20 07:17:43 +00006288 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006289 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006290 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregorebe10102009-08-20 07:17:43 +00006293 if (!getDerived().AlwaysRebuild() &&
6294 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006295 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006296 Inc.get() == S->getInc() &&
6297 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006298 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregorebe10102009-08-20 07:17:43 +00006300 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006301 Init.get(), FullCond, ConditionVar,
6302 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006303}
6304
6305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006306StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006307TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006308 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6309 S->getLabel());
6310 if (!LD)
6311 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006312
Douglas Gregorebe10102009-08-20 07:17:43 +00006313 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006314 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006315 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006316}
6317
6318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006319StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006320TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006321 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006322 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006323 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006324 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregorebe10102009-08-20 07:17:43 +00006326 if (!getDerived().AlwaysRebuild() &&
6327 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006328 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006329
6330 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006331 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006332}
6333
6334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006335StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006336TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006337 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006338}
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregorebe10102009-08-20 07:17:43 +00006340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006341StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006342TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006343 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006344}
Mike Stump11289f42009-09-09 15:08:12 +00006345
Douglas Gregorebe10102009-08-20 07:17:43 +00006346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006347StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006348TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006349 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6350 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006351 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006352 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006353
Mike Stump11289f42009-09-09 15:08:12 +00006354 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006355 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006356 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006357}
Mike Stump11289f42009-09-09 15:08:12 +00006358
Douglas Gregorebe10102009-08-20 07:17:43 +00006359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006360StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006361TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006362 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006363 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006364 for (auto *D : S->decls()) {
6365 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006366 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006367 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006368
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006369 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006370 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregorebe10102009-08-20 07:17:43 +00006372 Decls.push_back(Transformed);
6373 }
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregorebe10102009-08-20 07:17:43 +00006375 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006376 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006377
Rafael Espindolaab417692013-07-09 12:05:01 +00006378 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006379}
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregorebe10102009-08-20 07:17:43 +00006381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006382StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006383TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006384
Benjamin Kramerf0623432012-08-23 22:51:59 +00006385 SmallVector<Expr*, 8> Constraints;
6386 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006387 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006388
John McCalldadc5752010-08-24 06:29:42 +00006389 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006390 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006391
6392 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006393
Anders Carlssonaaeef072010-01-24 05:50:09 +00006394 // Go through the outputs.
6395 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006396 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006397
Anders Carlssonaaeef072010-01-24 05:50:09 +00006398 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006399 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006400
Anders Carlssonaaeef072010-01-24 05:50:09 +00006401 // Transform the output expr.
6402 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006403 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006404 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006405 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006406
Anders Carlssonaaeef072010-01-24 05:50:09 +00006407 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006408
John McCallb268a282010-08-23 23:25:46 +00006409 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006410 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006411
Anders Carlssonaaeef072010-01-24 05:50:09 +00006412 // Go through the inputs.
6413 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006414 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006415
Anders Carlssonaaeef072010-01-24 05:50:09 +00006416 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006417 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006418
Anders Carlssonaaeef072010-01-24 05:50:09 +00006419 // Transform the input expr.
6420 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006421 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006422 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006424
Anders Carlssonaaeef072010-01-24 05:50:09 +00006425 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006426
John McCallb268a282010-08-23 23:25:46 +00006427 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006429
Anders Carlssonaaeef072010-01-24 05:50:09 +00006430 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006431 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006432
6433 // Go through the clobbers.
6434 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006435 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006436
6437 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006438 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006439 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6440 S->isVolatile(), S->getNumOutputs(),
6441 S->getNumInputs(), Names.data(),
6442 Constraints, Exprs, AsmString.get(),
6443 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006444}
6445
Chad Rosier32503022012-06-11 20:47:18 +00006446template<typename Derived>
6447StmtResult
6448TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006449 ArrayRef<Token> AsmToks =
6450 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006451
John McCallf413f5e2013-05-03 00:10:13 +00006452 bool HadError = false, HadChange = false;
6453
6454 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6455 SmallVector<Expr*, 8> TransformedExprs;
6456 TransformedExprs.reserve(SrcExprs.size());
6457 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6458 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6459 if (!Result.isUsable()) {
6460 HadError = true;
6461 } else {
6462 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006463 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006464 }
6465 }
6466
6467 if (HadError) return StmtError();
6468 if (!HadChange && !getDerived().AlwaysRebuild())
6469 return Owned(S);
6470
Chad Rosierb6f46c12012-08-15 16:53:30 +00006471 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006472 AsmToks, S->getAsmString(),
6473 S->getNumOutputs(), S->getNumInputs(),
6474 S->getAllConstraints(), S->getClobbers(),
6475 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006476}
Douglas Gregorebe10102009-08-20 07:17:43 +00006477
Richard Smith9f690bd2015-10-27 06:02:45 +00006478// C++ Coroutines TS
6479
6480template<typename Derived>
6481StmtResult
6482TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6483 // The coroutine body should be re-formed by the caller if necessary.
6484 return getDerived().TransformStmt(S->getBody());
6485}
6486
6487template<typename Derived>
6488StmtResult
6489TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6490 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6491 /*NotCopyInit*/false);
6492 if (Result.isInvalid())
6493 return StmtError();
6494
6495 // Always rebuild; we don't know if this needs to be injected into a new
6496 // context or if the promise type has changed.
6497 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6498}
6499
6500template<typename Derived>
6501ExprResult
6502TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6503 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6504 /*NotCopyInit*/false);
6505 if (Result.isInvalid())
6506 return ExprError();
6507
6508 // Always rebuild; we don't know if this needs to be injected into a new
6509 // context or if the promise type has changed.
6510 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6511}
6512
6513template<typename Derived>
6514ExprResult
6515TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6516 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6517 /*NotCopyInit*/false);
6518 if (Result.isInvalid())
6519 return ExprError();
6520
6521 // Always rebuild; we don't know if this needs to be injected into a new
6522 // context or if the promise type has changed.
6523 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6524}
6525
6526// Objective-C Statements.
6527
Douglas Gregorebe10102009-08-20 07:17:43 +00006528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006529StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006530TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006531 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006532 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006533 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006535
Douglas Gregor96c79492010-04-23 22:50:49 +00006536 // Transform the @catch statements (if present).
6537 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006538 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006539 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006540 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006541 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006542 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006543 if (Catch.get() != S->getCatchStmt(I))
6544 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006545 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006546 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006547
Douglas Gregor306de2f2010-04-22 23:59:56 +00006548 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006549 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006550 if (S->getFinallyStmt()) {
6551 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6552 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006553 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006554 }
6555
6556 // If nothing changed, just retain this statement.
6557 if (!getDerived().AlwaysRebuild() &&
6558 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006559 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006560 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006561 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006562
Douglas Gregor306de2f2010-04-22 23:59:56 +00006563 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006564 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006565 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006566}
Mike Stump11289f42009-09-09 15:08:12 +00006567
Douglas Gregorebe10102009-08-20 07:17:43 +00006568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006569StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006570TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006571 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006572 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006573 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006574 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006575 if (FromVar->getTypeSourceInfo()) {
6576 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6577 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006580
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006581 QualType T;
6582 if (TSInfo)
6583 T = TSInfo->getType();
6584 else {
6585 T = getDerived().TransformType(FromVar->getType());
6586 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006587 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006588 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006589
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006590 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6591 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006592 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006594
John McCalldadc5752010-08-24 06:29:42 +00006595 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006596 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006597 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006598
6599 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006600 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006601 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006602}
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregorebe10102009-08-20 07:17:43 +00006604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006605StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006606TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006607 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006608 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006609 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006611
Douglas Gregor306de2f2010-04-22 23:59:56 +00006612 // If nothing changed, just retain this statement.
6613 if (!getDerived().AlwaysRebuild() &&
6614 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006615 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006616
6617 // Build a new statement.
6618 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006619 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006620}
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregorebe10102009-08-20 07:17:43 +00006622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006624TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006625 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006626 if (S->getThrowExpr()) {
6627 Operand = getDerived().TransformExpr(S->getThrowExpr());
6628 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006629 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006631
Douglas Gregor2900c162010-04-22 21:44:01 +00006632 if (!getDerived().AlwaysRebuild() &&
6633 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006634 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006635
John McCallb268a282010-08-23 23:25:46 +00006636 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006637}
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregorebe10102009-08-20 07:17:43 +00006639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006640StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006641TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006642 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006643 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006644 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006645 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006646 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006647 Object =
6648 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6649 Object.get());
6650 if (Object.isInvalid())
6651 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006652
Douglas Gregor6148de72010-04-22 22:01:21 +00006653 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006654 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006655 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006656 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006657
Douglas Gregor6148de72010-04-22 22:01:21 +00006658 // If nothing change, just retain the current statement.
6659 if (!getDerived().AlwaysRebuild() &&
6660 Object.get() == S->getSynchExpr() &&
6661 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006662 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006663
6664 // Build a new statement.
6665 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006666 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006667}
6668
6669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006670StmtResult
John McCall31168b02011-06-15 23:02:42 +00006671TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6672 ObjCAutoreleasePoolStmt *S) {
6673 // Transform the body.
6674 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6675 if (Body.isInvalid())
6676 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006677
John McCall31168b02011-06-15 23:02:42 +00006678 // If nothing changed, just retain this statement.
6679 if (!getDerived().AlwaysRebuild() &&
6680 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006681 return S;
John McCall31168b02011-06-15 23:02:42 +00006682
6683 // Build a new statement.
6684 return getDerived().RebuildObjCAutoreleasePoolStmt(
6685 S->getAtLoc(), Body.get());
6686}
6687
6688template<typename Derived>
6689StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006690TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006691 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006692 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006693 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006694 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006696
Douglas Gregorf68a5082010-04-22 23:10:45 +00006697 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006698 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006699 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006701
Douglas Gregorf68a5082010-04-22 23:10:45 +00006702 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006703 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006704 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006706
Douglas Gregorf68a5082010-04-22 23:10:45 +00006707 // If nothing changed, just retain this statement.
6708 if (!getDerived().AlwaysRebuild() &&
6709 Element.get() == S->getElement() &&
6710 Collection.get() == S->getCollection() &&
6711 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006712 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006713
Douglas Gregorf68a5082010-04-22 23:10:45 +00006714 // Build a new statement.
6715 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006716 Element.get(),
6717 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006718 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006719 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006720}
6721
David Majnemer5f7efef2013-10-15 09:50:08 +00006722template <typename Derived>
6723StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006724 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006725 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006726 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6727 TypeSourceInfo *T =
6728 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006729 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006731
David Majnemer5f7efef2013-10-15 09:50:08 +00006732 Var = getDerived().RebuildExceptionDecl(
6733 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6734 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006735 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006737 }
Mike Stump11289f42009-09-09 15:08:12 +00006738
Douglas Gregorebe10102009-08-20 07:17:43 +00006739 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006740 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006741 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006743
David Majnemer5f7efef2013-10-15 09:50:08 +00006744 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006745 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006746 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006747
David Majnemer5f7efef2013-10-15 09:50:08 +00006748 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006749}
Mike Stump11289f42009-09-09 15:08:12 +00006750
David Majnemer5f7efef2013-10-15 09:50:08 +00006751template <typename Derived>
6752StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006753 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006754 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006755 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006756 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregorebe10102009-08-20 07:17:43 +00006758 // Transform the handlers.
6759 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006760 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006761 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006762 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006763 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006764 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006765
Douglas Gregorebe10102009-08-20 07:17:43 +00006766 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006767 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006768 }
Mike Stump11289f42009-09-09 15:08:12 +00006769
David Majnemer5f7efef2013-10-15 09:50:08 +00006770 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006771 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006772 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006773
John McCallb268a282010-08-23 23:25:46 +00006774 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006775 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006776}
Mike Stump11289f42009-09-09 15:08:12 +00006777
Richard Smith02e85f32011-04-14 22:09:26 +00006778template<typename Derived>
6779StmtResult
6780TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6781 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6782 if (Range.isInvalid())
6783 return StmtError();
6784
6785 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6786 if (BeginEnd.isInvalid())
6787 return StmtError();
6788
6789 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6790 if (Cond.isInvalid())
6791 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006792 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006793 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006794 if (Cond.isInvalid())
6795 return StmtError();
6796 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006797 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006798
6799 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6800 if (Inc.isInvalid())
6801 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006802 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006803 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006804
6805 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6806 if (LoopVar.isInvalid())
6807 return StmtError();
6808
6809 StmtResult NewStmt = S;
6810 if (getDerived().AlwaysRebuild() ||
6811 Range.get() != S->getRangeStmt() ||
6812 BeginEnd.get() != S->getBeginEndStmt() ||
6813 Cond.get() != S->getCond() ||
6814 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006815 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006816 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006817 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006818 S->getColonLoc(), Range.get(),
6819 BeginEnd.get(), Cond.get(),
6820 Inc.get(), LoopVar.get(),
6821 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006822 if (NewStmt.isInvalid())
6823 return StmtError();
6824 }
Richard Smith02e85f32011-04-14 22:09:26 +00006825
6826 StmtResult Body = getDerived().TransformStmt(S->getBody());
6827 if (Body.isInvalid())
6828 return StmtError();
6829
6830 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6831 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006832 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006833 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00006834 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00006835 S->getColonLoc(), Range.get(),
6836 BeginEnd.get(), Cond.get(),
6837 Inc.get(), LoopVar.get(),
6838 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006839 if (NewStmt.isInvalid())
6840 return StmtError();
6841 }
Richard Smith02e85f32011-04-14 22:09:26 +00006842
6843 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006844 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006845
6846 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6847}
6848
John Wiegley1c0675e2011-04-28 01:08:34 +00006849template<typename Derived>
6850StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006851TreeTransform<Derived>::TransformMSDependentExistsStmt(
6852 MSDependentExistsStmt *S) {
6853 // Transform the nested-name-specifier, if any.
6854 NestedNameSpecifierLoc QualifierLoc;
6855 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006856 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006857 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6858 if (!QualifierLoc)
6859 return StmtError();
6860 }
6861
6862 // Transform the declaration name.
6863 DeclarationNameInfo NameInfo = S->getNameInfo();
6864 if (NameInfo.getName()) {
6865 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6866 if (!NameInfo.getName())
6867 return StmtError();
6868 }
6869
6870 // Check whether anything changed.
6871 if (!getDerived().AlwaysRebuild() &&
6872 QualifierLoc == S->getQualifierLoc() &&
6873 NameInfo.getName() == S->getNameInfo().getName())
6874 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006875
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006876 // Determine whether this name exists, if we can.
6877 CXXScopeSpec SS;
6878 SS.Adopt(QualifierLoc);
6879 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006880 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006881 case Sema::IER_Exists:
6882 if (S->isIfExists())
6883 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006884
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006885 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6886
6887 case Sema::IER_DoesNotExist:
6888 if (S->isIfNotExists())
6889 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006890
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006891 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006892
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006893 case Sema::IER_Dependent:
6894 Dependent = true;
6895 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006896
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006897 case Sema::IER_Error:
6898 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006899 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006900
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006901 // We need to continue with the instantiation, so do so now.
6902 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6903 if (SubStmt.isInvalid())
6904 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006905
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006906 // If we have resolved the name, just transform to the substatement.
6907 if (!Dependent)
6908 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006909
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006910 // The name is still dependent, so build a dependent expression again.
6911 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6912 S->isIfExists(),
6913 QualifierLoc,
6914 NameInfo,
6915 SubStmt.get());
6916}
6917
6918template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006919ExprResult
6920TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6921 NestedNameSpecifierLoc QualifierLoc;
6922 if (E->getQualifierLoc()) {
6923 QualifierLoc
6924 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6925 if (!QualifierLoc)
6926 return ExprError();
6927 }
6928
6929 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6930 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6931 if (!PD)
6932 return ExprError();
6933
6934 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6935 if (Base.isInvalid())
6936 return ExprError();
6937
6938 return new (SemaRef.getASTContext())
6939 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6940 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6941 QualifierLoc, E->getMemberLoc());
6942}
6943
David Majnemerfad8f482013-10-15 09:33:02 +00006944template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00006945ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
6946 MSPropertySubscriptExpr *E) {
6947 auto BaseRes = getDerived().TransformExpr(E->getBase());
6948 if (BaseRes.isInvalid())
6949 return ExprError();
6950 auto IdxRes = getDerived().TransformExpr(E->getIdx());
6951 if (IdxRes.isInvalid())
6952 return ExprError();
6953
6954 if (!getDerived().AlwaysRebuild() &&
6955 BaseRes.get() == E->getBase() &&
6956 IdxRes.get() == E->getIdx())
6957 return E;
6958
6959 return getDerived().RebuildArraySubscriptExpr(
6960 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
6961}
6962
6963template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00006964StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006965 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006966 if (TryBlock.isInvalid())
6967 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006968
6969 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006970 if (Handler.isInvalid())
6971 return StmtError();
6972
David Majnemerfad8f482013-10-15 09:33:02 +00006973 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6974 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006975 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006976
Warren Huntf6be4cb2014-07-25 20:52:51 +00006977 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6978 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006979}
6980
David Majnemerfad8f482013-10-15 09:33:02 +00006981template <typename Derived>
6982StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006983 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006984 if (Block.isInvalid())
6985 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006986
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006987 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006988}
6989
David Majnemerfad8f482013-10-15 09:33:02 +00006990template <typename Derived>
6991StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006992 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006993 if (FilterExpr.isInvalid())
6994 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006995
David Majnemer7e755502013-10-15 09:30:14 +00006996 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006997 if (Block.isInvalid())
6998 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006999
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007000 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7001 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007002}
7003
David Majnemerfad8f482013-10-15 09:33:02 +00007004template <typename Derived>
7005StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7006 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007007 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7008 else
7009 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7010}
7011
Nico Weber9b982072014-07-07 00:12:30 +00007012template<typename Derived>
7013StmtResult
7014TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7015 return S;
7016}
7017
Alexander Musman64d33f12014-06-04 07:53:32 +00007018//===----------------------------------------------------------------------===//
7019// OpenMP directive transformation
7020//===----------------------------------------------------------------------===//
7021template <typename Derived>
7022StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7023 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007024
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007025 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007026 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007027 ArrayRef<OMPClause *> Clauses = D->clauses();
7028 TClauses.reserve(Clauses.size());
7029 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7030 I != E; ++I) {
7031 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007032 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007033 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007034 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007035 if (Clause)
7036 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007037 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007038 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007039 }
7040 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007041 StmtResult AssociatedStmt;
7042 if (D->hasAssociatedStmt()) {
7043 if (!D->getAssociatedStmt()) {
7044 return StmtError();
7045 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007046 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7047 /*CurScope=*/nullptr);
7048 StmtResult Body;
7049 {
7050 Sema::CompoundScopeRAII CompoundScope(getSema());
7051 Body = getDerived().TransformStmt(
7052 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7053 }
7054 AssociatedStmt =
7055 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007056 if (AssociatedStmt.isInvalid()) {
7057 return StmtError();
7058 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007059 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007060 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007061 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007062 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007063
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007064 // Transform directive name for 'omp critical' directive.
7065 DeclarationNameInfo DirName;
7066 if (D->getDirectiveKind() == OMPD_critical) {
7067 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7068 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7069 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007070 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7071 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7072 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007073 } else if (D->getDirectiveKind() == OMPD_cancel) {
7074 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007075 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007076
Alexander Musman64d33f12014-06-04 07:53:32 +00007077 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007078 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7079 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007080}
7081
Alexander Musman64d33f12014-06-04 07:53:32 +00007082template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007083StmtResult
7084TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7085 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007086 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7087 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007088 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7089 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7090 return Res;
7091}
7092
Alexander Musman64d33f12014-06-04 07:53:32 +00007093template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007094StmtResult
7095TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7096 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007097 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7098 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007099 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7100 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007101 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007102}
7103
Alexey Bataevf29276e2014-06-18 04:14:57 +00007104template <typename Derived>
7105StmtResult
7106TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7107 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007108 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7109 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007110 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7111 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7112 return Res;
7113}
7114
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007115template <typename Derived>
7116StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007117TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7118 DeclarationNameInfo DirName;
7119 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7120 D->getLocStart());
7121 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7122 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7123 return Res;
7124}
7125
7126template <typename Derived>
7127StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007128TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7129 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007130 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7131 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007132 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7133 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7134 return Res;
7135}
7136
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007137template <typename Derived>
7138StmtResult
7139TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7140 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007141 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7142 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007143 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7144 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7145 return Res;
7146}
7147
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007148template <typename Derived>
7149StmtResult
7150TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7151 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007152 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7153 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7155 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7156 return Res;
7157}
7158
Alexey Bataev4acb8592014-07-07 13:01:15 +00007159template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007160StmtResult
7161TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7162 DeclarationNameInfo DirName;
7163 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7164 D->getLocStart());
7165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7166 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7167 return Res;
7168}
7169
7170template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007171StmtResult
7172TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7173 getDerived().getSema().StartOpenMPDSABlock(
7174 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7177 return Res;
7178}
7179
7180template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007181StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7182 OMPParallelForDirective *D) {
7183 DeclarationNameInfo DirName;
7184 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7185 nullptr, D->getLocStart());
7186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7188 return Res;
7189}
7190
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007191template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007192StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7193 OMPParallelForSimdDirective *D) {
7194 DeclarationNameInfo DirName;
7195 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7196 nullptr, D->getLocStart());
7197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7199 return Res;
7200}
7201
7202template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007203StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7204 OMPParallelSectionsDirective *D) {
7205 DeclarationNameInfo DirName;
7206 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7207 nullptr, D->getLocStart());
7208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7210 return Res;
7211}
7212
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007213template <typename Derived>
7214StmtResult
7215TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7216 DeclarationNameInfo DirName;
7217 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7218 D->getLocStart());
7219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7221 return Res;
7222}
7223
Alexey Bataev68446b72014-07-18 07:47:19 +00007224template <typename Derived>
7225StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7226 OMPTaskyieldDirective *D) {
7227 DeclarationNameInfo DirName;
7228 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7229 D->getLocStart());
7230 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7232 return Res;
7233}
7234
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007235template <typename Derived>
7236StmtResult
7237TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7238 DeclarationNameInfo DirName;
7239 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7240 D->getLocStart());
7241 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7242 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7243 return Res;
7244}
7245
Alexey Bataev2df347a2014-07-18 10:17:07 +00007246template <typename Derived>
7247StmtResult
7248TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7249 DeclarationNameInfo DirName;
7250 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7251 D->getLocStart());
7252 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7253 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7254 return Res;
7255}
7256
Alexey Bataev6125da92014-07-21 11:26:11 +00007257template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007258StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7259 OMPTaskgroupDirective *D) {
7260 DeclarationNameInfo DirName;
7261 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7262 D->getLocStart());
7263 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7264 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7265 return Res;
7266}
7267
7268template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007269StmtResult
7270TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7271 DeclarationNameInfo DirName;
7272 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7273 D->getLocStart());
7274 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7275 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7276 return Res;
7277}
7278
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007279template <typename Derived>
7280StmtResult
7281TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7282 DeclarationNameInfo DirName;
7283 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7284 D->getLocStart());
7285 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7286 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7287 return Res;
7288}
7289
Alexey Bataev0162e452014-07-22 10:10:35 +00007290template <typename Derived>
7291StmtResult
7292TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7293 DeclarationNameInfo DirName;
7294 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7295 D->getLocStart());
7296 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7297 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7298 return Res;
7299}
7300
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007301template <typename Derived>
7302StmtResult
7303TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7304 DeclarationNameInfo DirName;
7305 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7306 D->getLocStart());
7307 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7308 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7309 return Res;
7310}
7311
Alexey Bataev13314bf2014-10-09 04:18:56 +00007312template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007313StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7314 OMPTargetDataDirective *D) {
7315 DeclarationNameInfo DirName;
7316 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7317 D->getLocStart());
7318 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7319 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7320 return Res;
7321}
7322
7323template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007324StmtResult
7325TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7326 DeclarationNameInfo DirName;
7327 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7328 D->getLocStart());
7329 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7330 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7331 return Res;
7332}
7333
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007334template <typename Derived>
7335StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7336 OMPCancellationPointDirective *D) {
7337 DeclarationNameInfo DirName;
7338 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7339 nullptr, D->getLocStart());
7340 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7341 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7342 return Res;
7343}
7344
Alexey Bataev80909872015-07-02 11:25:17 +00007345template <typename Derived>
7346StmtResult
7347TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7348 DeclarationNameInfo DirName;
7349 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7350 D->getLocStart());
7351 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7352 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7353 return Res;
7354}
7355
Alexey Bataev49f6e782015-12-01 04:18:41 +00007356template <typename Derived>
7357StmtResult
7358TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7359 DeclarationNameInfo DirName;
7360 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7361 D->getLocStart());
7362 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7363 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7364 return Res;
7365}
7366
Alexander Musman64d33f12014-06-04 07:53:32 +00007367//===----------------------------------------------------------------------===//
7368// OpenMP clause transformation
7369//===----------------------------------------------------------------------===//
7370template <typename Derived>
7371OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007372 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7373 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007374 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007375 return getDerived().RebuildOMPIfClause(
7376 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7377 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007378}
7379
Alexander Musman64d33f12014-06-04 07:53:32 +00007380template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007381OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7382 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7383 if (Cond.isInvalid())
7384 return nullptr;
7385 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7386 C->getLParenLoc(), C->getLocEnd());
7387}
7388
7389template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007390OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007391TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7392 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7393 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007394 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007395 return getDerived().RebuildOMPNumThreadsClause(
7396 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007397}
7398
Alexey Bataev62c87d22014-03-21 04:51:18 +00007399template <typename Derived>
7400OMPClause *
7401TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7402 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7403 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007404 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007405 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007406 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007407}
7408
Alexander Musman8bd31e62014-05-27 15:12:19 +00007409template <typename Derived>
7410OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007411TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7412 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7413 if (E.isInvalid())
7414 return nullptr;
7415 return getDerived().RebuildOMPSimdlenClause(
7416 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7417}
7418
7419template <typename Derived>
7420OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007421TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7422 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7423 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007424 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007425 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007426 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007427}
7428
Alexander Musman64d33f12014-06-04 07:53:32 +00007429template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007430OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007431TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007432 return getDerived().RebuildOMPDefaultClause(
7433 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7434 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007435}
7436
Alexander Musman64d33f12014-06-04 07:53:32 +00007437template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007438OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007439TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007440 return getDerived().RebuildOMPProcBindClause(
7441 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7442 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007443}
7444
Alexander Musman64d33f12014-06-04 07:53:32 +00007445template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007446OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007447TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7448 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7449 if (E.isInvalid())
7450 return nullptr;
7451 return getDerived().RebuildOMPScheduleClause(
7452 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7453 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7454}
7455
7456template <typename Derived>
7457OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007458TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007459 ExprResult E;
7460 if (auto *Num = C->getNumForLoops()) {
7461 E = getDerived().TransformExpr(Num);
7462 if (E.isInvalid())
7463 return nullptr;
7464 }
7465 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7466 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007467}
7468
7469template <typename Derived>
7470OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007471TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7472 // No need to rebuild this clause, no template-dependent parameters.
7473 return C;
7474}
7475
7476template <typename Derived>
7477OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007478TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7479 // No need to rebuild this clause, no template-dependent parameters.
7480 return C;
7481}
7482
7483template <typename Derived>
7484OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007485TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7486 // No need to rebuild this clause, no template-dependent parameters.
7487 return C;
7488}
7489
7490template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007491OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7492 // No need to rebuild this clause, no template-dependent parameters.
7493 return C;
7494}
7495
7496template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007497OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7498 // No need to rebuild this clause, no template-dependent parameters.
7499 return C;
7500}
7501
7502template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007503OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007504TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7505 // No need to rebuild this clause, no template-dependent parameters.
7506 return C;
7507}
7508
7509template <typename Derived>
7510OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007511TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7512 // No need to rebuild this clause, no template-dependent parameters.
7513 return C;
7514}
7515
7516template <typename Derived>
7517OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007518TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7519 // No need to rebuild this clause, no template-dependent parameters.
7520 return C;
7521}
7522
7523template <typename Derived>
7524OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007525TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7526 // No need to rebuild this clause, no template-dependent parameters.
7527 return C;
7528}
7529
7530template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007531OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7532 // No need to rebuild this clause, no template-dependent parameters.
7533 return C;
7534}
7535
7536template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007537OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007538TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007539 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007540 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007541 for (auto *VE : C->varlists()) {
7542 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007543 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007544 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007545 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007546 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007547 return getDerived().RebuildOMPPrivateClause(
7548 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007549}
7550
Alexander Musman64d33f12014-06-04 07:53:32 +00007551template <typename Derived>
7552OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7553 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007554 llvm::SmallVector<Expr *, 16> Vars;
7555 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007556 for (auto *VE : C->varlists()) {
7557 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007558 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007559 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007560 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007561 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007562 return getDerived().RebuildOMPFirstprivateClause(
7563 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007564}
7565
Alexander Musman64d33f12014-06-04 07:53:32 +00007566template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007567OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007568TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7569 llvm::SmallVector<Expr *, 16> Vars;
7570 Vars.reserve(C->varlist_size());
7571 for (auto *VE : C->varlists()) {
7572 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7573 if (EVar.isInvalid())
7574 return nullptr;
7575 Vars.push_back(EVar.get());
7576 }
7577 return getDerived().RebuildOMPLastprivateClause(
7578 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7579}
7580
7581template <typename Derived>
7582OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007583TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *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 Bataev758e55e2013-09-06 18:03:48 +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 Bataev758e55e2013-09-06 18:03:48 +00007591 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007592 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7593 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007594}
7595
Alexander Musman64d33f12014-06-04 07:53:32 +00007596template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007597OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007598TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *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 CXXScopeSpec ReductionIdScopeSpec;
7608 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7609
7610 DeclarationNameInfo NameInfo = C->getNameInfo();
7611 if (NameInfo.getName()) {
7612 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7613 if (!NameInfo.getName())
7614 return nullptr;
7615 }
7616 return getDerived().RebuildOMPReductionClause(
7617 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7618 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7619}
7620
7621template <typename Derived>
7622OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007623TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7624 llvm::SmallVector<Expr *, 16> Vars;
7625 Vars.reserve(C->varlist_size());
7626 for (auto *VE : C->varlists()) {
7627 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7628 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007629 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007630 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007631 }
7632 ExprResult Step = getDerived().TransformExpr(C->getStep());
7633 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007634 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007635 return getDerived().RebuildOMPLinearClause(
7636 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7637 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007638}
7639
Alexander Musman64d33f12014-06-04 07:53:32 +00007640template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007641OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007642TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7643 llvm::SmallVector<Expr *, 16> Vars;
7644 Vars.reserve(C->varlist_size());
7645 for (auto *VE : C->varlists()) {
7646 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7647 if (EVar.isInvalid())
7648 return nullptr;
7649 Vars.push_back(EVar.get());
7650 }
7651 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7652 if (Alignment.isInvalid())
7653 return nullptr;
7654 return getDerived().RebuildOMPAlignedClause(
7655 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7656 C->getColonLoc(), C->getLocEnd());
7657}
7658
Alexander Musman64d33f12014-06-04 07:53:32 +00007659template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007660OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007661TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7662 llvm::SmallVector<Expr *, 16> Vars;
7663 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007664 for (auto *VE : C->varlists()) {
7665 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007666 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007667 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007668 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007669 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007670 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7671 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007672}
7673
Alexey Bataevbae9a792014-06-27 10:37:06 +00007674template <typename Derived>
7675OMPClause *
7676TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7677 llvm::SmallVector<Expr *, 16> Vars;
7678 Vars.reserve(C->varlist_size());
7679 for (auto *VE : C->varlists()) {
7680 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7681 if (EVar.isInvalid())
7682 return nullptr;
7683 Vars.push_back(EVar.get());
7684 }
7685 return getDerived().RebuildOMPCopyprivateClause(
7686 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7687}
7688
Alexey Bataev6125da92014-07-21 11:26:11 +00007689template <typename Derived>
7690OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7691 llvm::SmallVector<Expr *, 16> Vars;
7692 Vars.reserve(C->varlist_size());
7693 for (auto *VE : C->varlists()) {
7694 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7695 if (EVar.isInvalid())
7696 return nullptr;
7697 Vars.push_back(EVar.get());
7698 }
7699 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7700 C->getLParenLoc(), C->getLocEnd());
7701}
7702
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007703template <typename Derived>
7704OMPClause *
7705TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7706 llvm::SmallVector<Expr *, 16> Vars;
7707 Vars.reserve(C->varlist_size());
7708 for (auto *VE : C->varlists()) {
7709 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7710 if (EVar.isInvalid())
7711 return nullptr;
7712 Vars.push_back(EVar.get());
7713 }
7714 return getDerived().RebuildOMPDependClause(
7715 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7716 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7717}
7718
Michael Wonge710d542015-08-07 16:16:36 +00007719template <typename Derived>
7720OMPClause *
7721TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7722 ExprResult E = getDerived().TransformExpr(C->getDevice());
7723 if (E.isInvalid())
7724 return nullptr;
7725 return getDerived().RebuildOMPDeviceClause(
7726 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7727}
7728
Kelvin Li0bff7af2015-11-23 05:32:03 +00007729template <typename Derived>
7730OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7731 llvm::SmallVector<Expr *, 16> Vars;
7732 Vars.reserve(C->varlist_size());
7733 for (auto *VE : C->varlists()) {
7734 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7735 if (EVar.isInvalid())
7736 return nullptr;
7737 Vars.push_back(EVar.get());
7738 }
7739 return getDerived().RebuildOMPMapClause(
7740 C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7741 C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7742 C->getLocEnd());
7743}
7744
Kelvin Li099bb8c2015-11-24 20:50:12 +00007745template <typename Derived>
7746OMPClause *
7747TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7748 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7749 if (E.isInvalid())
7750 return nullptr;
7751 return getDerived().RebuildOMPNumTeamsClause(
7752 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7753}
7754
Kelvin Lia15fb1a2015-11-27 18:47:36 +00007755template <typename Derived>
7756OMPClause *
7757TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7758 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7759 if (E.isInvalid())
7760 return nullptr;
7761 return getDerived().RebuildOMPThreadLimitClause(
7762 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7763}
7764
Alexey Bataeva0569352015-12-01 10:17:31 +00007765template <typename Derived>
7766OMPClause *
7767TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7768 ExprResult E = getDerived().TransformExpr(C->getPriority());
7769 if (E.isInvalid())
7770 return nullptr;
7771 return getDerived().RebuildOMPPriorityClause(
7772 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7773}
7774
Douglas Gregorebe10102009-08-20 07:17:43 +00007775//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007776// Expression transformation
7777//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007780TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007781 if (!E->isTypeDependent())
7782 return E;
7783
7784 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7785 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007786}
Mike Stump11289f42009-09-09 15:08:12 +00007787
7788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007790TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007791 NestedNameSpecifierLoc QualifierLoc;
7792 if (E->getQualifierLoc()) {
7793 QualifierLoc
7794 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7795 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007796 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007797 }
John McCallce546572009-12-08 09:08:17 +00007798
7799 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007800 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7801 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007802 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007804
John McCall815039a2010-08-17 21:27:17 +00007805 DeclarationNameInfo NameInfo = E->getNameInfo();
7806 if (NameInfo.getName()) {
7807 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7808 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007809 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007810 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007811
7812 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007813 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007814 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007815 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007816 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007817
7818 // Mark it referenced in the new context regardless.
7819 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007820 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007821
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007822 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007823 }
John McCallce546572009-12-08 09:08:17 +00007824
Craig Topperc3ec1492014-05-26 06:22:03 +00007825 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007826 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007827 TemplateArgs = &TransArgs;
7828 TransArgs.setLAngleLoc(E->getLAngleLoc());
7829 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007830 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7831 E->getNumTemplateArgs(),
7832 TransArgs))
7833 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007834 }
7835
Chad Rosier1dcde962012-08-08 18:46:20 +00007836 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007837 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007838}
Mike Stump11289f42009-09-09 15:08:12 +00007839
Douglas Gregora16548e2009-08-11 05:31:07 +00007840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007842TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007843 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007844}
Mike Stump11289f42009-09-09 15:08:12 +00007845
Douglas Gregora16548e2009-08-11 05:31:07 +00007846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007848TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007849 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007850}
Mike Stump11289f42009-09-09 15:08:12 +00007851
Douglas Gregora16548e2009-08-11 05:31:07 +00007852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007854TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007855 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007856}
Mike Stump11289f42009-09-09 15:08:12 +00007857
Douglas Gregora16548e2009-08-11 05:31:07 +00007858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007860TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007861 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007862}
Mike Stump11289f42009-09-09 15:08:12 +00007863
Douglas Gregora16548e2009-08-11 05:31:07 +00007864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007866TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007867 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007868}
7869
7870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007871ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007872TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007873 if (FunctionDecl *FD = E->getDirectCallee())
7874 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007875 return SemaRef.MaybeBindToTemporary(E);
7876}
7877
7878template<typename Derived>
7879ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007880TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7881 ExprResult ControllingExpr =
7882 getDerived().TransformExpr(E->getControllingExpr());
7883 if (ControllingExpr.isInvalid())
7884 return ExprError();
7885
Chris Lattner01cf8db2011-07-20 06:58:45 +00007886 SmallVector<Expr *, 4> AssocExprs;
7887 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007888 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7889 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7890 if (TS) {
7891 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7892 if (!AssocType)
7893 return ExprError();
7894 AssocTypes.push_back(AssocType);
7895 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007896 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007897 }
7898
7899 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7900 if (AssocExpr.isInvalid())
7901 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007902 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007903 }
7904
7905 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7906 E->getDefaultLoc(),
7907 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007908 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007909 AssocTypes,
7910 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007911}
7912
7913template<typename Derived>
7914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007915TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007916 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007917 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007919
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007921 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007922
John McCallb268a282010-08-23 23:25:46 +00007923 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 E->getRParen());
7925}
7926
Richard Smithdb2630f2012-10-21 03:28:35 +00007927/// \brief The operand of a unary address-of operator has special rules: it's
7928/// allowed to refer to a non-static member of a class even if there's no 'this'
7929/// object available.
7930template<typename Derived>
7931ExprResult
7932TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7933 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007934 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007935 else
7936 return getDerived().TransformExpr(E);
7937}
7938
Mike Stump11289f42009-09-09 15:08:12 +00007939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007941TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007942 ExprResult SubExpr;
7943 if (E->getOpcode() == UO_AddrOf)
7944 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7945 else
7946 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007947 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007949
Douglas Gregora16548e2009-08-11 05:31:07 +00007950 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007951 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007952
Douglas Gregora16548e2009-08-11 05:31:07 +00007953 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7954 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007955 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007956}
Mike Stump11289f42009-09-09 15:08:12 +00007957
Douglas Gregora16548e2009-08-11 05:31:07 +00007958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007959ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007960TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7961 // Transform the type.
7962 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7963 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007964 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007965
Douglas Gregor882211c2010-04-28 22:16:22 +00007966 // Transform all of the components into components similar to what the
7967 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007968 // FIXME: It would be slightly more efficient in the non-dependent case to
7969 // just map FieldDecls, rather than requiring the rebuilder to look for
7970 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007971 // template code that we don't care.
7972 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007973 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007974 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007975 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007976 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7977 const Node &ON = E->getComponent(I);
7978 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007979 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007980 Comp.LocStart = ON.getSourceRange().getBegin();
7981 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007982 switch (ON.getKind()) {
7983 case Node::Array: {
7984 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007985 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007986 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007987 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007988
Douglas Gregor882211c2010-04-28 22:16:22 +00007989 ExprChanged = ExprChanged || Index.get() != FromIndex;
7990 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007991 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007992 break;
7993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007994
Douglas Gregor882211c2010-04-28 22:16:22 +00007995 case Node::Field:
7996 case Node::Identifier:
7997 Comp.isBrackets = false;
7998 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007999 if (!Comp.U.IdentInfo)
8000 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008001
Douglas Gregor882211c2010-04-28 22:16:22 +00008002 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008003
Douglas Gregord1702062010-04-29 00:18:15 +00008004 case Node::Base:
8005 // Will be recomputed during the rebuild.
8006 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008007 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008008
Douglas Gregor882211c2010-04-28 22:16:22 +00008009 Components.push_back(Comp);
8010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008011
Douglas Gregor882211c2010-04-28 22:16:22 +00008012 // If nothing changed, retain the existing expression.
8013 if (!getDerived().AlwaysRebuild() &&
8014 Type == E->getTypeSourceInfo() &&
8015 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008016 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008017
Douglas Gregor882211c2010-04-28 22:16:22 +00008018 // Build a new offsetof expression.
8019 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008020 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008021}
8022
8023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008024ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008025TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008026 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008027 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008028 return E;
John McCall8d69a212010-11-15 23:31:06 +00008029}
8030
8031template<typename Derived>
8032ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008033TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8034 return E;
8035}
8036
8037template<typename Derived>
8038ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008039TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008040 // Rebuild the syntactic form. The original syntactic form has
8041 // opaque-value expressions in it, so strip those away and rebuild
8042 // the result. This is a really awful way of doing this, but the
8043 // better solution (rebuilding the semantic expressions and
8044 // rebinding OVEs as necessary) doesn't work; we'd need
8045 // TreeTransform to not strip away implicit conversions.
8046 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8047 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008048 if (result.isInvalid()) return ExprError();
8049
8050 // If that gives us a pseudo-object result back, the pseudo-object
8051 // expression must have been an lvalue-to-rvalue conversion which we
8052 // should reapply.
8053 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008054 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008055
8056 return result;
8057}
8058
8059template<typename Derived>
8060ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008061TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8062 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008063 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008064 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008065
John McCallbcd03502009-12-07 02:54:59 +00008066 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008067 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008069
John McCall4c98fd82009-11-04 07:28:41 +00008070 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008071 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008072
Peter Collingbournee190dee2011-03-11 19:24:49 +00008073 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8074 E->getKind(),
8075 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008076 }
Mike Stump11289f42009-09-09 15:08:12 +00008077
Eli Friedmane4f22df2012-02-29 04:03:55 +00008078 // C++0x [expr.sizeof]p1:
8079 // The operand is either an expression, which is an unevaluated operand
8080 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008081 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8082 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008083
Reid Kleckner32506ed2014-06-12 23:03:48 +00008084 // Try to recover if we have something like sizeof(T::X) where X is a type.
8085 // Notably, there must be *exactly* one set of parens if X is a type.
8086 TypeSourceInfo *RecoveryTSI = nullptr;
8087 ExprResult SubExpr;
8088 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8089 if (auto *DRE =
8090 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8091 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8092 PE, DRE, false, &RecoveryTSI);
8093 else
8094 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8095
8096 if (RecoveryTSI) {
8097 return getDerived().RebuildUnaryExprOrTypeTrait(
8098 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8099 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008101
Eli Friedmane4f22df2012-02-29 04:03:55 +00008102 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008103 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008104
Peter Collingbournee190dee2011-03-11 19:24:49 +00008105 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8106 E->getOperatorLoc(),
8107 E->getKind(),
8108 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008109}
Mike Stump11289f42009-09-09 15:08:12 +00008110
Douglas Gregora16548e2009-08-11 05:31:07 +00008111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008113TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008114 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008117
John McCalldadc5752010-08-24 06:29:42 +00008118 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008119 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008121
8122
Douglas Gregora16548e2009-08-11 05:31:07 +00008123 if (!getDerived().AlwaysRebuild() &&
8124 LHS.get() == E->getLHS() &&
8125 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008126 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008127
John McCallb268a282010-08-23 23:25:46 +00008128 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008129 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008130 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 E->getRBracketLoc());
8132}
Mike Stump11289f42009-09-09 15:08:12 +00008133
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008134template <typename Derived>
8135ExprResult
8136TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8137 ExprResult Base = getDerived().TransformExpr(E->getBase());
8138 if (Base.isInvalid())
8139 return ExprError();
8140
8141 ExprResult LowerBound;
8142 if (E->getLowerBound()) {
8143 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8144 if (LowerBound.isInvalid())
8145 return ExprError();
8146 }
8147
8148 ExprResult Length;
8149 if (E->getLength()) {
8150 Length = getDerived().TransformExpr(E->getLength());
8151 if (Length.isInvalid())
8152 return ExprError();
8153 }
8154
8155 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8156 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8157 return E;
8158
8159 return getDerived().RebuildOMPArraySectionExpr(
8160 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8161 Length.get(), E->getRBracketLoc());
8162}
8163
Mike Stump11289f42009-09-09 15:08:12 +00008164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008166TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008167 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008168 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008169 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008170 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008171
8172 // Transform arguments.
8173 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008174 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008175 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008176 &ArgChanged))
8177 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008178
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 if (!getDerived().AlwaysRebuild() &&
8180 Callee.get() == E->getCallee() &&
8181 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008182 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008183
Douglas Gregora16548e2009-08-11 05:31:07 +00008184 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008185 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008186 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008187 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008188 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008189 E->getRParenLoc());
8190}
Mike Stump11289f42009-09-09 15:08:12 +00008191
8192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008194TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008195 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008196 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008198
Douglas Gregorea972d32011-02-28 21:54:11 +00008199 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008200 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008201 QualifierLoc
8202 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008203
Douglas Gregorea972d32011-02-28 21:54:11 +00008204 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008205 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008206 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008207 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008208
Eli Friedman2cfcef62009-12-04 06:40:45 +00008209 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008210 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8211 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008212 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008214
John McCall16df1e52010-03-30 21:47:33 +00008215 NamedDecl *FoundDecl = E->getFoundDecl();
8216 if (FoundDecl == E->getMemberDecl()) {
8217 FoundDecl = Member;
8218 } else {
8219 FoundDecl = cast_or_null<NamedDecl>(
8220 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8221 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008222 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008223 }
8224
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (!getDerived().AlwaysRebuild() &&
8226 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008227 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008228 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008229 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008230 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008231
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008232 // Mark it referenced in the new context regardless.
8233 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008234 SemaRef.MarkMemberReferenced(E);
8235
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008236 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008237 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008238
John McCall6b51f282009-11-23 01:53:49 +00008239 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008240 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008241 TransArgs.setLAngleLoc(E->getLAngleLoc());
8242 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008243 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8244 E->getNumTemplateArgs(),
8245 TransArgs))
8246 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008247 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008248
Douglas Gregora16548e2009-08-11 05:31:07 +00008249 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008250 SourceLocation FakeOperatorLoc =
8251 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008252
John McCall38836f02010-01-15 08:34:02 +00008253 // FIXME: to do this check properly, we will need to preserve the
8254 // first-qualifier-in-scope here, just in case we had a dependent
8255 // base (and therefore couldn't do the check) and a
8256 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008257 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008258
John McCallb268a282010-08-23 23:25:46 +00008259 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008260 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008261 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008262 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008263 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008264 Member,
John McCall16df1e52010-03-30 21:47:33 +00008265 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008266 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008267 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008268 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008269}
Mike Stump11289f42009-09-09 15:08:12 +00008270
Douglas Gregora16548e2009-08-11 05:31:07 +00008271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008273TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008274 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008275 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008277
John McCalldadc5752010-08-24 06:29:42 +00008278 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008279 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008281
Douglas Gregora16548e2009-08-11 05:31:07 +00008282 if (!getDerived().AlwaysRebuild() &&
8283 LHS.get() == E->getLHS() &&
8284 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008285 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008286
Lang Hames5de91cc2012-10-02 04:45:10 +00008287 Sema::FPContractStateRAII FPContractState(getSema());
8288 getSema().FPFeatures.fp_contract = E->isFPContractable();
8289
Douglas Gregora16548e2009-08-11 05:31:07 +00008290 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008291 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008292}
8293
Mike Stump11289f42009-09-09 15:08:12 +00008294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008295ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008296TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008297 CompoundAssignOperator *E) {
8298 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008299}
Mike Stump11289f42009-09-09 15:08:12 +00008300
Douglas Gregora16548e2009-08-11 05:31:07 +00008301template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008302ExprResult TreeTransform<Derived>::
8303TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8304 // Just rebuild the common and RHS expressions and see whether we
8305 // get any changes.
8306
8307 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8308 if (commonExpr.isInvalid())
8309 return ExprError();
8310
8311 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8312 if (rhs.isInvalid())
8313 return ExprError();
8314
8315 if (!getDerived().AlwaysRebuild() &&
8316 commonExpr.get() == e->getCommon() &&
8317 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008318 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008319
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008320 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008321 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008322 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008323 e->getColonLoc(),
8324 rhs.get());
8325}
8326
8327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008328ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008329TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008330 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008333
John McCalldadc5752010-08-24 06:29:42 +00008334 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008335 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008337
John McCalldadc5752010-08-24 06:29:42 +00008338 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008339 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342 if (!getDerived().AlwaysRebuild() &&
8343 Cond.get() == E->getCond() &&
8344 LHS.get() == E->getLHS() &&
8345 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008346 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008347
John McCallb268a282010-08-23 23:25:46 +00008348 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008349 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008350 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008351 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008352 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008353}
Mike Stump11289f42009-09-09 15:08:12 +00008354
8355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008357TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008358 // Implicit casts are eliminated during transformation, since they
8359 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008360 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008361}
Mike Stump11289f42009-09-09 15:08:12 +00008362
Douglas Gregora16548e2009-08-11 05:31:07 +00008363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008365TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008366 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8367 if (!Type)
8368 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008369
John McCalldadc5752010-08-24 06:29:42 +00008370 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008371 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008372 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008374
Douglas Gregora16548e2009-08-11 05:31:07 +00008375 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008376 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008377 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008378 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008379
John McCall97513962010-01-15 18:39:57 +00008380 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008381 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008383 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008384}
Mike Stump11289f42009-09-09 15:08:12 +00008385
Douglas Gregora16548e2009-08-11 05:31:07 +00008386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008388TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008389 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8390 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8391 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008392 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008393
John McCalldadc5752010-08-24 06:29:42 +00008394 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008395 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008397
Douglas Gregora16548e2009-08-11 05:31:07 +00008398 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008399 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008400 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008401 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008402
John McCall5d7aa7f2010-01-19 22:33:45 +00008403 // Note: the expression type doesn't necessarily match the
8404 // type-as-written, but that's okay, because it should always be
8405 // derivable from the initializer.
8406
John McCalle15bbff2010-01-18 19:35:47 +00008407 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008409 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008410}
Mike Stump11289f42009-09-09 15:08:12 +00008411
Douglas Gregora16548e2009-08-11 05:31:07 +00008412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008414TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008415 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008416 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008418
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 if (!getDerived().AlwaysRebuild() &&
8420 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008421 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008422
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008424 SourceLocation FakeOperatorLoc =
8425 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008426 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008427 E->getAccessorLoc(),
8428 E->getAccessor());
8429}
Mike Stump11289f42009-09-09 15:08:12 +00008430
Douglas Gregora16548e2009-08-11 05:31:07 +00008431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008433TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008434 if (InitListExpr *Syntactic = E->getSyntacticForm())
8435 E = Syntactic;
8436
Douglas Gregora16548e2009-08-11 05:31:07 +00008437 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008438
Benjamin Kramerf0623432012-08-23 22:51:59 +00008439 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008440 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008441 Inits, &InitChanged))
8442 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008443
Richard Smith520449d2015-02-05 06:15:50 +00008444 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8445 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8446 // in some cases. We can't reuse it in general, because the syntactic and
8447 // semantic forms are linked, and we can't know that semantic form will
8448 // match even if the syntactic form does.
8449 }
Mike Stump11289f42009-09-09 15:08:12 +00008450
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008451 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008452 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008453}
Mike Stump11289f42009-09-09 15:08:12 +00008454
Douglas Gregora16548e2009-08-11 05:31:07 +00008455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008457TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008458 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008459
Douglas Gregorebe10102009-08-20 07:17:43 +00008460 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008461 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008462 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008463 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008464
Douglas Gregorebe10102009-08-20 07:17:43 +00008465 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008466 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008467 bool ExprChanged = false;
8468 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8469 DEnd = E->designators_end();
8470 D != DEnd; ++D) {
8471 if (D->isFieldDesignator()) {
8472 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8473 D->getDotLoc(),
8474 D->getFieldLoc()));
8475 continue;
8476 }
Mike Stump11289f42009-09-09 15:08:12 +00008477
Douglas Gregora16548e2009-08-11 05:31:07 +00008478 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008479 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008480 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008482
8483 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008485
Douglas Gregora16548e2009-08-11 05:31:07 +00008486 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008487 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008488 continue;
8489 }
Mike Stump11289f42009-09-09 15:08:12 +00008490
Douglas Gregora16548e2009-08-11 05:31:07 +00008491 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008492 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008493 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8494 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008495 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008496
John McCalldadc5752010-08-24 06:29:42 +00008497 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008498 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008500
8501 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 End.get(),
8503 D->getLBracketLoc(),
8504 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008505
Douglas Gregora16548e2009-08-11 05:31:07 +00008506 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8507 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008508
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008509 ArrayExprs.push_back(Start.get());
8510 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008511 }
Mike Stump11289f42009-09-09 15:08:12 +00008512
Douglas Gregora16548e2009-08-11 05:31:07 +00008513 if (!getDerived().AlwaysRebuild() &&
8514 Init.get() == E->getInit() &&
8515 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008516 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008517
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008518 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008520 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008521}
Mike Stump11289f42009-09-09 15:08:12 +00008522
Yunzhong Gaocb779302015-06-10 00:27:52 +00008523// Seems that if TransformInitListExpr() only works on the syntactic form of an
8524// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8525template<typename Derived>
8526ExprResult
8527TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8528 DesignatedInitUpdateExpr *E) {
8529 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8530 "initializer");
8531 return ExprError();
8532}
8533
8534template<typename Derived>
8535ExprResult
8536TreeTransform<Derived>::TransformNoInitExpr(
8537 NoInitExpr *E) {
8538 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8539 return ExprError();
8540}
8541
Douglas Gregora16548e2009-08-11 05:31:07 +00008542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008543ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008544TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008545 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008546 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008547
Douglas Gregor3da3c062009-10-28 00:29:27 +00008548 // FIXME: Will we ever have proper type location here? Will we actually
8549 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008550 QualType T = getDerived().TransformType(E->getType());
8551 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008553
Douglas Gregora16548e2009-08-11 05:31:07 +00008554 if (!getDerived().AlwaysRebuild() &&
8555 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008556 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008557
Douglas Gregora16548e2009-08-11 05:31:07 +00008558 return getDerived().RebuildImplicitValueInitExpr(T);
8559}
Mike Stump11289f42009-09-09 15:08:12 +00008560
Douglas Gregora16548e2009-08-11 05:31:07 +00008561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008563TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008564 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8565 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008567
John McCalldadc5752010-08-24 06:29:42 +00008568 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008571
Douglas Gregora16548e2009-08-11 05:31:07 +00008572 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008573 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008575 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008576
John McCallb268a282010-08-23 23:25:46 +00008577 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008578 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008579}
8580
8581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008583TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008584 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008585 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008586 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8587 &ArgumentChanged))
8588 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008589
Douglas Gregora16548e2009-08-11 05:31:07 +00008590 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008591 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008592 E->getRParenLoc());
8593}
Mike Stump11289f42009-09-09 15:08:12 +00008594
Douglas Gregora16548e2009-08-11 05:31:07 +00008595/// \brief Transform an address-of-label expression.
8596///
8597/// By default, the transformation of an address-of-label expression always
8598/// rebuilds the expression, so that the label identifier can be resolved to
8599/// the corresponding label statement by semantic analysis.
8600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008601ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008602TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008603 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8604 E->getLabel());
8605 if (!LD)
8606 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008607
Douglas Gregora16548e2009-08-11 05:31:07 +00008608 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008609 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008610}
Mike Stump11289f42009-09-09 15:08:12 +00008611
8612template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008614TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008615 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008616 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008617 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008618 if (SubStmt.isInvalid()) {
8619 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008620 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008621 }
Mike Stump11289f42009-09-09 15:08:12 +00008622
Douglas Gregora16548e2009-08-11 05:31:07 +00008623 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008624 SubStmt.get() == E->getSubStmt()) {
8625 // Calling this an 'error' is unintuitive, but it does the right thing.
8626 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008627 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008628 }
Mike Stump11289f42009-09-09 15:08:12 +00008629
8630 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008631 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 E->getRParenLoc());
8633}
Mike Stump11289f42009-09-09 15:08:12 +00008634
Douglas Gregora16548e2009-08-11 05:31:07 +00008635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008636ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008637TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008638 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008641
John McCalldadc5752010-08-24 06:29:42 +00008642 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008643 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008645
John McCalldadc5752010-08-24 06:29:42 +00008646 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008647 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008649
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (!getDerived().AlwaysRebuild() &&
8651 Cond.get() == E->getCond() &&
8652 LHS.get() == E->getLHS() &&
8653 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008654 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008655
Douglas Gregora16548e2009-08-11 05:31:07 +00008656 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008657 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008658 E->getRParenLoc());
8659}
Mike Stump11289f42009-09-09 15:08:12 +00008660
Douglas Gregora16548e2009-08-11 05:31:07 +00008661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008663TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008664 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008665}
8666
8667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008669TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008670 switch (E->getOperator()) {
8671 case OO_New:
8672 case OO_Delete:
8673 case OO_Array_New:
8674 case OO_Array_Delete:
8675 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008676
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008677 case OO_Call: {
8678 // This is a call to an object's operator().
8679 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8680
8681 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008682 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008683 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008684 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008685
8686 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008687 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8688 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008689
8690 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008691 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008692 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008693 Args))
8694 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008695
John McCallb268a282010-08-23 23:25:46 +00008696 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008697 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008698 E->getLocEnd());
8699 }
8700
8701#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8702 case OO_##Name:
8703#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8704#include "clang/Basic/OperatorKinds.def"
8705 case OO_Subscript:
8706 // Handled below.
8707 break;
8708
8709 case OO_Conditional:
8710 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008711
8712 case OO_None:
8713 case NUM_OVERLOADED_OPERATORS:
8714 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008715 }
8716
John McCalldadc5752010-08-24 06:29:42 +00008717 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008718 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008720
Richard Smithdb2630f2012-10-21 03:28:35 +00008721 ExprResult First;
8722 if (E->getOperator() == OO_Amp)
8723 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8724 else
8725 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008726 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008727 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008728
John McCalldadc5752010-08-24 06:29:42 +00008729 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008730 if (E->getNumArgs() == 2) {
8731 Second = getDerived().TransformExpr(E->getArg(1));
8732 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008733 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008734 }
Mike Stump11289f42009-09-09 15:08:12 +00008735
Douglas Gregora16548e2009-08-11 05:31:07 +00008736 if (!getDerived().AlwaysRebuild() &&
8737 Callee.get() == E->getCallee() &&
8738 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008739 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008740 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008741
Lang Hames5de91cc2012-10-02 04:45:10 +00008742 Sema::FPContractStateRAII FPContractState(getSema());
8743 getSema().FPFeatures.fp_contract = E->isFPContractable();
8744
Douglas Gregora16548e2009-08-11 05:31:07 +00008745 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8746 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008747 Callee.get(),
8748 First.get(),
8749 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008750}
Mike Stump11289f42009-09-09 15:08:12 +00008751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008753ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008754TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8755 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008756}
Mike Stump11289f42009-09-09 15:08:12 +00008757
Douglas Gregora16548e2009-08-11 05:31:07 +00008758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008759ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008760TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8761 // Transform the callee.
8762 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8763 if (Callee.isInvalid())
8764 return ExprError();
8765
8766 // Transform exec config.
8767 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8768 if (EC.isInvalid())
8769 return ExprError();
8770
8771 // Transform arguments.
8772 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008773 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008774 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008775 &ArgChanged))
8776 return ExprError();
8777
8778 if (!getDerived().AlwaysRebuild() &&
8779 Callee.get() == E->getCallee() &&
8780 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008781 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008782
8783 // FIXME: Wrong source location information for the '('.
8784 SourceLocation FakeLParenLoc
8785 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8786 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008787 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008788 E->getRParenLoc(), EC.get());
8789}
8790
8791template<typename Derived>
8792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008793TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008794 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8795 if (!Type)
8796 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008797
John McCalldadc5752010-08-24 06:29:42 +00008798 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008799 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008800 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008801 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008802
Douglas Gregora16548e2009-08-11 05:31:07 +00008803 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008804 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008805 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008806 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008807 return getDerived().RebuildCXXNamedCastExpr(
8808 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8809 Type, E->getAngleBrackets().getEnd(),
8810 // FIXME. this should be '(' location
8811 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008812}
Mike Stump11289f42009-09-09 15:08:12 +00008813
Douglas Gregora16548e2009-08-11 05:31:07 +00008814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008815ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008816TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8817 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008818}
Mike Stump11289f42009-09-09 15:08:12 +00008819
8820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008822TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8823 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008824}
8825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008827ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008828TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008829 CXXReinterpretCastExpr *E) {
8830 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008831}
Mike Stump11289f42009-09-09 15:08:12 +00008832
Douglas Gregora16548e2009-08-11 05:31:07 +00008833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008835TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8836 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008837}
Mike Stump11289f42009-09-09 15:08:12 +00008838
Douglas Gregora16548e2009-08-11 05:31:07 +00008839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008840ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008841TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008842 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008843 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8844 if (!Type)
8845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008846
John McCalldadc5752010-08-24 06:29:42 +00008847 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008848 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008849 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008851
Douglas Gregora16548e2009-08-11 05:31:07 +00008852 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008853 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008854 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008855 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008856
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008857 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008858 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008859 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008860 E->getRParenLoc());
8861}
Mike Stump11289f42009-09-09 15:08:12 +00008862
Douglas Gregora16548e2009-08-11 05:31:07 +00008863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008865TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008866 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008867 TypeSourceInfo *TInfo
8868 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8869 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008871
Douglas Gregora16548e2009-08-11 05:31:07 +00008872 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008873 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008874 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008875
Douglas Gregor9da64192010-04-26 22:37:10 +00008876 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8877 E->getLocStart(),
8878 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008879 E->getLocEnd());
8880 }
Mike Stump11289f42009-09-09 15:08:12 +00008881
Eli Friedman456f0182012-01-20 01:26:23 +00008882 // We don't know whether the subexpression is potentially evaluated until
8883 // after we perform semantic analysis. We speculatively assume it is
8884 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008885 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008886 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8887 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008888
John McCalldadc5752010-08-24 06:29:42 +00008889 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008890 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008892
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 if (!getDerived().AlwaysRebuild() &&
8894 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008895 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008896
Douglas Gregor9da64192010-04-26 22:37:10 +00008897 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8898 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008899 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008900 E->getLocEnd());
8901}
8902
8903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008904ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008905TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8906 if (E->isTypeOperand()) {
8907 TypeSourceInfo *TInfo
8908 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8909 if (!TInfo)
8910 return ExprError();
8911
8912 if (!getDerived().AlwaysRebuild() &&
8913 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008914 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008915
Douglas Gregor69735112011-03-06 17:40:41 +00008916 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008917 E->getLocStart(),
8918 TInfo,
8919 E->getLocEnd());
8920 }
8921
Francois Pichet9f4f2072010-09-08 12:20:18 +00008922 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8923
8924 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8925 if (SubExpr.isInvalid())
8926 return ExprError();
8927
8928 if (!getDerived().AlwaysRebuild() &&
8929 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008930 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008931
8932 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8933 E->getLocStart(),
8934 SubExpr.get(),
8935 E->getLocEnd());
8936}
8937
8938template<typename Derived>
8939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008940TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008941 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008942}
Mike Stump11289f42009-09-09 15:08:12 +00008943
Douglas Gregora16548e2009-08-11 05:31:07 +00008944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008945ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008946TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008947 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008948 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008949}
Mike Stump11289f42009-09-09 15:08:12 +00008950
Douglas Gregora16548e2009-08-11 05:31:07 +00008951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008953TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008954 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008955
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008956 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8957 // Make sure that we capture 'this'.
8958 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008959 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008961
Douglas Gregorb15af892010-01-07 23:12:05 +00008962 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008963}
Mike Stump11289f42009-09-09 15:08:12 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008967TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008968 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008969 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008971
Douglas Gregora16548e2009-08-11 05:31:07 +00008972 if (!getDerived().AlwaysRebuild() &&
8973 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008974 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008975
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008976 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8977 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008978}
Mike Stump11289f42009-09-09 15:08:12 +00008979
Douglas Gregora16548e2009-08-11 05:31:07 +00008980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008981ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008982TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008983 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008984 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8985 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008988
Chandler Carruth794da4c2010-02-08 06:42:49 +00008989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008990 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008991 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008992
Douglas Gregor033f6752009-12-23 23:03:06 +00008993 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008994}
Mike Stump11289f42009-09-09 15:08:12 +00008995
Douglas Gregora16548e2009-08-11 05:31:07 +00008996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008997ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008998TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8999 FieldDecl *Field
9000 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9001 E->getField()));
9002 if (!Field)
9003 return ExprError();
9004
9005 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009006 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009007
9008 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9009}
9010
9011template<typename Derived>
9012ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009013TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9014 CXXScalarValueInitExpr *E) {
9015 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9016 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009017 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009018
Douglas Gregora16548e2009-08-11 05:31:07 +00009019 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009020 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009021 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009022
Chad Rosier1dcde962012-08-08 18:46:20 +00009023 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009024 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009025 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009026}
Mike Stump11289f42009-09-09 15:08:12 +00009027
Douglas Gregora16548e2009-08-11 05:31:07 +00009028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009030TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009031 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009032 TypeSourceInfo *AllocTypeInfo
9033 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9034 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009036
Douglas Gregora16548e2009-08-11 05:31:07 +00009037 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009038 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009039 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009040 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009041
Douglas Gregora16548e2009-08-11 05:31:07 +00009042 // Transform the placement arguments (if any).
9043 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009044 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009045 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009046 E->getNumPlacementArgs(), true,
9047 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009048 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009049
Sebastian Redl6047f072012-02-16 12:22:20 +00009050 // Transform the initializer (if any).
9051 Expr *OldInit = E->getInitializer();
9052 ExprResult NewInit;
9053 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009054 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009055 if (NewInit.isInvalid())
9056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009057
Sebastian Redl6047f072012-02-16 12:22:20 +00009058 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009059 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009060 if (E->getOperatorNew()) {
9061 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009062 getDerived().TransformDecl(E->getLocStart(),
9063 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009064 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009065 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009066 }
9067
Craig Topperc3ec1492014-05-26 06:22:03 +00009068 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009069 if (E->getOperatorDelete()) {
9070 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009071 getDerived().TransformDecl(E->getLocStart(),
9072 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009073 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009074 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009075 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009076
Douglas Gregora16548e2009-08-11 05:31:07 +00009077 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009078 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009079 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009080 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009081 OperatorNew == E->getOperatorNew() &&
9082 OperatorDelete == E->getOperatorDelete() &&
9083 !ArgumentChanged) {
9084 // Mark any declarations we need as referenced.
9085 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009086 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009087 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009088 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009089 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009090
Sebastian Redl6047f072012-02-16 12:22:20 +00009091 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009092 QualType ElementType
9093 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9094 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9095 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9096 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009097 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009098 }
9099 }
9100 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009101
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009102 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009103 }
Mike Stump11289f42009-09-09 15:08:12 +00009104
Douglas Gregor0744ef62010-09-07 21:49:58 +00009105 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009106 if (!ArraySize.get()) {
9107 // If no array size was specified, but the new expression was
9108 // instantiated with an array type (e.g., "new T" where T is
9109 // instantiated with "int[4]"), extract the outer bound from the
9110 // array type as our array size. We do this with constant and
9111 // dependently-sized array types.
9112 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9113 if (!ArrayT) {
9114 // Do nothing
9115 } else if (const ConstantArrayType *ConsArrayT
9116 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009117 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9118 SemaRef.Context.getSizeType(),
9119 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009120 AllocType = ConsArrayT->getElementType();
9121 } else if (const DependentSizedArrayType *DepArrayT
9122 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9123 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009124 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009125 AllocType = DepArrayT->getElementType();
9126 }
9127 }
9128 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009129
Douglas Gregora16548e2009-08-11 05:31:07 +00009130 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9131 E->isGlobalNew(),
9132 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009133 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009134 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009135 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009136 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009137 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009138 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009139 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009140 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009141}
Mike Stump11289f42009-09-09 15:08:12 +00009142
Douglas Gregora16548e2009-08-11 05:31:07 +00009143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009144ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009145TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009146 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009147 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009149
Douglas Gregord2d9da02010-02-26 00:38:10 +00009150 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009151 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009152 if (E->getOperatorDelete()) {
9153 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009154 getDerived().TransformDecl(E->getLocStart(),
9155 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009156 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009157 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009159
Douglas Gregora16548e2009-08-11 05:31:07 +00009160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009161 Operand.get() == E->getArgument() &&
9162 OperatorDelete == E->getOperatorDelete()) {
9163 // Mark any declarations we need as referenced.
9164 // FIXME: instantiation-specific.
9165 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009166 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009167
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009168 if (!E->getArgument()->isTypeDependent()) {
9169 QualType Destroyed = SemaRef.Context.getBaseElementType(
9170 E->getDestroyedType());
9171 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9172 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009173 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009174 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009175 }
9176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009177
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009178 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009179 }
Mike Stump11289f42009-09-09 15:08:12 +00009180
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9182 E->isGlobalDelete(),
9183 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009184 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009185}
Mike Stump11289f42009-09-09 15:08:12 +00009186
Douglas Gregora16548e2009-08-11 05:31:07 +00009187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009188ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009189TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009190 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009191 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009192 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009194
John McCallba7bf592010-08-24 05:47:05 +00009195 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009196 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009197 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009198 E->getOperatorLoc(),
9199 E->isArrow()? tok::arrow : tok::period,
9200 ObjectTypePtr,
9201 MayBePseudoDestructor);
9202 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009203 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009204
John McCallba7bf592010-08-24 05:47:05 +00009205 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009206 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9207 if (QualifierLoc) {
9208 QualifierLoc
9209 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9210 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009211 return ExprError();
9212 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009213 CXXScopeSpec SS;
9214 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009215
Douglas Gregor678f90d2010-02-25 01:56:36 +00009216 PseudoDestructorTypeStorage Destroyed;
9217 if (E->getDestroyedTypeInfo()) {
9218 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009219 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009220 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009221 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009222 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009223 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009224 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009225 // We aren't likely to be able to resolve the identifier down to a type
9226 // now anyway, so just retain the identifier.
9227 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9228 E->getDestroyedTypeLoc());
9229 } else {
9230 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009231 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009232 *E->getDestroyedTypeIdentifier(),
9233 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009234 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009235 SS, ObjectTypePtr,
9236 false);
9237 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009238 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009239
Douglas Gregor678f90d2010-02-25 01:56:36 +00009240 Destroyed
9241 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9242 E->getDestroyedTypeLoc());
9243 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009244
Craig Topperc3ec1492014-05-26 06:22:03 +00009245 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009246 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009247 CXXScopeSpec EmptySS;
9248 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009249 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009250 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009251 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009252 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009253
John McCallb268a282010-08-23 23:25:46 +00009254 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009255 E->getOperatorLoc(),
9256 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009257 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009258 ScopeTypeInfo,
9259 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009260 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009261 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009262}
Mike Stump11289f42009-09-09 15:08:12 +00009263
Douglas Gregorad8a3362009-09-04 17:36:40 +00009264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009265ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009266TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009267 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009268 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9269 Sema::LookupOrdinaryName);
9270
9271 // Transform all the decls.
9272 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9273 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009274 NamedDecl *InstD = static_cast<NamedDecl*>(
9275 getDerived().TransformDecl(Old->getNameLoc(),
9276 *I));
John McCall84d87672009-12-10 09:41:52 +00009277 if (!InstD) {
9278 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9279 // This can happen because of dependent hiding.
9280 if (isa<UsingShadowDecl>(*I))
9281 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009282 else {
9283 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009284 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009285 }
John McCall84d87672009-12-10 09:41:52 +00009286 }
John McCalle66edc12009-11-24 19:00:30 +00009287
9288 // Expand using declarations.
9289 if (isa<UsingDecl>(InstD)) {
9290 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009291 for (auto *I : UD->shadows())
9292 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009293 continue;
9294 }
9295
9296 R.addDecl(InstD);
9297 }
9298
9299 // Resolve a kind, but don't do any further analysis. If it's
9300 // ambiguous, the callee needs to deal with it.
9301 R.resolveKind();
9302
9303 // Rebuild the nested-name qualifier, if present.
9304 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009305 if (Old->getQualifierLoc()) {
9306 NestedNameSpecifierLoc QualifierLoc
9307 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9308 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009309 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009310
Douglas Gregor0da1d432011-02-28 20:01:57 +00009311 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009312 }
9313
Douglas Gregor9262f472010-04-27 18:19:34 +00009314 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009315 CXXRecordDecl *NamingClass
9316 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9317 Old->getNameLoc(),
9318 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009319 if (!NamingClass) {
9320 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009321 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009323
Douglas Gregorda7be082010-04-27 16:10:10 +00009324 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009325 }
9326
Abramo Bagnara7945c982012-01-27 09:46:47 +00009327 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9328
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009329 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009330 // it's a normal declaration name or member reference.
9331 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9332 NamedDecl *D = R.getAsSingle<NamedDecl>();
9333 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9334 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9335 // give a good diagnostic.
9336 if (D && D->isCXXInstanceMember()) {
9337 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9338 /*TemplateArgs=*/nullptr,
9339 /*Scope=*/nullptr);
9340 }
9341
John McCalle66edc12009-11-24 19:00:30 +00009342 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009343 }
John McCalle66edc12009-11-24 19:00:30 +00009344
9345 // If we have template arguments, rebuild them, then rebuild the
9346 // templateid expression.
9347 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009348 if (Old->hasExplicitTemplateArgs() &&
9349 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009350 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009351 TransArgs)) {
9352 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009353 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009354 }
John McCalle66edc12009-11-24 19:00:30 +00009355
Abramo Bagnara7945c982012-01-27 09:46:47 +00009356 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009357 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009358}
Mike Stump11289f42009-09-09 15:08:12 +00009359
Douglas Gregora16548e2009-08-11 05:31:07 +00009360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009361ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009362TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9363 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009364 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009365 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9366 TypeSourceInfo *From = E->getArg(I);
9367 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009368 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009369 TypeLocBuilder TLB;
9370 TLB.reserve(FromTL.getFullDataSize());
9371 QualType To = getDerived().TransformType(TLB, FromTL);
9372 if (To.isNull())
9373 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009374
Douglas Gregor29c42f22012-02-24 07:38:34 +00009375 if (To == From->getType())
9376 Args.push_back(From);
9377 else {
9378 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9379 ArgChanged = true;
9380 }
9381 continue;
9382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009383
Douglas Gregor29c42f22012-02-24 07:38:34 +00009384 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009385
Douglas Gregor29c42f22012-02-24 07:38:34 +00009386 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009387 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009388 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9389 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9390 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009391
Douglas Gregor29c42f22012-02-24 07:38:34 +00009392 // Determine whether the set of unexpanded parameter packs can and should
9393 // be expanded.
9394 bool Expand = true;
9395 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009396 Optional<unsigned> OrigNumExpansions =
9397 ExpansionTL.getTypePtr()->getNumExpansions();
9398 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009399 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9400 PatternTL.getSourceRange(),
9401 Unexpanded,
9402 Expand, RetainExpansion,
9403 NumExpansions))
9404 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009405
Douglas Gregor29c42f22012-02-24 07:38:34 +00009406 if (!Expand) {
9407 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009408 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009409 // expansion.
9410 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009411
Douglas Gregor29c42f22012-02-24 07:38:34 +00009412 TypeLocBuilder TLB;
9413 TLB.reserve(From->getTypeLoc().getFullDataSize());
9414
9415 QualType To = getDerived().TransformType(TLB, PatternTL);
9416 if (To.isNull())
9417 return ExprError();
9418
Chad Rosier1dcde962012-08-08 18:46:20 +00009419 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009420 PatternTL.getSourceRange(),
9421 ExpansionTL.getEllipsisLoc(),
9422 NumExpansions);
9423 if (To.isNull())
9424 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009425
Douglas Gregor29c42f22012-02-24 07:38:34 +00009426 PackExpansionTypeLoc ToExpansionTL
9427 = TLB.push<PackExpansionTypeLoc>(To);
9428 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9429 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9430 continue;
9431 }
9432
9433 // Expand the pack expansion by substituting for each argument in the
9434 // pack(s).
9435 for (unsigned I = 0; I != *NumExpansions; ++I) {
9436 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9437 TypeLocBuilder TLB;
9438 TLB.reserve(PatternTL.getFullDataSize());
9439 QualType To = getDerived().TransformType(TLB, PatternTL);
9440 if (To.isNull())
9441 return ExprError();
9442
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009443 if (To->containsUnexpandedParameterPack()) {
9444 To = getDerived().RebuildPackExpansionType(To,
9445 PatternTL.getSourceRange(),
9446 ExpansionTL.getEllipsisLoc(),
9447 NumExpansions);
9448 if (To.isNull())
9449 return ExprError();
9450
9451 PackExpansionTypeLoc ToExpansionTL
9452 = TLB.push<PackExpansionTypeLoc>(To);
9453 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9454 }
9455
Douglas Gregor29c42f22012-02-24 07:38:34 +00009456 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009458
Douglas Gregor29c42f22012-02-24 07:38:34 +00009459 if (!RetainExpansion)
9460 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009461
Douglas Gregor29c42f22012-02-24 07:38:34 +00009462 // If we're supposed to retain a pack expansion, do so by temporarily
9463 // forgetting the partially-substituted parameter pack.
9464 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9465
9466 TypeLocBuilder TLB;
9467 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009468
Douglas Gregor29c42f22012-02-24 07:38:34 +00009469 QualType To = getDerived().TransformType(TLB, PatternTL);
9470 if (To.isNull())
9471 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009472
9473 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009474 PatternTL.getSourceRange(),
9475 ExpansionTL.getEllipsisLoc(),
9476 NumExpansions);
9477 if (To.isNull())
9478 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009479
Douglas Gregor29c42f22012-02-24 07:38:34 +00009480 PackExpansionTypeLoc ToExpansionTL
9481 = TLB.push<PackExpansionTypeLoc>(To);
9482 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9483 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009485
Douglas Gregor29c42f22012-02-24 07:38:34 +00009486 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009487 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009488
9489 return getDerived().RebuildTypeTrait(E->getTrait(),
9490 E->getLocStart(),
9491 Args,
9492 E->getLocEnd());
9493}
9494
9495template<typename Derived>
9496ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009497TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9498 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9499 if (!T)
9500 return ExprError();
9501
9502 if (!getDerived().AlwaysRebuild() &&
9503 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009504 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009505
9506 ExprResult SubExpr;
9507 {
9508 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9509 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9510 if (SubExpr.isInvalid())
9511 return ExprError();
9512
9513 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009514 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009515 }
9516
9517 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9518 E->getLocStart(),
9519 T,
9520 SubExpr.get(),
9521 E->getLocEnd());
9522}
9523
9524template<typename Derived>
9525ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009526TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9527 ExprResult SubExpr;
9528 {
9529 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9530 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9531 if (SubExpr.isInvalid())
9532 return ExprError();
9533
9534 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009535 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009536 }
9537
9538 return getDerived().RebuildExpressionTrait(
9539 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9540}
9541
Reid Kleckner32506ed2014-06-12 23:03:48 +00009542template <typename Derived>
9543ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9544 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9545 TypeSourceInfo **RecoveryTSI) {
9546 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9547 DRE, AddrTaken, RecoveryTSI);
9548
9549 // Propagate both errors and recovered types, which return ExprEmpty.
9550 if (!NewDRE.isUsable())
9551 return NewDRE;
9552
9553 // We got an expr, wrap it up in parens.
9554 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9555 return PE;
9556 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9557 PE->getRParen());
9558}
9559
9560template <typename Derived>
9561ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9562 DependentScopeDeclRefExpr *E) {
9563 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9564 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009565}
9566
9567template<typename Derived>
9568ExprResult
9569TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9570 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009571 bool IsAddressOfOperand,
9572 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009573 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009574 NestedNameSpecifierLoc QualifierLoc
9575 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9576 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009577 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009578 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009579
John McCall31f82722010-11-12 08:19:04 +00009580 // TODO: If this is a conversion-function-id, verify that the
9581 // destination type name (if present) resolves the same way after
9582 // instantiation as it did in the local scope.
9583
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009584 DeclarationNameInfo NameInfo
9585 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9586 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009588
John McCalle66edc12009-11-24 19:00:30 +00009589 if (!E->hasExplicitTemplateArgs()) {
9590 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009591 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009592 // Note: it is sufficient to compare the Name component of NameInfo:
9593 // if name has not changed, DNLoc has not changed either.
9594 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009595 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009596
Reid Kleckner32506ed2014-06-12 23:03:48 +00009597 return getDerived().RebuildDependentScopeDeclRefExpr(
9598 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9599 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009600 }
John McCall6b51f282009-11-23 01:53:49 +00009601
9602 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009603 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9604 E->getNumTemplateArgs(),
9605 TransArgs))
9606 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009607
Reid Kleckner32506ed2014-06-12 23:03:48 +00009608 return getDerived().RebuildDependentScopeDeclRefExpr(
9609 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9610 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009611}
9612
9613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009614ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009615TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009616 // CXXConstructExprs other than for list-initialization and
9617 // CXXTemporaryObjectExpr are always implicit, so when we have
9618 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009619 if ((E->getNumArgs() == 1 ||
9620 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009621 (!getDerived().DropCallArgument(E->getArg(0))) &&
9622 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009623 return getDerived().TransformExpr(E->getArg(0));
9624
Douglas Gregora16548e2009-08-11 05:31:07 +00009625 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9626
9627 QualType T = getDerived().TransformType(E->getType());
9628 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009629 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009630
9631 CXXConstructorDecl *Constructor
9632 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009633 getDerived().TransformDecl(E->getLocStart(),
9634 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009635 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009637
Douglas Gregora16548e2009-08-11 05:31:07 +00009638 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009639 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009640 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009641 &ArgumentChanged))
9642 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009643
Douglas Gregora16548e2009-08-11 05:31:07 +00009644 if (!getDerived().AlwaysRebuild() &&
9645 T == E->getType() &&
9646 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009647 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009648 // Mark the constructor as referenced.
9649 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009650 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009651 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009652 }
Mike Stump11289f42009-09-09 15:08:12 +00009653
Douglas Gregordb121ba2009-12-14 16:27:04 +00009654 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9655 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009656 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009657 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009658 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009659 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009660 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009661 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009662 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009663}
Mike Stump11289f42009-09-09 15:08:12 +00009664
Douglas Gregora16548e2009-08-11 05:31:07 +00009665/// \brief Transform a C++ temporary-binding expression.
9666///
Douglas Gregor363b1512009-12-24 18:51:59 +00009667/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9668/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009670ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009671TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009672 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009673}
Mike Stump11289f42009-09-09 15:08:12 +00009674
John McCall5d413782010-12-06 08:20:24 +00009675/// \brief Transform a C++ expression that contains cleanups that should
9676/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009677///
John McCall5d413782010-12-06 08:20:24 +00009678/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009679/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009681ExprResult
John McCall5d413782010-12-06 08:20:24 +00009682TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009683 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009684}
Mike Stump11289f42009-09-09 15:08:12 +00009685
Douglas Gregora16548e2009-08-11 05:31:07 +00009686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009687ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009688TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009689 CXXTemporaryObjectExpr *E) {
9690 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9691 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009693
Douglas Gregora16548e2009-08-11 05:31:07 +00009694 CXXConstructorDecl *Constructor
9695 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009696 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009697 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009698 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009700
Douglas Gregora16548e2009-08-11 05:31:07 +00009701 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009702 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009703 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009704 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009705 &ArgumentChanged))
9706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009707
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009709 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009710 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009711 !ArgumentChanged) {
9712 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009713 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009714 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009716
Richard Smithd59b8322012-12-19 01:39:02 +00009717 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009718 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9719 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009720 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009721 E->getLocEnd());
9722}
Mike Stump11289f42009-09-09 15:08:12 +00009723
Douglas Gregora16548e2009-08-11 05:31:07 +00009724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009725ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009726TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009727 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009728 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009729 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009730 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9731 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009732 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009733 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009734 CEnd = E->capture_end();
9735 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009736 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009737 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009738 EnterExpressionEvaluationContext EEEC(getSema(),
9739 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009740 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9741 C->getCapturedVar()->getInit(),
9742 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009743
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009744 if (NewExprInitResult.isInvalid())
9745 return ExprError();
9746 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009747
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009748 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009749 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +00009750 getSema().buildLambdaInitCaptureInitialization(
9751 C->getLocation(), OldVD->getType()->isReferenceType(),
9752 OldVD->getIdentifier(),
9753 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009754 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009755 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9756 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009757 }
9758
Faisal Vali2cba1332013-10-23 06:44:28 +00009759 // Transform the template parameters, and add them to the current
9760 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009761 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009762 E->getTemplateParameterList());
9763
Richard Smith01014ce2014-11-20 23:53:14 +00009764 // Transform the type of the original lambda's call operator.
9765 // The transformation MUST be done in the CurrentInstantiationScope since
9766 // it introduces a mapping of the original to the newly created
9767 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009768 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009769 {
9770 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9771 FunctionProtoTypeLoc OldCallOpFPTL =
9772 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009773
9774 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009775 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009776 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009777 QualType NewCallOpType = TransformFunctionProtoType(
9778 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009779 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9780 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9781 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009782 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009783 if (NewCallOpType.isNull())
9784 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009785 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9786 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009787 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009788
Richard Smithc38498f2015-04-27 21:27:54 +00009789 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9790 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9791 LSI->GLTemplateParameterList = TPL;
9792
Eli Friedmand564afb2012-09-19 01:18:11 +00009793 // Create the local class that will describe the lambda.
9794 CXXRecordDecl *Class
9795 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009796 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009797 /*KnownDependent=*/false,
9798 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009799 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9800
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009801 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009802 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9803 Class, E->getIntroducerRange(), NewCallOpTSI,
9804 E->getCallOperator()->getLocEnd(),
9805 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009806 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009807
Faisal Vali2cba1332013-10-23 06:44:28 +00009808 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009809 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009810
Douglas Gregorb4328232012-02-14 00:00:48 +00009811 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009812 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009813 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009814
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009815 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009816 getSema().buildLambdaScope(LSI, NewCallOperator,
9817 E->getIntroducerRange(),
9818 E->getCaptureDefault(),
9819 E->getCaptureDefaultLoc(),
9820 E->hasExplicitParameters(),
9821 E->hasExplicitResultType(),
9822 E->isMutable());
9823
9824 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009825
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009826 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009827 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009828 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009829 CEnd = E->capture_end();
9830 C != CEnd; ++C) {
9831 // When we hit the first implicit capture, tell Sema that we've finished
9832 // the list of explicit captures.
9833 if (!FinishedExplicitCaptures && C->isImplicit()) {
9834 getSema().finishLambdaExplicitCaptures(LSI);
9835 FinishedExplicitCaptures = true;
9836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009837
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009838 // Capturing 'this' is trivial.
9839 if (C->capturesThis()) {
9840 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9841 continue;
9842 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009843 // Captured expression will be recaptured during captured variables
9844 // rebuilding.
9845 if (C->capturesVLAType())
9846 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009847
Richard Smithba71c082013-05-16 06:20:58 +00009848 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009849 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009850 InitCaptureInfoTy InitExprTypePair =
9851 InitCaptureExprsAndTypes[C - E->capture_begin()];
9852 ExprResult Init = InitExprTypePair.first;
9853 QualType InitQualType = InitExprTypePair.second;
9854 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009855 Invalid = true;
9856 continue;
9857 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009858 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009859 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +00009860 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
9861 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009862 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009863 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009864 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009865 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009866 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009867 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009868 continue;
9869 }
9870
9871 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9872
Douglas Gregor3e308b12012-02-14 19:27:52 +00009873 // Determine the capture kind for Sema.
9874 Sema::TryCaptureKind Kind
9875 = C->isImplicit()? Sema::TryCapture_Implicit
9876 : C->getCaptureKind() == LCK_ByCopy
9877 ? Sema::TryCapture_ExplicitByVal
9878 : Sema::TryCapture_ExplicitByRef;
9879 SourceLocation EllipsisLoc;
9880 if (C->isPackExpansion()) {
9881 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9882 bool ShouldExpand = false;
9883 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009884 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009885 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9886 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009887 Unexpanded,
9888 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009889 NumExpansions)) {
9890 Invalid = true;
9891 continue;
9892 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009893
Douglas Gregor3e308b12012-02-14 19:27:52 +00009894 if (ShouldExpand) {
9895 // The transform has determined that we should perform an expansion;
9896 // transform and capture each of the arguments.
9897 // expansion of the pattern. Do so.
9898 VarDecl *Pack = C->getCapturedVar();
9899 for (unsigned I = 0; I != *NumExpansions; ++I) {
9900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9901 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009902 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009903 Pack));
9904 if (!CapturedVar) {
9905 Invalid = true;
9906 continue;
9907 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009908
Douglas Gregor3e308b12012-02-14 19:27:52 +00009909 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009910 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9911 }
Richard Smith9467be42014-06-06 17:33:35 +00009912
9913 // FIXME: Retain a pack expansion if RetainExpansion is true.
9914
Douglas Gregor3e308b12012-02-14 19:27:52 +00009915 continue;
9916 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009917
Douglas Gregor3e308b12012-02-14 19:27:52 +00009918 EllipsisLoc = C->getEllipsisLoc();
9919 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009920
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009921 // Transform the captured variable.
9922 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009923 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009924 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009925 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009926 Invalid = true;
9927 continue;
9928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009929
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009930 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009931 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9932 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009933 }
9934 if (!FinishedExplicitCaptures)
9935 getSema().finishLambdaExplicitCaptures(LSI);
9936
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009937 // Enter a new evaluation context to insulate the lambda from any
9938 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009939 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009940
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009941 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009942 StmtResult Body =
9943 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9944
9945 // ActOnLambda* will pop the function scope for us.
9946 FuncScopeCleanup.disable();
9947
Douglas Gregorb4328232012-02-14 00:00:48 +00009948 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009949 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009950 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009951 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009952 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009953 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009954
Richard Smithc38498f2015-04-27 21:27:54 +00009955 // Copy the LSI before ActOnFinishFunctionBody removes it.
9956 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9957 // the call operator.
9958 auto LSICopy = *LSI;
9959 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9960 /*IsInstantiation*/ true);
9961 SavedContext.pop();
9962
9963 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9964 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009965}
9966
9967template<typename Derived>
9968ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009969TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009970 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009971 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9972 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009974
Douglas Gregora16548e2009-08-11 05:31:07 +00009975 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009976 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009977 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009978 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009979 &ArgumentChanged))
9980 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009981
Douglas Gregora16548e2009-08-11 05:31:07 +00009982 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009983 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009984 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009985 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009986
Douglas Gregora16548e2009-08-11 05:31:07 +00009987 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009988 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009989 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009990 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009991 E->getRParenLoc());
9992}
Mike Stump11289f42009-09-09 15:08:12 +00009993
Douglas Gregora16548e2009-08-11 05:31:07 +00009994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009995ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009996TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009997 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009998 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009999 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010000 Expr *OldBase;
10001 QualType BaseType;
10002 QualType ObjectType;
10003 if (!E->isImplicitAccess()) {
10004 OldBase = E->getBase();
10005 Base = getDerived().TransformExpr(OldBase);
10006 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010008
John McCall2d74de92009-12-01 22:10:20 +000010009 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010010 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010011 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010012 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010013 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010014 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010015 ObjectTy,
10016 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010017 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010018 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010019
John McCallba7bf592010-08-24 05:47:05 +000010020 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010021 BaseType = ((Expr*) Base.get())->getType();
10022 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010023 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010024 BaseType = getDerived().TransformType(E->getBaseType());
10025 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10026 }
Mike Stump11289f42009-09-09 15:08:12 +000010027
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010028 // Transform the first part of the nested-name-specifier that qualifies
10029 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010030 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010031 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010032 E->getFirstQualifierFoundInScope(),
10033 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010034
Douglas Gregore16af532011-02-28 18:50:33 +000010035 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010036 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010037 QualifierLoc
10038 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10039 ObjectType,
10040 FirstQualifierInScope);
10041 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010042 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010043 }
Mike Stump11289f42009-09-09 15:08:12 +000010044
Abramo Bagnara7945c982012-01-27 09:46:47 +000010045 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10046
John McCall31f82722010-11-12 08:19:04 +000010047 // TODO: If this is a conversion-function-id, verify that the
10048 // destination type name (if present) resolves the same way after
10049 // instantiation as it did in the local scope.
10050
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010051 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010052 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010053 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010055
John McCall2d74de92009-12-01 22:10:20 +000010056 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010057 // This is a reference to a member without an explicitly-specified
10058 // template argument list. Optimize for this common case.
10059 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010060 Base.get() == OldBase &&
10061 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010062 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010063 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010064 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010065 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010066
John McCallb268a282010-08-23 23:25:46 +000010067 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010068 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010069 E->isArrow(),
10070 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010071 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010072 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010073 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010074 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010075 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010076 }
10077
John McCall6b51f282009-11-23 01:53:49 +000010078 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010079 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10080 E->getNumTemplateArgs(),
10081 TransArgs))
10082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010083
John McCallb268a282010-08-23 23:25:46 +000010084 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010085 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010086 E->isArrow(),
10087 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010088 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010089 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010090 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010091 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010092 &TransArgs);
10093}
10094
10095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010097TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010098 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010099 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010100 QualType BaseType;
10101 if (!Old->isImplicitAccess()) {
10102 Base = getDerived().TransformExpr(Old->getBase());
10103 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010104 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010105 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010106 Old->isArrow());
10107 if (Base.isInvalid())
10108 return ExprError();
10109 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010110 } else {
10111 BaseType = getDerived().TransformType(Old->getBaseType());
10112 }
John McCall10eae182009-11-30 22:42:35 +000010113
Douglas Gregor0da1d432011-02-28 20:01:57 +000010114 NestedNameSpecifierLoc QualifierLoc;
10115 if (Old->getQualifierLoc()) {
10116 QualifierLoc
10117 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10118 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010119 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010120 }
10121
Abramo Bagnara7945c982012-01-27 09:46:47 +000010122 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10123
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010124 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010125 Sema::LookupOrdinaryName);
10126
10127 // Transform all the decls.
10128 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10129 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010130 NamedDecl *InstD = static_cast<NamedDecl*>(
10131 getDerived().TransformDecl(Old->getMemberLoc(),
10132 *I));
John McCall84d87672009-12-10 09:41:52 +000010133 if (!InstD) {
10134 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10135 // This can happen because of dependent hiding.
10136 if (isa<UsingShadowDecl>(*I))
10137 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010138 else {
10139 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010140 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010141 }
John McCall84d87672009-12-10 09:41:52 +000010142 }
John McCall10eae182009-11-30 22:42:35 +000010143
10144 // Expand using declarations.
10145 if (isa<UsingDecl>(InstD)) {
10146 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010147 for (auto *I : UD->shadows())
10148 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010149 continue;
10150 }
10151
10152 R.addDecl(InstD);
10153 }
10154
10155 R.resolveKind();
10156
Douglas Gregor9262f472010-04-27 18:19:34 +000010157 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010158 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010159 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010160 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010161 Old->getMemberLoc(),
10162 Old->getNamingClass()));
10163 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010164 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010165
Douglas Gregorda7be082010-04-27 16:10:10 +000010166 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010167 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010168
John McCall10eae182009-11-30 22:42:35 +000010169 TemplateArgumentListInfo TransArgs;
10170 if (Old->hasExplicitTemplateArgs()) {
10171 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10172 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010173 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10174 Old->getNumTemplateArgs(),
10175 TransArgs))
10176 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010177 }
John McCall38836f02010-01-15 08:34:02 +000010178
10179 // FIXME: to do this check properly, we will need to preserve the
10180 // first-qualifier-in-scope here, just in case we had a dependent
10181 // base (and therefore couldn't do the check) and a
10182 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010183 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010184
John McCallb268a282010-08-23 23:25:46 +000010185 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010186 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010187 Old->getOperatorLoc(),
10188 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010189 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010190 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010191 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010192 R,
10193 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010194 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010195}
10196
10197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010198ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010199TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010200 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010201 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10202 if (SubExpr.isInvalid())
10203 return ExprError();
10204
10205 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010206 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010207
10208 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10209}
10210
10211template<typename Derived>
10212ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010213TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010214 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10215 if (Pattern.isInvalid())
10216 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010217
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010218 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010219 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010220
Douglas Gregorb8840002011-01-14 21:20:45 +000010221 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10222 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010223}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010224
10225template<typename Derived>
10226ExprResult
10227TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10228 // If E is not value-dependent, then nothing will change when we transform it.
10229 // Note: This is an instantiation-centric view.
10230 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010231 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010232
Richard Smithd784e682015-09-23 21:41:42 +000010233 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010234
Richard Smithd784e682015-09-23 21:41:42 +000010235 ArrayRef<TemplateArgument> PackArgs;
10236 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010237
Richard Smithd784e682015-09-23 21:41:42 +000010238 // Find the argument list to transform.
10239 if (E->isPartiallySubstituted()) {
10240 PackArgs = E->getPartialArguments();
10241 } else if (E->isValueDependent()) {
10242 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10243 bool ShouldExpand = false;
10244 bool RetainExpansion = false;
10245 Optional<unsigned> NumExpansions;
10246 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10247 Unexpanded,
10248 ShouldExpand, RetainExpansion,
10249 NumExpansions))
10250 return ExprError();
10251
10252 // If we need to expand the pack, build a template argument from it and
10253 // expand that.
10254 if (ShouldExpand) {
10255 auto *Pack = E->getPack();
10256 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10257 ArgStorage = getSema().Context.getPackExpansionType(
10258 getSema().Context.getTypeDeclType(TTPD), None);
10259 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10260 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10261 } else {
10262 auto *VD = cast<ValueDecl>(Pack);
10263 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10264 VK_RValue, E->getPackLoc());
10265 if (DRE.isInvalid())
10266 return ExprError();
10267 ArgStorage = new (getSema().Context) PackExpansionExpr(
10268 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10269 }
10270 PackArgs = ArgStorage;
10271 }
10272 }
10273
10274 // If we're not expanding the pack, just transform the decl.
10275 if (!PackArgs.size()) {
10276 auto *Pack = cast_or_null<NamedDecl>(
10277 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010278 if (!Pack)
10279 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010280 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10281 E->getPackLoc(),
10282 E->getRParenLoc(), None, None);
10283 }
10284
10285 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10286 E->getPackLoc());
10287 {
10288 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10289 typedef TemplateArgumentLocInventIterator<
10290 Derived, const TemplateArgument*> PackLocIterator;
10291 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10292 PackLocIterator(*this, PackArgs.end()),
10293 TransformedPackArgs, /*Uneval*/true))
10294 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010295 }
10296
Richard Smithd784e682015-09-23 21:41:42 +000010297 SmallVector<TemplateArgument, 8> Args;
10298 bool PartialSubstitution = false;
10299 for (auto &Loc : TransformedPackArgs.arguments()) {
10300 Args.push_back(Loc.getArgument());
10301 if (Loc.getArgument().isPackExpansion())
10302 PartialSubstitution = true;
10303 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010304
Richard Smithd784e682015-09-23 21:41:42 +000010305 if (PartialSubstitution)
10306 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10307 E->getPackLoc(),
10308 E->getRParenLoc(), None, Args);
10309
10310 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010311 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010312 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010313}
10314
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010315template<typename Derived>
10316ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010317TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10318 SubstNonTypeTemplateParmPackExpr *E) {
10319 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010320 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010321}
10322
10323template<typename Derived>
10324ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010325TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10326 SubstNonTypeTemplateParmExpr *E) {
10327 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010328 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010329}
10330
10331template<typename Derived>
10332ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010333TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10334 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010335 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010336}
10337
10338template<typename Derived>
10339ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010340TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10341 MaterializeTemporaryExpr *E) {
10342 return getDerived().TransformExpr(E->GetTemporaryExpr());
10343}
Chad Rosier1dcde962012-08-08 18:46:20 +000010344
Douglas Gregorfe314812011-06-21 17:03:29 +000010345template<typename Derived>
10346ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010347TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10348 Expr *Pattern = E->getPattern();
10349
10350 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10351 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10352 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10353
10354 // Determine whether the set of unexpanded parameter packs can and should
10355 // be expanded.
10356 bool Expand = true;
10357 bool RetainExpansion = false;
10358 Optional<unsigned> NumExpansions;
10359 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10360 Pattern->getSourceRange(),
10361 Unexpanded,
10362 Expand, RetainExpansion,
10363 NumExpansions))
10364 return true;
10365
10366 if (!Expand) {
10367 // Do not expand any packs here, just transform and rebuild a fold
10368 // expression.
10369 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10370
10371 ExprResult LHS =
10372 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10373 if (LHS.isInvalid())
10374 return true;
10375
10376 ExprResult RHS =
10377 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10378 if (RHS.isInvalid())
10379 return true;
10380
10381 if (!getDerived().AlwaysRebuild() &&
10382 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10383 return E;
10384
10385 return getDerived().RebuildCXXFoldExpr(
10386 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10387 RHS.get(), E->getLocEnd());
10388 }
10389
10390 // The transform has determined that we should perform an elementwise
10391 // expansion of the pattern. Do so.
10392 ExprResult Result = getDerived().TransformExpr(E->getInit());
10393 if (Result.isInvalid())
10394 return true;
10395 bool LeftFold = E->isLeftFold();
10396
10397 // If we're retaining an expansion for a right fold, it is the innermost
10398 // component and takes the init (if any).
10399 if (!LeftFold && RetainExpansion) {
10400 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10401
10402 ExprResult Out = getDerived().TransformExpr(Pattern);
10403 if (Out.isInvalid())
10404 return true;
10405
10406 Result = getDerived().RebuildCXXFoldExpr(
10407 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10408 Result.get(), E->getLocEnd());
10409 if (Result.isInvalid())
10410 return true;
10411 }
10412
10413 for (unsigned I = 0; I != *NumExpansions; ++I) {
10414 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10415 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10416 ExprResult Out = getDerived().TransformExpr(Pattern);
10417 if (Out.isInvalid())
10418 return true;
10419
10420 if (Out.get()->containsUnexpandedParameterPack()) {
10421 // We still have a pack; retain a pack expansion for this slice.
10422 Result = getDerived().RebuildCXXFoldExpr(
10423 E->getLocStart(),
10424 LeftFold ? Result.get() : Out.get(),
10425 E->getOperator(), E->getEllipsisLoc(),
10426 LeftFold ? Out.get() : Result.get(),
10427 E->getLocEnd());
10428 } else if (Result.isUsable()) {
10429 // We've got down to a single element; build a binary operator.
10430 Result = getDerived().RebuildBinaryOperator(
10431 E->getEllipsisLoc(), E->getOperator(),
10432 LeftFold ? Result.get() : Out.get(),
10433 LeftFold ? Out.get() : Result.get());
10434 } else
10435 Result = Out;
10436
10437 if (Result.isInvalid())
10438 return true;
10439 }
10440
10441 // If we're retaining an expansion for a left fold, it is the outermost
10442 // component and takes the complete expansion so far as its init (if any).
10443 if (LeftFold && RetainExpansion) {
10444 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10445
10446 ExprResult Out = getDerived().TransformExpr(Pattern);
10447 if (Out.isInvalid())
10448 return true;
10449
10450 Result = getDerived().RebuildCXXFoldExpr(
10451 E->getLocStart(), Result.get(),
10452 E->getOperator(), E->getEllipsisLoc(),
10453 Out.get(), E->getLocEnd());
10454 if (Result.isInvalid())
10455 return true;
10456 }
10457
10458 // If we had no init and an empty pack, and we're not retaining an expansion,
10459 // then produce a fallback value or error.
10460 if (Result.isUnset())
10461 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10462 E->getOperator());
10463
10464 return Result;
10465}
10466
10467template<typename Derived>
10468ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010469TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10470 CXXStdInitializerListExpr *E) {
10471 return getDerived().TransformExpr(E->getSubExpr());
10472}
10473
10474template<typename Derived>
10475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010476TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010477 return SemaRef.MaybeBindToTemporary(E);
10478}
10479
10480template<typename Derived>
10481ExprResult
10482TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010483 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010484}
10485
10486template<typename Derived>
10487ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010488TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10489 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10490 if (SubExpr.isInvalid())
10491 return ExprError();
10492
10493 if (!getDerived().AlwaysRebuild() &&
10494 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010495 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010496
10497 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010498}
10499
10500template<typename Derived>
10501ExprResult
10502TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10503 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010504 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010505 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010506 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010507 /*IsCall=*/false, Elements, &ArgChanged))
10508 return ExprError();
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);
Chad Rosier1dcde962012-08-08 18:46:20 +000010512
Ted Kremeneke65b0862012-03-06 20:05:56 +000010513 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10514 Elements.data(),
10515 Elements.size());
10516}
10517
10518template<typename Derived>
10519ExprResult
10520TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010521 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010522 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010523 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010524 bool ArgChanged = false;
10525 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10526 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010527
Ted Kremeneke65b0862012-03-06 20:05:56 +000010528 if (OrigElement.isPackExpansion()) {
10529 // This key/value element is a pack expansion.
10530 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10531 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10532 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10533 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10534
10535 // Determine whether the set of unexpanded parameter packs can
10536 // and should be expanded.
10537 bool Expand = true;
10538 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010539 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10540 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010541 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10542 OrigElement.Value->getLocEnd());
10543 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10544 PatternRange,
10545 Unexpanded,
10546 Expand, RetainExpansion,
10547 NumExpansions))
10548 return ExprError();
10549
10550 if (!Expand) {
10551 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010552 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010553 // expansion.
10554 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10555 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10556 if (Key.isInvalid())
10557 return ExprError();
10558
10559 if (Key.get() != OrigElement.Key)
10560 ArgChanged = true;
10561
10562 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10563 if (Value.isInvalid())
10564 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010565
Ted Kremeneke65b0862012-03-06 20:05:56 +000010566 if (Value.get() != OrigElement.Value)
10567 ArgChanged = true;
10568
Chad Rosier1dcde962012-08-08 18:46:20 +000010569 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010570 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10571 };
10572 Elements.push_back(Expansion);
10573 continue;
10574 }
10575
10576 // Record right away that the argument was changed. This needs
10577 // to happen even if the array expands to nothing.
10578 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010579
Ted Kremeneke65b0862012-03-06 20:05:56 +000010580 // The transform has determined that we should perform an elementwise
10581 // expansion of the pattern. Do so.
10582 for (unsigned I = 0; I != *NumExpansions; ++I) {
10583 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10584 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10585 if (Key.isInvalid())
10586 return ExprError();
10587
10588 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10589 if (Value.isInvalid())
10590 return ExprError();
10591
Chad Rosier1dcde962012-08-08 18:46:20 +000010592 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010593 Key.get(), Value.get(), SourceLocation(), NumExpansions
10594 };
10595
10596 // If any unexpanded parameter packs remain, we still have a
10597 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010598 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010599 if (Key.get()->containsUnexpandedParameterPack() ||
10600 Value.get()->containsUnexpandedParameterPack())
10601 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010602
Ted Kremeneke65b0862012-03-06 20:05:56 +000010603 Elements.push_back(Element);
10604 }
10605
Richard Smith9467be42014-06-06 17:33:35 +000010606 // FIXME: Retain a pack expansion if RetainExpansion is true.
10607
Ted Kremeneke65b0862012-03-06 20:05:56 +000010608 // We've finished with this pack expansion.
10609 continue;
10610 }
10611
10612 // Transform and check key.
10613 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10614 if (Key.isInvalid())
10615 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010616
Ted Kremeneke65b0862012-03-06 20:05:56 +000010617 if (Key.get() != OrigElement.Key)
10618 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010619
Ted Kremeneke65b0862012-03-06 20:05:56 +000010620 // Transform and check value.
10621 ExprResult Value
10622 = getDerived().TransformExpr(OrigElement.Value);
10623 if (Value.isInvalid())
10624 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010625
Ted Kremeneke65b0862012-03-06 20:05:56 +000010626 if (Value.get() != OrigElement.Value)
10627 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010628
10629 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010630 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010631 };
10632 Elements.push_back(Element);
10633 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010634
Ted Kremeneke65b0862012-03-06 20:05:56 +000010635 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10636 return SemaRef.MaybeBindToTemporary(E);
10637
10638 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10639 Elements.data(),
10640 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010641}
10642
Mike Stump11289f42009-09-09 15:08:12 +000010643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010645TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010646 TypeSourceInfo *EncodedTypeInfo
10647 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10648 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010649 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010650
Douglas Gregora16548e2009-08-11 05:31:07 +000010651 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010652 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010653 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010654
10655 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010656 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010657 E->getRParenLoc());
10658}
Mike Stump11289f42009-09-09 15:08:12 +000010659
Douglas Gregora16548e2009-08-11 05:31:07 +000010660template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010661ExprResult TreeTransform<Derived>::
10662TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010663 // This is a kind of implicit conversion, and it needs to get dropped
10664 // and recomputed for the same general reasons that ImplicitCastExprs
10665 // do, as well a more specific one: this expression is only valid when
10666 // it appears *immediately* as an argument expression.
10667 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010668}
10669
10670template<typename Derived>
10671ExprResult TreeTransform<Derived>::
10672TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010673 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010674 = getDerived().TransformType(E->getTypeInfoAsWritten());
10675 if (!TSInfo)
10676 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010677
John McCall31168b02011-06-15 23:02:42 +000010678 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010679 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010680 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010681
John McCall31168b02011-06-15 23:02:42 +000010682 if (!getDerived().AlwaysRebuild() &&
10683 TSInfo == E->getTypeInfoAsWritten() &&
10684 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010685 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010686
John McCall31168b02011-06-15 23:02:42 +000010687 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010688 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010689 Result.get());
10690}
10691
10692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010694TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010695 // Transform arguments.
10696 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010697 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010698 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010699 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010700 &ArgChanged))
10701 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010702
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010703 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10704 // Class message: transform the receiver type.
10705 TypeSourceInfo *ReceiverTypeInfo
10706 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10707 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010708 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010709
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010710 // If nothing changed, just retain the existing message send.
10711 if (!getDerived().AlwaysRebuild() &&
10712 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010713 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010714
10715 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010716 SmallVector<SourceLocation, 16> SelLocs;
10717 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010718 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10719 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010720 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010721 E->getMethodDecl(),
10722 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010723 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010724 E->getRightLoc());
10725 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010726 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10727 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10728 // Build a new class message send to 'super'.
10729 SmallVector<SourceLocation, 16> SelLocs;
10730 E->getSelectorLocs(SelLocs);
10731 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10732 E->getSelector(),
10733 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010734 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010735 E->getMethodDecl(),
10736 E->getLeftLoc(),
10737 Args,
10738 E->getRightLoc());
10739 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010740
10741 // Instance message: transform the receiver
10742 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10743 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010744 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010745 = getDerived().TransformExpr(E->getInstanceReceiver());
10746 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010747 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010748
10749 // If nothing changed, just retain the existing message send.
10750 if (!getDerived().AlwaysRebuild() &&
10751 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010752 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010753
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010754 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010755 SmallVector<SourceLocation, 16> SelLocs;
10756 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010757 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010758 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010759 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010760 E->getMethodDecl(),
10761 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010762 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010763 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010764}
10765
Mike Stump11289f42009-09-09 15:08:12 +000010766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010767ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010768TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010769 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010770}
10771
Mike Stump11289f42009-09-09 15:08:12 +000010772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010774TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010775 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010776}
10777
Mike Stump11289f42009-09-09 15:08:12 +000010778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010780TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010781 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010782 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010783 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010784 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010785
10786 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010787
Douglas Gregord51d90d2010-04-26 20:11:03 +000010788 // If nothing changed, just retain the existing expression.
10789 if (!getDerived().AlwaysRebuild() &&
10790 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010791 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010792
John McCallb268a282010-08-23 23:25:46 +000010793 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010794 E->getLocation(),
10795 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010796}
10797
Mike Stump11289f42009-09-09 15:08:12 +000010798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010800TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010801 // 'super' and types never change. Property never changes. Just
10802 // retain the existing expression.
10803 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010804 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010805
Douglas Gregor9faee212010-04-26 20:47:02 +000010806 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010807 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010808 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010809 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010810
Douglas Gregor9faee212010-04-26 20:47:02 +000010811 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010812
Douglas Gregor9faee212010-04-26 20:47:02 +000010813 // If nothing changed, just retain the existing expression.
10814 if (!getDerived().AlwaysRebuild() &&
10815 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010816 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010817
John McCallb7bd14f2010-12-02 01:19:52 +000010818 if (E->isExplicitProperty())
10819 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10820 E->getExplicitProperty(),
10821 E->getLocation());
10822
10823 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010824 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010825 E->getImplicitPropertyGetter(),
10826 E->getImplicitPropertySetter(),
10827 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010828}
10829
Mike Stump11289f42009-09-09 15:08:12 +000010830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010831ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010832TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10833 // Transform the base expression.
10834 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10835 if (Base.isInvalid())
10836 return ExprError();
10837
10838 // Transform the key expression.
10839 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10840 if (Key.isInvalid())
10841 return ExprError();
10842
10843 // If nothing changed, just retain the existing expression.
10844 if (!getDerived().AlwaysRebuild() &&
10845 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010846 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010847
Chad Rosier1dcde962012-08-08 18:46:20 +000010848 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010849 Base.get(), Key.get(),
10850 E->getAtIndexMethodDecl(),
10851 E->setAtIndexMethodDecl());
10852}
10853
10854template<typename Derived>
10855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010856TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010857 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010858 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010859 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010860 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010861
Douglas Gregord51d90d2010-04-26 20:11:03 +000010862 // If nothing changed, just retain the existing expression.
10863 if (!getDerived().AlwaysRebuild() &&
10864 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010865 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010866
John McCallb268a282010-08-23 23:25:46 +000010867 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010868 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010869 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010870}
10871
Mike Stump11289f42009-09-09 15:08:12 +000010872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010874TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010875 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010876 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010877 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010878 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010879 SubExprs, &ArgumentChanged))
10880 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010881
Douglas Gregora16548e2009-08-11 05:31:07 +000010882 if (!getDerived().AlwaysRebuild() &&
10883 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010884 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010885
Douglas Gregora16548e2009-08-11 05:31:07 +000010886 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010887 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010888 E->getRParenLoc());
10889}
10890
Mike Stump11289f42009-09-09 15:08:12 +000010891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010892ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010893TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10894 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10895 if (SrcExpr.isInvalid())
10896 return ExprError();
10897
10898 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10899 if (!Type)
10900 return ExprError();
10901
10902 if (!getDerived().AlwaysRebuild() &&
10903 Type == E->getTypeSourceInfo() &&
10904 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010905 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010906
10907 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10908 SrcExpr.get(), Type,
10909 E->getRParenLoc());
10910}
10911
10912template<typename Derived>
10913ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010914TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010915 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010916
Craig Topperc3ec1492014-05-26 06:22:03 +000010917 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010918 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10919
10920 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010921 blockScope->TheDecl->setBlockMissingReturnType(
10922 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010923
Chris Lattner01cf8db2011-07-20 06:58:45 +000010924 SmallVector<ParmVarDecl*, 4> params;
10925 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010926
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010927 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010928 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10929 oldBlock->param_begin(),
10930 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010931 nullptr, paramTypes, &params)) {
10932 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010933 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010934 }
John McCall490112f2011-02-04 18:33:18 +000010935
Jordan Rosea0a86be2013-03-08 22:25:36 +000010936 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010937 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010938 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010939
Jordan Rose5c382722013-03-08 21:51:21 +000010940 QualType functionType =
10941 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010942 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010943 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010944
10945 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010946 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010947 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010948
10949 if (!oldBlock->blockMissingReturnType()) {
10950 blockScope->HasImplicitReturnType = false;
10951 blockScope->ReturnType = exprResultType;
10952 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010953
John McCall3882ace2011-01-05 12:14:39 +000010954 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010955 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010956 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010957 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010958 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010959 }
John McCall3882ace2011-01-05 12:14:39 +000010960
John McCall490112f2011-02-04 18:33:18 +000010961#ifndef NDEBUG
10962 // In builds with assertions, make sure that we captured everything we
10963 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010964 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010965 for (const auto &I : oldBlock->captures()) {
10966 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010967
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010968 // Ignore parameter packs.
10969 if (isa<ParmVarDecl>(oldCapture) &&
10970 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10971 continue;
John McCall490112f2011-02-04 18:33:18 +000010972
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010973 VarDecl *newCapture =
10974 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10975 oldCapture));
10976 assert(blockScope->CaptureMap.count(newCapture));
10977 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010978 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010979 }
10980#endif
10981
10982 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010983 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010984}
10985
Mike Stump11289f42009-09-09 15:08:12 +000010986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010987ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010988TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010989 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010990}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010991
10992template<typename Derived>
10993ExprResult
10994TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010995 QualType RetTy = getDerived().TransformType(E->getType());
10996 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010997 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010998 SubExprs.reserve(E->getNumSubExprs());
10999 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11000 SubExprs, &ArgumentChanged))
11001 return ExprError();
11002
11003 if (!getDerived().AlwaysRebuild() &&
11004 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011005 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011006
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011007 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011008 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011009}
Chad Rosier1dcde962012-08-08 18:46:20 +000011010
Douglas Gregora16548e2009-08-11 05:31:07 +000011011//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011012// Type reconstruction
11013//===----------------------------------------------------------------------===//
11014
Mike Stump11289f42009-09-09 15:08:12 +000011015template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011016QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11017 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011018 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011019 getDerived().getBaseEntity());
11020}
11021
Mike Stump11289f42009-09-09 15:08:12 +000011022template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011023QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11024 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011025 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011026 getDerived().getBaseEntity());
11027}
11028
Mike Stump11289f42009-09-09 15:08:12 +000011029template<typename Derived>
11030QualType
John McCall70dd5f62009-10-30 00:06:24 +000011031TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11032 bool WrittenAsLValue,
11033 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011034 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011035 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011036}
11037
11038template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011039QualType
John McCall70dd5f62009-10-30 00:06:24 +000011040TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11041 QualType ClassType,
11042 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011043 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11044 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011045}
11046
11047template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011048QualType TreeTransform<Derived>::RebuildObjCObjectType(
11049 QualType BaseType,
11050 SourceLocation Loc,
11051 SourceLocation TypeArgsLAngleLoc,
11052 ArrayRef<TypeSourceInfo *> TypeArgs,
11053 SourceLocation TypeArgsRAngleLoc,
11054 SourceLocation ProtocolLAngleLoc,
11055 ArrayRef<ObjCProtocolDecl *> Protocols,
11056 ArrayRef<SourceLocation> ProtocolLocs,
11057 SourceLocation ProtocolRAngleLoc) {
11058 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11059 TypeArgs, TypeArgsRAngleLoc,
11060 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11061 ProtocolRAngleLoc,
11062 /*FailOnError=*/true);
11063}
11064
11065template<typename Derived>
11066QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11067 QualType PointeeType,
11068 SourceLocation Star) {
11069 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11070}
11071
11072template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011073QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011074TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11075 ArrayType::ArraySizeModifier SizeMod,
11076 const llvm::APInt *Size,
11077 Expr *SizeExpr,
11078 unsigned IndexTypeQuals,
11079 SourceRange BracketsRange) {
11080 if (SizeExpr || !Size)
11081 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11082 IndexTypeQuals, BracketsRange,
11083 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011084
11085 QualType Types[] = {
11086 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11087 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11088 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011089 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011090 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011091 QualType SizeType;
11092 for (unsigned I = 0; I != NumTypes; ++I)
11093 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11094 SizeType = Types[I];
11095 break;
11096 }
Mike Stump11289f42009-09-09 15:08:12 +000011097
Eli Friedman9562f392012-01-25 23:20:27 +000011098 // Note that we can return a VariableArrayType here in the case where
11099 // the element type was a dependent VariableArrayType.
11100 IntegerLiteral *ArraySize
11101 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11102 /*FIXME*/BracketsRange.getBegin());
11103 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011104 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011105 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011106}
Mike Stump11289f42009-09-09 15:08:12 +000011107
Douglas Gregord6ff3322009-08-04 16:50:30 +000011108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011109QualType
11110TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011111 ArrayType::ArraySizeModifier SizeMod,
11112 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011113 unsigned IndexTypeQuals,
11114 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011115 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011116 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011117}
11118
11119template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011120QualType
Mike Stump11289f42009-09-09 15:08:12 +000011121TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011122 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011123 unsigned IndexTypeQuals,
11124 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011125 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011126 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011127}
Mike Stump11289f42009-09-09 15:08:12 +000011128
Douglas Gregord6ff3322009-08-04 16:50:30 +000011129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011130QualType
11131TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011132 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011133 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011134 unsigned IndexTypeQuals,
11135 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011136 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011137 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011138 IndexTypeQuals, BracketsRange);
11139}
11140
11141template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011142QualType
11143TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011144 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011145 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011146 unsigned IndexTypeQuals,
11147 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011148 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011149 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011150 IndexTypeQuals, BracketsRange);
11151}
11152
11153template<typename Derived>
11154QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011155 unsigned NumElements,
11156 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011157 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011158 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011159}
Mike Stump11289f42009-09-09 15:08:12 +000011160
Douglas Gregord6ff3322009-08-04 16:50:30 +000011161template<typename Derived>
11162QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11163 unsigned NumElements,
11164 SourceLocation AttributeLoc) {
11165 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11166 NumElements, true);
11167 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011168 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11169 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011170 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011171}
Mike Stump11289f42009-09-09 15:08:12 +000011172
Douglas Gregord6ff3322009-08-04 16:50:30 +000011173template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011174QualType
11175TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011176 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011177 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011178 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011179}
Mike Stump11289f42009-09-09 15:08:12 +000011180
Douglas Gregord6ff3322009-08-04 16:50:30 +000011181template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011182QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11183 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011184 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011185 const FunctionProtoType::ExtProtoInfo &EPI) {
11186 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011187 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011188 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011189 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011190}
Mike Stump11289f42009-09-09 15:08:12 +000011191
Douglas Gregord6ff3322009-08-04 16:50:30 +000011192template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011193QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11194 return SemaRef.Context.getFunctionNoProtoType(T);
11195}
11196
11197template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011198QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11199 assert(D && "no decl found");
11200 if (D->isInvalidDecl()) return QualType();
11201
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011202 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011203 TypeDecl *Ty;
11204 if (isa<UsingDecl>(D)) {
11205 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011206 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011207 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11208
11209 // A valid resolved using typename decl points to exactly one type decl.
11210 assert(++Using->shadow_begin() == Using->shadow_end());
11211 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011212
John McCallb96ec562009-12-04 22:46:56 +000011213 } else {
11214 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11215 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11216 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11217 }
11218
11219 return SemaRef.Context.getTypeDeclType(Ty);
11220}
11221
11222template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011223QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11224 SourceLocation Loc) {
11225 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011226}
11227
11228template<typename Derived>
11229QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11230 return SemaRef.Context.getTypeOfType(Underlying);
11231}
11232
11233template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011234QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11235 SourceLocation Loc) {
11236 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011237}
11238
11239template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011240QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11241 UnaryTransformType::UTTKind UKind,
11242 SourceLocation Loc) {
11243 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11244}
11245
11246template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011247QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011248 TemplateName Template,
11249 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011250 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011251 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011252}
Mike Stump11289f42009-09-09 15:08:12 +000011253
Douglas Gregor1135c352009-08-06 05:28:30 +000011254template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011255QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11256 SourceLocation KWLoc) {
11257 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11258}
11259
11260template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011261TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011262TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011263 bool TemplateKW,
11264 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011265 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011266 Template);
11267}
11268
11269template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011270TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011271TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11272 const IdentifierInfo &Name,
11273 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011274 QualType ObjectType,
11275 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011276 UnqualifiedId TemplateName;
11277 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011278 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011279 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011280 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011281 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011282 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011283 /*EnteringContext=*/false,
11284 Template);
John McCall31f82722010-11-12 08:19:04 +000011285 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011286}
Mike Stump11289f42009-09-09 15:08:12 +000011287
Douglas Gregora16548e2009-08-11 05:31:07 +000011288template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011289TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011290TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011291 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011292 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011293 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011294 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011295 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011296 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011297 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011298 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011299 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011300 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011301 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011302 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011303 /*EnteringContext=*/false,
11304 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011305 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011306}
Chad Rosier1dcde962012-08-08 18:46:20 +000011307
Douglas Gregor71395fa2009-11-04 00:56:37 +000011308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011309ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011310TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11311 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011312 Expr *OrigCallee,
11313 Expr *First,
11314 Expr *Second) {
11315 Expr *Callee = OrigCallee->IgnoreParenCasts();
11316 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011317
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011318 if (First->getObjectKind() == OK_ObjCProperty) {
11319 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11320 if (BinaryOperator::isAssignmentOp(Opc))
11321 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11322 First, Second);
11323 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11324 if (Result.isInvalid())
11325 return ExprError();
11326 First = Result.get();
11327 }
11328
11329 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11330 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11331 if (Result.isInvalid())
11332 return ExprError();
11333 Second = Result.get();
11334 }
11335
Douglas Gregora16548e2009-08-11 05:31:07 +000011336 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011337 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011338 if (!First->getType()->isOverloadableType() &&
11339 !Second->getType()->isOverloadableType())
11340 return getSema().CreateBuiltinArraySubscriptExpr(First,
11341 Callee->getLocStart(),
11342 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011343 } else if (Op == OO_Arrow) {
11344 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011345 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11346 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011347 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011348 // The argument is not of overloadable type, so try to create a
11349 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011350 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011351 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011352
John McCallb268a282010-08-23 23:25:46 +000011353 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011354 }
11355 } else {
John McCallb268a282010-08-23 23:25:46 +000011356 if (!First->getType()->isOverloadableType() &&
11357 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011358 // Neither of the arguments is an overloadable type, so try to
11359 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011360 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011361 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011362 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011363 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011365
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011366 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011367 }
11368 }
Mike Stump11289f42009-09-09 15:08:12 +000011369
11370 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011371 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011372 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011373
John McCallb268a282010-08-23 23:25:46 +000011374 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011375 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011376 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011377 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011378 // If we've resolved this to a particular non-member function, just call
11379 // that function. If we resolved it to a member function,
11380 // CreateOverloaded* will find that function for us.
11381 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11382 if (!isa<CXXMethodDecl>(ND))
11383 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011384 }
Mike Stump11289f42009-09-09 15:08:12 +000011385
Douglas Gregora16548e2009-08-11 05:31:07 +000011386 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011387 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011388 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011389
Douglas Gregora16548e2009-08-11 05:31:07 +000011390 // Create the overloaded operator invocation for unary operators.
11391 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011392 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011393 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011394 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011395 }
Mike Stump11289f42009-09-09 15:08:12 +000011396
Douglas Gregore9d62932011-07-15 16:25:15 +000011397 if (Op == OO_Subscript) {
11398 SourceLocation LBrace;
11399 SourceLocation RBrace;
11400
11401 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011402 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011403 LBrace = SourceLocation::getFromRawEncoding(
11404 NameLoc.CXXOperatorName.BeginOpNameLoc);
11405 RBrace = SourceLocation::getFromRawEncoding(
11406 NameLoc.CXXOperatorName.EndOpNameLoc);
11407 } else {
11408 LBrace = Callee->getLocStart();
11409 RBrace = OpLoc;
11410 }
11411
11412 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11413 First, Second);
11414 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011415
Douglas Gregora16548e2009-08-11 05:31:07 +000011416 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011417 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011418 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011419 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11420 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011422
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011423 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011424}
Mike Stump11289f42009-09-09 15:08:12 +000011425
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011426template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011427ExprResult
John McCallb268a282010-08-23 23:25:46 +000011428TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011429 SourceLocation OperatorLoc,
11430 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011431 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011432 TypeSourceInfo *ScopeType,
11433 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011434 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011435 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011436 QualType BaseType = Base->getType();
11437 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011438 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011439 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011440 !BaseType->getAs<PointerType>()->getPointeeType()
11441 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011442 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011443 return SemaRef.BuildPseudoDestructorExpr(
11444 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11445 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011446 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011447
Douglas Gregor678f90d2010-02-25 01:56:36 +000011448 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011449 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11450 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11451 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11452 NameInfo.setNamedTypeInfo(DestroyedType);
11453
Richard Smith8e4a3862012-05-15 06:15:11 +000011454 // The scope type is now known to be a valid nested name specifier
11455 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011456 if (ScopeType) {
11457 if (!ScopeType->getType()->getAs<TagType>()) {
11458 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11459 diag::err_expected_class_or_namespace)
11460 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11461 return ExprError();
11462 }
11463 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11464 CCLoc);
11465 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011466
Abramo Bagnara7945c982012-01-27 09:46:47 +000011467 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011468 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011469 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011470 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011471 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011472 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011473 /*TemplateArgs*/ nullptr,
11474 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011475}
11476
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011477template<typename Derived>
11478StmtResult
11479TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011480 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011481 CapturedDecl *CD = S->getCapturedDecl();
11482 unsigned NumParams = CD->getNumParams();
11483 unsigned ContextParamPos = CD->getContextParamPosition();
11484 SmallVector<Sema::CapturedParamNameType, 4> Params;
11485 for (unsigned I = 0; I < NumParams; ++I) {
11486 if (I != ContextParamPos) {
11487 Params.push_back(
11488 std::make_pair(
11489 CD->getParam(I)->getName(),
11490 getDerived().TransformType(CD->getParam(I)->getType())));
11491 } else {
11492 Params.push_back(std::make_pair(StringRef(), QualType()));
11493 }
11494 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011495 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011496 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011497 StmtResult Body;
11498 {
11499 Sema::CompoundScopeRAII CompoundScope(getSema());
11500 Body = getDerived().TransformStmt(S->getCapturedStmt());
11501 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011502
11503 if (Body.isInvalid()) {
11504 getSema().ActOnCapturedRegionError();
11505 return StmtError();
11506 }
11507
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011508 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011509}
11510
Douglas Gregord6ff3322009-08-04 16:50:30 +000011511} // end namespace clang
11512
Hans Wennborg59dbe862015-09-29 20:56:43 +000011513#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H