blob: a562bfd61676a2a0e93362ddebb507ecd5a0c637 [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
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
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"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000607
Richard Smithdb2630f2012-10-21 03:28:35 +0000608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000609 bool IsAddressOfOperand,
610 TypeSourceInfo **RecoveryTSI);
611
612 ExprResult TransformParenDependentScopeDeclRefExpr(
613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
614 TypeSourceInfo **RecoveryTSI);
615
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000616 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000617
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
619// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000620#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000622 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000623#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000625 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000626#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000627#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000628
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000629#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000630 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000631 OMPClause *Transform ## Class(Class *S);
632#include "clang/Basic/OpenMPKinds.def"
633
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 /// \brief Build a new pointer type given its pointee type.
635 ///
636 /// By default, performs semantic analysis when building the pointer type.
637 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
640 /// \brief Build a new block pointer type given its pointee type.
641 ///
Mike Stump11289f42009-09-09 15:08:12 +0000642 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000644 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000647 ///
John McCall70dd5f62009-10-30 00:06:24 +0000648 /// By default, performs semantic analysis when building the
649 /// reference type. Subclasses may override this routine to provide
650 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 ///
John McCall70dd5f62009-10-30 00:06:24 +0000652 /// \param LValue whether the type was written with an lvalue sigil
653 /// or an rvalue sigil.
654 QualType RebuildReferenceType(QualType ReferentType,
655 bool LValue,
656 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new member pointer type given the pointee type and the
659 /// class type it refers into.
660 ///
661 /// By default, performs semantic analysis when building the member pointer
662 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000663 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
664 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 /// \brief Build a new array type given the element type, size
667 /// modifier, size of the array (if known), size expression, and index type
668 /// qualifiers.
669 ///
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 QualType RebuildArrayType(QualType ElementType,
674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt *Size,
676 Expr *SizeExpr,
677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new constant array type given the element type, size
681 /// modifier, (known) size of the array, and index type qualifiers.
682 ///
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 ArrayType::ArraySizeModifier SizeMod,
687 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000688 unsigned IndexTypeQuals,
689 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 /// \brief Build a new incomplete array type given the element type, size
692 /// modifier, and index type qualifiers.
693 ///
694 /// By default, performs semantic analysis when building the array type.
695 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000696 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700
Mike Stump11289f42009-09-09 15:08:12 +0000701 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// size modifier, size expression, and index type qualifiers.
703 ///
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000706 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
711
Mike Stump11289f42009-09-09 15:08:12 +0000712 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// size modifier, size expression, and index type qualifiers.
714 ///
715 /// By default, performs semantic analysis when building the array type.
716 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000717 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000719 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
722
723 /// \brief Build a new vector type given the element type and
724 /// number of elements.
725 ///
726 /// By default, performs semantic analysis when building the vector type.
727 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000728 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000729 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// \brief Build a new extended vector type given the element type and
732 /// number of elements.
733 ///
734 /// By default, performs semantic analysis when building the vector type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
737 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000738
739 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// given the element type and number of elements.
741 ///
742 /// By default, performs semantic analysis when building the vector type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000745 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new function type.
749 ///
750 /// By default, performs semantic analysis when building the function type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000753 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000754 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000755
John McCall550e0c22009-10-21 00:40:46 +0000756 /// \brief Build a new unprototyped function type.
757 QualType RebuildFunctionNoProtoType(QualType ResultType);
758
John McCallb96ec562009-12-04 22:46:56 +0000759 /// \brief Rebuild an unresolved typename type, given the decl that
760 /// the UnresolvedUsingTypenameDecl was transformed to.
761 QualType RebuildUnresolvedUsingType(Decl *D);
762
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000764 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 return SemaRef.Context.getTypeDeclType(Typedef);
766 }
767
768 /// \brief Build a new class/struct/union type.
769 QualType RebuildRecordType(RecordDecl *Record) {
770 return SemaRef.Context.getTypeDeclType(Record);
771 }
772
773 /// \brief Build a new Enum type.
774 QualType RebuildEnumType(EnumDecl *Enum) {
775 return SemaRef.Context.getTypeDeclType(Enum);
776 }
John McCallfcc33b02009-09-05 00:15:47 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, performs semantic analysis when building the typeof type.
781 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000782 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783
Mike Stump11289f42009-09-09 15:08:12 +0000784 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 ///
786 /// By default, builds a new TypeOfType with the given underlying type.
787 QualType RebuildTypeOfType(QualType Underlying);
788
Alexis Hunte852b102011-05-24 22:41:36 +0000789 /// \brief Build a new unary transform type.
790 QualType RebuildUnaryTransformType(QualType BaseType,
791 UnaryTransformType::UTTKind UKind,
792 SourceLocation Loc);
793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 ///
796 /// By default, performs semantic analysis when building the decltype type.
797 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000798 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000799
Richard Smith74aeef52013-04-26 16:15:35 +0000800 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000801 ///
802 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000803 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000804 // Note, IsDependent is always false here: we implicitly convert an 'auto'
805 // which has been deduced to a dependent type into an undeduced 'auto', so
806 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000807 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
808 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000809 }
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new template specialization type.
812 ///
813 /// By default, performs semantic analysis when building the template
814 /// specialization type. Subclasses may override this routine to provide
815 /// different behavior.
816 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000817 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000818 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000819
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000820 /// \brief Build a new parenthesized type.
821 ///
822 /// By default, builds a new ParenType type from the inner type.
823 /// Subclasses may override this routine to provide different behavior.
824 QualType RebuildParenType(QualType InnerType) {
825 return SemaRef.Context.getParenType(InnerType);
826 }
827
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 /// \brief Build a new qualified name type.
829 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000830 /// By default, builds a new ElaboratedType type from the keyword,
831 /// the nested-name-specifier and the named type.
832 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000833 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
834 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000835 NestedNameSpecifierLoc QualifierLoc,
836 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000837 return SemaRef.Context.getElaboratedType(Keyword,
838 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000839 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000840 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000841
842 /// \brief Build a new typename type that refers to a template-id.
843 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000844 /// By default, builds a new DependentNameType type from the
845 /// nested-name-specifier and the given type. Subclasses may override
846 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000847 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000848 ElaboratedTypeKeyword Keyword,
849 NestedNameSpecifierLoc QualifierLoc,
850 const IdentifierInfo *Name,
851 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000852 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000853 // Rebuild the template name.
854 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000855 CXXScopeSpec SS;
856 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000857 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000858 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
859 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000860
Douglas Gregora7a795b2011-03-01 20:11:18 +0000861 if (InstName.isNull())
862 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // If it's still dependent, make a dependent specialization.
865 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000866 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
867 QualifierLoc.getNestedNameSpecifier(),
868 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000869 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000870
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 // Otherwise, make an elaborated type wrapping a non-dependent
872 // specialization.
873 QualType T =
874 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
875 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000876
Craig Topperc3ec1492014-05-26 06:22:03 +0000877 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000878 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000879
880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000882 T);
883 }
884
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 /// \brief Build a new typename type that refers to an identifier.
886 ///
887 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000888 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000891 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000892 NestedNameSpecifierLoc QualifierLoc,
893 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000894 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000895 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000897
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000898 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000899 // If the name is still dependent, just build a new dependent name type.
900 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000901 return SemaRef.Context.getDependentNameType(Keyword,
902 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000903 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000904 }
905
Abramo Bagnara6150c882010-05-11 21:36:43 +0000906 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000907 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000908 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000909
910 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
911
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000913 // into a non-dependent elaborated-type-specifier. Find the tag we're
914 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000915 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
917 if (!DC)
918 return QualType();
919
John McCallbf8c5192010-05-27 06:40:31 +0000920 if (SemaRef.RequireCompleteDeclContext(SS, DC))
921 return QualType();
922
Craig Topperc3ec1492014-05-26 06:22:03 +0000923 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000924 SemaRef.LookupQualifiedName(Result, DC);
925 switch (Result.getResultKind()) {
926 case LookupResult::NotFound:
927 case LookupResult::NotFoundInCurrentInstantiation:
928 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000929
Douglas Gregore677daf2010-03-31 22:19:08 +0000930 case LookupResult::Found:
931 Tag = Result.getAsSingle<TagDecl>();
932 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Douglas Gregore677daf2010-03-31 22:19:08 +0000934 case LookupResult::FoundOverloaded:
935 case LookupResult::FoundUnresolvedValue:
936 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000937
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 case LookupResult::Ambiguous:
939 // Let the LookupResult structure handle ambiguities.
940 return QualType();
941 }
942
943 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000944 // Check where the name exists but isn't a tag type and use that to emit
945 // better diagnostics.
946 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
947 SemaRef.LookupQualifiedName(Result, DC);
948 switch (Result.getResultKind()) {
949 case LookupResult::Found:
950 case LookupResult::FoundOverloaded:
951 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000952 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000953 unsigned Kind = 0;
954 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000955 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
956 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
958 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
959 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000960 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000961 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000962 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000963 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000964 break;
965 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 return QualType();
967 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000968
Richard Trieucaa33d32011-06-10 03:11:26 +0000969 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
970 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000971 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
973 return QualType();
974 }
975
976 // Build the elaborated-type-specifier type.
977 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000978 return SemaRef.Context.getElaboratedType(Keyword,
979 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000980 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregor822d0302011-01-12 17:07:58 +0000983 /// \brief Build a new pack expansion type.
984 ///
985 /// By default, builds a new PackExpansionType type from the given pattern.
986 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000987 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000988 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000989 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000990 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000991 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
992 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000993 }
994
Eli Friedman0dfb8892011-10-06 23:00:33 +0000995 /// \brief Build a new atomic type given its value type.
996 ///
997 /// By default, performs semantic analysis when building the atomic type.
998 /// Subclasses may override this routine to provide different behavior.
999 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1000
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 /// \brief Build a new template name given a nested name specifier, a flag
1002 /// indicating whether the "template" keyword was provided, and the template
1003 /// that the template name refers to.
1004 ///
1005 /// By default, builds the new template name directly. Subclasses may override
1006 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001007 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001008 bool TemplateKW,
1009 TemplateDecl *Template);
1010
Douglas Gregor71dc5092009-08-06 06:41:21 +00001011 /// \brief Build a new template name given a nested name specifier and the
1012 /// name that is referred to as a template.
1013 ///
1014 /// By default, performs semantic analysis to determine whether the name can
1015 /// be resolved to a specific template, then builds the appropriate kind of
1016 /// template name. Subclasses may override this routine to provide different
1017 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001018 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1019 const IdentifierInfo &Name,
1020 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001021 QualType ObjectType,
1022 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001023
Douglas Gregor71395fa2009-11-04 00:56:37 +00001024 /// \brief Build a new template name given a nested name specifier and the
1025 /// overloaded operator name that is referred to as a template.
1026 ///
1027 /// By default, performs semantic analysis to determine whether the name can
1028 /// be resolved to a specific template, then builds the appropriate kind of
1029 /// template name. Subclasses may override this routine to provide different
1030 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001031 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001032 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001033 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001034 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001035
1036 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001037 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001038 ///
1039 /// By default, performs semantic analysis to determine whether the name can
1040 /// be resolved to a specific template, then builds the appropriate kind of
1041 /// template name. Subclasses may override this routine to provide different
1042 /// behavior.
1043 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1044 const TemplateArgument &ArgPack) {
1045 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1046 }
1047
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 /// \brief Build a new compound statement.
1049 ///
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001052 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 MultiStmtArg Statements,
1054 SourceLocation RBraceLoc,
1055 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001056 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001057 IsStmtExpr);
1058 }
1059
1060 /// \brief Build a new case statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001064 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001065 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001067 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001069 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 ColonLoc);
1071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 /// \brief Attach the body to a new case statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001078 getSema().ActOnCaseStmtBody(S, Body);
1079 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /// \brief Build a new default statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001088 Stmt *SubStmt) {
1089 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001090 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 /// \brief Build a new label statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001097 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1098 SourceLocation ColonLoc, Stmt *SubStmt) {
1099 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Richard Smithc202b282012-04-14 00:33:13 +00001102 /// \brief Build a new label statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001106 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1107 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001108 Stmt *SubStmt) {
1109 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1110 }
1111
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 /// \brief Build a new "if" statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001117 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001118 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001119 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 /// \brief Start building a new switch statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001126 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001127 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001128 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001129 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Attach the body to the switch statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001137 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new while 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 RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1146 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001147 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 /// \brief Build a new do-while statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001154 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001155 SourceLocation WhileLoc, SourceLocation LParenLoc,
1156 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001157 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1158 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 }
1160
1161 /// \brief Build a new for statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001165 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001166 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001167 VarDecl *CondVar, Sema::FullExprArg Inc,
1168 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001169 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 /// \brief Build a new goto statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1178 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001179 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 }
1181
1182 /// \brief Build a new indirect goto statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001186 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 SourceLocation StarLoc,
1188 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Build a new return statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001196 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001197 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new declaration statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001204 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001205 SourceLocation StartLoc, SourceLocation EndLoc) {
1206 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001207 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Anders Carlssonaaeef072010-01-24 05:50:09 +00001210 /// \brief Build a new inline asm statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001214 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1215 bool IsVolatile, unsigned NumOutputs,
1216 unsigned NumInputs, IdentifierInfo **Names,
1217 MultiExprArg Constraints, MultiExprArg Exprs,
1218 Expr *AsmString, MultiExprArg Clobbers,
1219 SourceLocation RParenLoc) {
1220 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1221 NumInputs, Names, Constraints, Exprs,
1222 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001223 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001224
Chad Rosier32503022012-06-11 20:47:18 +00001225 /// \brief Build a new MS style inline asm statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001229 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001230 ArrayRef<Token> AsmToks,
1231 StringRef AsmString,
1232 unsigned NumOutputs, unsigned NumInputs,
1233 ArrayRef<StringRef> Constraints,
1234 ArrayRef<StringRef> Clobbers,
1235 ArrayRef<Expr*> Exprs,
1236 SourceLocation EndLoc) {
1237 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1238 NumOutputs, NumInputs,
1239 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001240 }
1241
James Dennett2a4d13c2012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001247 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001248 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001249 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001250 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001251 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001252 }
1253
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001254 /// \brief Rebuild an Objective-C exception declaration.
1255 ///
1256 /// By default, performs semantic analysis to build the new declaration.
1257 /// Subclasses may override this routine to provide different behavior.
1258 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1259 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001260 return getSema().BuildObjCExceptionDecl(TInfo, T,
1261 ExceptionDecl->getInnerLocStart(),
1262 ExceptionDecl->getLocation(),
1263 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001265
James Dennett2a4d13c2012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001271 SourceLocation RParenLoc,
1272 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001273 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001274 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001275 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001277
James Dennett2a4d13c2012-06-15 07:13:21 +00001278 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001282 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001283 Stmt *Body) {
1284 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001286
James Dennett2a4d13c2012-06-15 07:13:21 +00001287 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 ///
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001292 Expr *Operand) {
1293 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001295
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001296 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001300 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1301 ArrayRef<OMPClause *> Clauses,
1302 Stmt *AStmt,
1303 SourceLocation StartLoc,
1304 SourceLocation EndLoc) {
1305 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1306 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001307 }
1308
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309 /// \brief Build a new OpenMP 'if' clause.
1310 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001311 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1318 LParenLoc, EndLoc);
1319 }
1320
Alexey Bataev3778b602014-07-17 07:32:53 +00001321 /// \brief Build a new OpenMP 'final' clause.
1322 ///
1323 /// By default, performs semantic analysis to build the new OpenMP clause.
1324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1326 SourceLocation LParenLoc,
1327 SourceLocation EndLoc) {
1328 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1329 EndLoc);
1330 }
1331
Alexey Bataev568a8332014-03-06 06:15:19 +00001332 /// \brief Build a new OpenMP 'num_threads' clause.
1333 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001334 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001335 /// Subclasses may override this routine to provide different behavior.
1336 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1341 LParenLoc, EndLoc);
1342 }
1343
Alexey Bataev62c87d22014-03-21 04:51:18 +00001344 /// \brief Build a new OpenMP 'safelen' clause.
1345 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001346 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001347 /// Subclasses may override this routine to provide different behavior.
1348 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc) {
1351 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1352 }
1353
Alexander Musman8bd31e62014-05-27 15:12:19 +00001354 /// \brief Build a new OpenMP 'collapse' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1359 SourceLocation LParenLoc,
1360 SourceLocation EndLoc) {
1361 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1362 EndLoc);
1363 }
1364
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001365 /// \brief Build a new OpenMP 'default' clause.
1366 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001367 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001368 /// Subclasses may override this routine to provide different behavior.
1369 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1370 SourceLocation KindKwLoc,
1371 SourceLocation StartLoc,
1372 SourceLocation LParenLoc,
1373 SourceLocation EndLoc) {
1374 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1375 StartLoc, LParenLoc, EndLoc);
1376 }
1377
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001378 /// \brief Build a new OpenMP 'proc_bind' clause.
1379 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001380 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001381 /// Subclasses may override this routine to provide different behavior.
1382 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1383 SourceLocation KindKwLoc,
1384 SourceLocation StartLoc,
1385 SourceLocation LParenLoc,
1386 SourceLocation EndLoc) {
1387 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1388 StartLoc, LParenLoc, EndLoc);
1389 }
1390
Alexey Bataev56dafe82014-06-20 07:16:17 +00001391 /// \brief Build a new OpenMP 'schedule' clause.
1392 ///
1393 /// By default, performs semantic analysis to build the new OpenMP clause.
1394 /// Subclasses may override this routine to provide different behavior.
1395 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1396 Expr *ChunkSize,
1397 SourceLocation StartLoc,
1398 SourceLocation LParenLoc,
1399 SourceLocation KindLoc,
1400 SourceLocation CommaLoc,
1401 SourceLocation EndLoc) {
1402 return getSema().ActOnOpenMPScheduleClause(
1403 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1404 }
1405
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001406 /// \brief Build a new OpenMP 'private' clause.
1407 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001408 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1411 SourceLocation StartLoc,
1412 SourceLocation LParenLoc,
1413 SourceLocation EndLoc) {
1414 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1415 EndLoc);
1416 }
1417
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001418 /// \brief Build a new OpenMP 'firstprivate' clause.
1419 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001420 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1423 SourceLocation StartLoc,
1424 SourceLocation LParenLoc,
1425 SourceLocation EndLoc) {
1426 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1427 EndLoc);
1428 }
1429
Alexander Musman1bb328c2014-06-04 13:06:39 +00001430 /// \brief Build a new OpenMP 'lastprivate' 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 *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1435 SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 SourceLocation EndLoc) {
1438 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1439 EndLoc);
1440 }
1441
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001442 /// \brief Build a new OpenMP 'shared' clause.
1443 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001444 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001445 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001446 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1447 SourceLocation StartLoc,
1448 SourceLocation LParenLoc,
1449 SourceLocation EndLoc) {
1450 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1451 EndLoc);
1452 }
1453
Alexey Bataevc5e02582014-06-16 07:08:35 +00001454 /// \brief Build a new OpenMP 'reduction' clause.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1458 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation ColonLoc,
1462 SourceLocation EndLoc,
1463 CXXScopeSpec &ReductionIdScopeSpec,
1464 const DeclarationNameInfo &ReductionId) {
1465 return getSema().ActOnOpenMPReductionClause(
1466 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1467 ReductionId);
1468 }
1469
Alexander Musman8dba6642014-04-22 13:09:42 +00001470 /// \brief Build a new OpenMP 'linear' clause.
1471 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001472 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001473 /// Subclasses may override this routine to provide different behavior.
1474 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1475 SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation ColonLoc,
1478 SourceLocation EndLoc) {
1479 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1480 ColonLoc, EndLoc);
1481 }
1482
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001483 /// \brief Build a new OpenMP 'aligned' clause.
1484 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001485 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001486 /// Subclasses may override this routine to provide different behavior.
1487 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1488 SourceLocation StartLoc,
1489 SourceLocation LParenLoc,
1490 SourceLocation ColonLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1493 LParenLoc, ColonLoc, EndLoc);
1494 }
1495
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001496 /// \brief Build a new OpenMP 'copyin' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataevbae9a792014-06-27 10:37:06 +00001508 /// \brief Build a new OpenMP 'copyprivate' clause.
1509 ///
1510 /// By default, performs semantic analysis to build the new OpenMP clause.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1517 EndLoc);
1518 }
1519
James Dennett2a4d13c2012-06-15 07:13:21 +00001520 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001521 ///
1522 /// By default, performs semantic analysis to build the new statement.
1523 /// Subclasses may override this routine to provide different behavior.
1524 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1525 Expr *object) {
1526 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1527 }
1528
James Dennett2a4d13c2012-06-15 07:13:21 +00001529 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001530 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001531 /// By default, performs semantic analysis to build the new statement.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001534 Expr *Object, Stmt *Body) {
1535 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001536 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001537
James Dennett2a4d13c2012-06-15 07:13:21 +00001538 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001539 ///
1540 /// By default, performs semantic analysis to build the new statement.
1541 /// Subclasses may override this routine to provide different behavior.
1542 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1543 Stmt *Body) {
1544 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1545 }
John McCall53848232011-07-27 01:07:15 +00001546
Douglas Gregorf68a5082010-04-22 23:10:45 +00001547 /// \brief Build a new Objective-C fast enumeration statement.
1548 ///
1549 /// By default, performs semantic analysis to build the new statement.
1550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001551 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001552 Stmt *Element,
1553 Expr *Collection,
1554 SourceLocation RParenLoc,
1555 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001556 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001557 Element,
John McCallb268a282010-08-23 23:25:46 +00001558 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001559 RParenLoc);
1560 if (ForEachStmt.isInvalid())
1561 return StmtError();
1562
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001563 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001565
Douglas Gregorebe10102009-08-20 07:17:43 +00001566 /// \brief Build a new C++ exception declaration.
1567 ///
1568 /// By default, performs semantic analysis to build the new decaration.
1569 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001570 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001571 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001572 SourceLocation StartLoc,
1573 SourceLocation IdLoc,
1574 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001575 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001576 StartLoc, IdLoc, Id);
1577 if (Var)
1578 getSema().CurContext->addDecl(Var);
1579 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001580 }
1581
1582 /// \brief Build a new C++ catch statement.
1583 ///
1584 /// By default, performs semantic analysis to build the new statement.
1585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001586 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001587 VarDecl *ExceptionDecl,
1588 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001589 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1590 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregorebe10102009-08-20 07:17:43 +00001593 /// \brief Build a new C++ try statement.
1594 ///
1595 /// By default, performs semantic analysis to build the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001597 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1598 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001599 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001600 }
Mike Stump11289f42009-09-09 15:08:12 +00001601
Richard Smith02e85f32011-04-14 22:09:26 +00001602 /// \brief Build a new C++0x range-based for statement.
1603 ///
1604 /// By default, performs semantic analysis to build the new statement.
1605 /// Subclasses may override this routine to provide different behavior.
1606 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1607 SourceLocation ColonLoc,
1608 Stmt *Range, Stmt *BeginEnd,
1609 Expr *Cond, Expr *Inc,
1610 Stmt *LoopVar,
1611 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001612 // If we've just learned that the range is actually an Objective-C
1613 // collection, treat this as an Objective-C fast enumeration loop.
1614 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1615 if (RangeStmt->isSingleDecl()) {
1616 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001617 if (RangeVar->isInvalidDecl())
1618 return StmtError();
1619
Douglas Gregorf7106af2013-04-08 18:40:13 +00001620 Expr *RangeExpr = RangeVar->getInit();
1621 if (!RangeExpr->isTypeDependent() &&
1622 RangeExpr->getType()->isObjCObjectPointerType())
1623 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1624 RParenLoc);
1625 }
1626 }
1627 }
1628
Richard Smith02e85f32011-04-14 22:09:26 +00001629 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001630 Cond, Inc, LoopVar, RParenLoc,
1631 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001632 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001633
1634 /// \brief Build a new C++0x range-based for statement.
1635 ///
1636 /// By default, performs semantic analysis to build the new statement.
1637 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001638 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001639 bool IsIfExists,
1640 NestedNameSpecifierLoc QualifierLoc,
1641 DeclarationNameInfo NameInfo,
1642 Stmt *Nested) {
1643 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1644 QualifierLoc, NameInfo, Nested);
1645 }
1646
Richard Smith02e85f32011-04-14 22:09:26 +00001647 /// \brief Attach body to a C++0x range-based for statement.
1648 ///
1649 /// By default, performs semantic analysis to finish the new statement.
1650 /// Subclasses may override this routine to provide different behavior.
1651 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1652 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001654
David Majnemerfad8f482013-10-15 09:33:02 +00001655 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1656 Stmt *TryBlock, Stmt *Handler) {
1657 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001658 }
1659
David Majnemerfad8f482013-10-15 09:33:02 +00001660 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001661 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001662 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001663 }
1664
David Majnemerfad8f482013-10-15 09:33:02 +00001665 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1666 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001667 }
1668
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 /// \brief Build a new expression that references a declaration.
1670 ///
1671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001673 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001674 LookupResult &R,
1675 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001676 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1677 }
1678
1679
1680 /// \brief Build a new expression that references a declaration.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001684 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001685 ValueDecl *VD,
1686 const DeclarationNameInfo &NameInfo,
1687 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001688 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001689 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001690
1691 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001692
1693 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 }
Mike Stump11289f42009-09-09 15:08:12 +00001695
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001697 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001702 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
1704
Douglas Gregorad8a3362009-09-04 17:36:40 +00001705 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001706 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001709 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001710 SourceLocation OperatorLoc,
1711 bool isArrow,
1712 CXXScopeSpec &SS,
1713 TypeSourceInfo *ScopeType,
1714 SourceLocation CCLoc,
1715 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001716 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001717
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001719 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001722 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001723 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001724 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001725 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 }
Mike Stump11289f42009-09-09 15:08:12 +00001727
Douglas Gregor882211c2010-04-28 22:16:22 +00001728 /// \brief Build a new builtin offsetof expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001732 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001733 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001734 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001735 unsigned NumComponents,
1736 SourceLocation RParenLoc) {
1737 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1738 NumComponents, RParenLoc);
1739 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001740
1741 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001742 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001743 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001746 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1747 SourceLocation OpLoc,
1748 UnaryExprOrTypeTrait ExprKind,
1749 SourceRange R) {
1750 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
1752
Peter Collingbournee190dee2011-03-11 19:24:49 +00001753 /// \brief Build a new sizeof, alignof or vec step expression with an
1754 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001755 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001758 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1759 UnaryExprOrTypeTrait ExprKind,
1760 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001762 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001765
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001766 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 }
Mike Stump11289f42009-09-09 15:08:12 +00001768
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001770 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001775 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001777 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001778 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 RBracketLoc);
1780 }
1781
1782 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001783 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001788 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001789 Expr *ExecConfig = nullptr) {
1790 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001791 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001795 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001799 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001800 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001801 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001802 const DeclarationNameInfo &MemberNameInfo,
1803 ValueDecl *Member,
1804 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001805 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001806 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001807 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1808 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001809 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001810 // We have a reference to an unnamed field. This is always the
1811 // base of an anonymous struct/union member access, i.e. the
1812 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001813 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001814 assert(Member->getType()->isRecordType() &&
1815 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001816
Richard Smithcab9a7d2011-10-26 19:06:56 +00001817 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001818 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001819 QualifierLoc.getNestedNameSpecifier(),
1820 FoundDecl, Member);
1821 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001822 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001823 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001824 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001825 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001826 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001827 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001828 cast<FieldDecl>(Member)->getType(),
1829 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001830 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001831 }
Mike Stump11289f42009-09-09 15:08:12 +00001832
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001833 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001834 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001835
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001836 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001837 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001838
John McCall16df1e52010-03-30 21:47:33 +00001839 // FIXME: this involves duplicating earlier analysis in a lot of
1840 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001841 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001842 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001843 R.resolveKind();
1844
John McCallb268a282010-08-23 23:25:46 +00001845 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001846 SS, TemplateKWLoc,
1847 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001848 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001856 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001857 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001858 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 }
1860
1861 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001862 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001865 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001866 SourceLocation QuestionLoc,
1867 Expr *LHS,
1868 SourceLocation ColonLoc,
1869 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001870 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1871 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 }
1873
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001875 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001879 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001881 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001882 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001883 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 }
Mike Stump11289f42009-09-09 15:08:12 +00001885
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001887 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001891 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001893 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001894 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001895 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 }
Mike Stump11289f42009-09-09 15:08:12 +00001897
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001899 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001902 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 SourceLocation OpLoc,
1904 SourceLocation AccessorLoc,
1905 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001906
John McCall10eae182009-11-30 22:42:35 +00001907 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001908 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001909 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001910 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001911 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001912 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001913 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001914 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 }
Mike Stump11289f42009-09-09 15:08:12 +00001916
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001918 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001921 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001922 MultiExprArg Inits,
1923 SourceLocation RBraceLoc,
1924 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001925 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001926 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001927 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001928 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001929
Douglas Gregord3d93062009-11-09 17:16:50 +00001930 // Patch in the result type we were given, which may have been computed
1931 // when the initial InitListExpr was built.
1932 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1933 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001934 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001938 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 MultiExprArg ArrayExprs,
1943 SourceLocation EqualOrColonLoc,
1944 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001945 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001948 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001951
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001952 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 }
Mike Stump11289f42009-09-09 15:08:12 +00001954
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001956 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 /// By default, builds the implicit value initialization without performing
1958 /// any semantic analysis. Subclasses may override this routine to provide
1959 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001960 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001961 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 }
Mike Stump11289f42009-09-09 15:08:12 +00001963
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001965 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001969 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001970 SourceLocation RParenLoc) {
1971 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001972 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001973 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
1975
1976 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001977 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001981 MultiExprArg SubExprs,
1982 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001983 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 }
Mike Stump11289f42009-09-09 15:08:12 +00001985
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001987 ///
1988 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 /// rather than attempting to map the label statement itself.
1990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001991 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001992 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001993 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002000 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002001 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002003 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 }
Mike Stump11289f42009-09-09 15:08:12 +00002005
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// \brief Build a new __builtin_choose_expr expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002011 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 SourceLocation RParenLoc) {
2013 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002014 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 RParenLoc);
2016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Peter Collingbourne91147592011-04-15 00:35:48 +00002018 /// \brief Build a new generic selection expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
2022 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2023 SourceLocation DefaultLoc,
2024 SourceLocation RParenLoc,
2025 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002026 ArrayRef<TypeSourceInfo *> Types,
2027 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002028 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002029 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002030 }
2031
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// \brief Build a new overloaded operator call expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// The semantic analysis provides the behavior of template instantiation,
2036 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002037 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 /// argument-dependent lookup, etc. Subclasses may override this routine to
2039 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *Callee,
2043 Expr *First,
2044 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002045
2046 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// reinterpret_cast.
2048 ///
2049 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002050 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 Stmt::StmtClass Class,
2054 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002055 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 SourceLocation RAngleLoc,
2057 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002058 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 SourceLocation RParenLoc) {
2060 switch (Class) {
2061 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002062 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002063 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002064 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002065
2066 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002067 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002068 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002070
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002072 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002073 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002074 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002076
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002078 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002079 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002080 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002083 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 }
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new C++ static_cast expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002093 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 SourceLocation RAngleLoc,
2095 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002096 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002098 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002099 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002100 SourceRange(LAngleLoc, RAngleLoc),
2101 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 }
2103
2104 /// \brief Build a new C++ dynamic_cast expression.
2105 ///
2106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002108 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002110 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 SourceLocation RAngleLoc,
2112 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002113 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002115 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002116 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002117 SourceRange(LAngleLoc, RAngleLoc),
2118 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 }
2120
2121 /// \brief Build a new C++ reinterpret_cast expression.
2122 ///
2123 /// By default, performs semantic analysis to build the new expression.
2124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002125 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002127 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 SourceLocation RAngleLoc,
2129 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002130 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002132 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002133 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002134 SourceRange(LAngleLoc, RAngleLoc),
2135 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 }
2137
2138 /// \brief Build a new C++ const_cast expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002144 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 SourceLocation RAngleLoc,
2146 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002147 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002149 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002150 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002151 SourceRange(LAngleLoc, RAngleLoc),
2152 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 }
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// \brief Build a new C++ functional-style cast expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002159 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2160 SourceLocation LParenLoc,
2161 Expr *Sub,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002164 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 RParenLoc);
2166 }
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 /// \brief Build a new C++ typeid(type) expression.
2169 ///
2170 /// By default, performs semantic analysis to build the new expression.
2171 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002172 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002173 SourceLocation TypeidLoc,
2174 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002176 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002177 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 }
Mike Stump11289f42009-09-09 15:08:12 +00002179
Francois Pichet9f4f2072010-09-08 12:20:18 +00002180
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 /// \brief Build a new C++ typeid(expr) expression.
2182 ///
2183 /// 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 RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002186 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002187 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002189 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002190 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002191 }
2192
Francois Pichet9f4f2072010-09-08 12:20:18 +00002193 /// \brief Build a new C++ __uuidof(type) expression.
2194 ///
2195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
2197 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2198 SourceLocation TypeidLoc,
2199 TypeSourceInfo *Operand,
2200 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002201 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002202 RParenLoc);
2203 }
2204
2205 /// \brief Build a new C++ __uuidof(expr) expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
2209 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2210 SourceLocation TypeidLoc,
2211 Expr *Operand,
2212 SourceLocation RParenLoc) {
2213 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2214 RParenLoc);
2215 }
2216
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 /// \brief Build a new C++ "this" expression.
2218 ///
2219 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002220 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002222 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002223 QualType ThisType,
2224 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002225 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002226 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 }
2228
2229 /// \brief Build a new C++ throw expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002233 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2234 bool IsThrownVariableInScope) {
2235 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 }
2237
2238 /// \brief Build a new C++ default-argument expression.
2239 ///
2240 /// By default, builds a new default-argument expression, which does not
2241 /// require any semantic analysis. Subclasses may override this routine to
2242 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002243 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002244 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002245 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 }
2247
Richard Smith852c9db2013-04-20 22:23:05 +00002248 /// \brief Build a new C++11 default-initialization expression.
2249 ///
2250 /// By default, builds a new default field initialization expression, which
2251 /// does not require any semantic analysis. Subclasses may override this
2252 /// routine to provide different behavior.
2253 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2254 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002255 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002256 }
2257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ zero-initialization expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002262 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2263 SourceLocation LParenLoc,
2264 SourceLocation RParenLoc) {
2265 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002266 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 }
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// \brief Build a new C++ "new" expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002273 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002274 bool UseGlobal,
2275 SourceLocation PlacementLParen,
2276 MultiExprArg PlacementArgs,
2277 SourceLocation PlacementRParen,
2278 SourceRange TypeIdParens,
2279 QualType AllocatedType,
2280 TypeSourceInfo *AllocatedTypeInfo,
2281 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002282 SourceRange DirectInitRange,
2283 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002284 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002286 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002288 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002289 AllocatedType,
2290 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002291 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002292 DirectInitRange,
2293 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 }
Mike Stump11289f42009-09-09 15:08:12 +00002295
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 /// \brief Build a new C++ "delete" expression.
2297 ///
2298 /// By default, performs semantic analysis to build the new expression.
2299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002300 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 bool IsGlobalDelete,
2302 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002303 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002305 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 }
Mike Stump11289f42009-09-09 15:08:12 +00002307
Douglas Gregor29c42f22012-02-24 07:38:34 +00002308 /// \brief Build a new type trait expression.
2309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
2312 ExprResult RebuildTypeTrait(TypeTrait Trait,
2313 SourceLocation StartLoc,
2314 ArrayRef<TypeSourceInfo *> Args,
2315 SourceLocation RParenLoc) {
2316 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2317 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002318
John Wiegley6242b6a2011-04-28 00:16:57 +00002319 /// \brief Build a new array type trait expression.
2320 ///
2321 /// By default, performs semantic analysis to build the new expression.
2322 /// Subclasses may override this routine to provide different behavior.
2323 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2324 SourceLocation StartLoc,
2325 TypeSourceInfo *TSInfo,
2326 Expr *DimExpr,
2327 SourceLocation RParenLoc) {
2328 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2329 }
2330
John Wiegleyf9f65842011-04-25 06:54:41 +00002331 /// \brief Build a new expression trait expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2336 SourceLocation StartLoc,
2337 Expr *Queried,
2338 SourceLocation RParenLoc) {
2339 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2340 }
2341
Mike Stump11289f42009-09-09 15:08:12 +00002342 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 /// expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002347 ExprResult RebuildDependentScopeDeclRefExpr(
2348 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002349 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002350 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002351 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002352 bool IsAddressOfOperand,
2353 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002355 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002356
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002357 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002358 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2359 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002360
Reid Kleckner32506ed2014-06-12 23:03:48 +00002361 return getSema().BuildQualifiedDeclarationNameExpr(
2362 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 }
2364
2365 /// \brief Build a new template-id expression.
2366 ///
2367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002369 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002370 SourceLocation TemplateKWLoc,
2371 LookupResult &R,
2372 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002373 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002374 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2375 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002376 }
2377
2378 /// \brief Build a new object-construction expression.
2379 ///
2380 /// By default, performs semantic analysis to build the new expression.
2381 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002382 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002383 SourceLocation Loc,
2384 CXXConstructorDecl *Constructor,
2385 bool IsElidable,
2386 MultiExprArg Args,
2387 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002388 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002389 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002390 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002391 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002392 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002393 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002394 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002395 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002396 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002397
Douglas Gregordb121ba2009-12-14 16:27:04 +00002398 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002399 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002400 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002401 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002402 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002403 RequiresZeroInit, ConstructKind,
2404 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 }
2406
2407 /// \brief Build a new object-construction expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002411 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2412 SourceLocation LParenLoc,
2413 MultiExprArg Args,
2414 SourceLocation RParenLoc) {
2415 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002417 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 RParenLoc);
2419 }
2420
2421 /// \brief Build a new object-construction expression.
2422 ///
2423 /// By default, performs semantic analysis to build the new expression.
2424 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002425 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2426 SourceLocation LParenLoc,
2427 MultiExprArg Args,
2428 SourceLocation RParenLoc) {
2429 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002431 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 RParenLoc);
2433 }
Mike Stump11289f42009-09-09 15:08:12 +00002434
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 /// \brief Build a new member reference expression.
2436 ///
2437 /// By default, performs semantic analysis to build the new expression.
2438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002439 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002440 QualType BaseType,
2441 bool IsArrow,
2442 SourceLocation OperatorLoc,
2443 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002444 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002445 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002446 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002447 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002448 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002449 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002450
John McCallb268a282010-08-23 23:25:46 +00002451 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002452 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002453 SS, TemplateKWLoc,
2454 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002455 MemberNameInfo,
2456 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 }
2458
John McCall10eae182009-11-30 22:42:35 +00002459 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002460 ///
2461 /// By default, performs semantic analysis to build the new expression.
2462 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002463 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2464 SourceLocation OperatorLoc,
2465 bool IsArrow,
2466 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002467 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002468 NamedDecl *FirstQualifierInScope,
2469 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002470 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002471 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002472 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002473
John McCallb268a282010-08-23 23:25:46 +00002474 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002475 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002476 SS, TemplateKWLoc,
2477 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002478 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002479 }
Mike Stump11289f42009-09-09 15:08:12 +00002480
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002481 /// \brief Build a new noexcept expression.
2482 ///
2483 /// By default, performs semantic analysis to build the new expression.
2484 /// Subclasses may override this routine to provide different behavior.
2485 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2486 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2487 }
2488
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002489 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002490 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2491 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002492 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002493 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002494 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002495 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2496 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002497 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002498
2499 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2500 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002501 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002502 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002503
Patrick Beard0caa3942012-04-19 00:25:12 +00002504 /// \brief Build a new Objective-C boxed expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
2508 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2509 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2510 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002511
Ted Kremeneke65b0862012-03-06 20:05:56 +00002512 /// \brief Build a new Objective-C array literal.
2513 ///
2514 /// By default, performs semantic analysis to build the new expression.
2515 /// Subclasses may override this routine to provide different behavior.
2516 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2517 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002518 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002519 MultiExprArg(Elements, NumElements));
2520 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002521
2522 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002523 Expr *Base, Expr *Key,
2524 ObjCMethodDecl *getterMethod,
2525 ObjCMethodDecl *setterMethod) {
2526 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2527 getterMethod, setterMethod);
2528 }
2529
2530 /// \brief Build a new Objective-C dictionary literal.
2531 ///
2532 /// By default, performs semantic analysis to build the new expression.
2533 /// Subclasses may override this routine to provide different behavior.
2534 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2535 ObjCDictionaryElement *Elements,
2536 unsigned NumElements) {
2537 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
James Dennett2a4d13c2012-06-15 07:13:21 +00002540 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 ///
2542 /// By default, performs semantic analysis to build the new expression.
2543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002544 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002545 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002547 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002548 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002549
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002550 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002551 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002552 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002553 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002554 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002555 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002556 MultiExprArg Args,
2557 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002558 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2559 ReceiverTypeInfo->getType(),
2560 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002561 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002562 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002563 }
2564
2565 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002566 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002567 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002568 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002569 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002570 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002571 MultiExprArg Args,
2572 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002573 return SemaRef.BuildInstanceMessage(Receiver,
2574 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002575 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002576 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002577 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002578 }
2579
Douglas Gregord51d90d2010-04-26 20:11:03 +00002580 /// \brief Build a new Objective-C ivar reference expression.
2581 ///
2582 /// By default, performs semantic analysis to build the new expression.
2583 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002584 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002585 SourceLocation IvarLoc,
2586 bool IsArrow, bool IsFreeIvar) {
2587 // FIXME: We lose track of the IsFreeIvar bit.
2588 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002589 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2590 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002591 /*FIXME:*/IvarLoc, IsArrow,
2592 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002593 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002594 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002595 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002596 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002597
2598 /// \brief Build a new Objective-C property reference expression.
2599 ///
2600 /// By default, performs semantic analysis to build the new expression.
2601 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002602 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002603 ObjCPropertyDecl *Property,
2604 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002605 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002606 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2607 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2608 /*FIXME:*/PropertyLoc,
2609 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002610 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002611 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002612 NameInfo,
2613 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002615
John McCallb7bd14f2010-12-02 01:19:52 +00002616 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002617 ///
2618 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002619 /// Subclasses may override this routine to provide different behavior.
2620 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2621 ObjCMethodDecl *Getter,
2622 ObjCMethodDecl *Setter,
2623 SourceLocation PropertyLoc) {
2624 // Since these expressions can only be value-dependent, we do not
2625 // need to perform semantic analysis again.
2626 return Owned(
2627 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2628 VK_LValue, OK_ObjCProperty,
2629 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002630 }
2631
Douglas Gregord51d90d2010-04-26 20:11:03 +00002632 /// \brief Build a new Objective-C "isa" expression.
2633 ///
2634 /// By default, performs semantic analysis to build the new expression.
2635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002636 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002637 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002638 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002639 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2640 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002641 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002642 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002643 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002644 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002645 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002646 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002647
Douglas Gregora16548e2009-08-11 05:31:07 +00002648 /// \brief Build a new shuffle vector expression.
2649 ///
2650 /// By default, performs semantic analysis to build the new expression.
2651 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002652 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002653 MultiExprArg SubExprs,
2654 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002655 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002656 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002657 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2658 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2659 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002660 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002661
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002663 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002664 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2665 SemaRef.Context.BuiltinFnTy,
2666 VK_RValue, BuiltinLoc);
2667 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2668 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002669 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002670
2671 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002672 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002673 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002674 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002675
Douglas Gregora16548e2009-08-11 05:31:07 +00002676 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002677 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002678 }
John McCall31f82722010-11-12 08:19:04 +00002679
Hal Finkelc4d7c822013-09-18 03:29:45 +00002680 /// \brief Build a new convert vector expression.
2681 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2682 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2683 SourceLocation RParenLoc) {
2684 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2685 BuiltinLoc, RParenLoc);
2686 }
2687
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002688 /// \brief Build a new template argument pack expansion.
2689 ///
2690 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002691 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002692 /// different behavior.
2693 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002694 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002695 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002696 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002697 case TemplateArgument::Expression: {
2698 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002699 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2700 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002701 if (Result.isInvalid())
2702 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002703
Douglas Gregor98318c22011-01-03 21:37:45 +00002704 return TemplateArgumentLoc(Result.get(), Result.get());
2705 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002706
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002707 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002708 return TemplateArgumentLoc(TemplateArgument(
2709 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002710 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002711 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002712 Pattern.getTemplateNameLoc(),
2713 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002714
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002715 case TemplateArgument::Null:
2716 case TemplateArgument::Integral:
2717 case TemplateArgument::Declaration:
2718 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002719 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002720 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002721 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002722
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002723 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002724 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002725 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002726 EllipsisLoc,
2727 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002728 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2729 Expansion);
2730 break;
2731 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002732
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002733 return TemplateArgumentLoc();
2734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002735
Douglas Gregor968f23a2011-01-03 19:31:53 +00002736 /// \brief Build a new expression pack expansion.
2737 ///
2738 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002739 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002740 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002741 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002742 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002743 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002744 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002745
2746 /// \brief Build a new atomic operation expression.
2747 ///
2748 /// By default, performs semantic analysis to build the new expression.
2749 /// Subclasses may override this routine to provide different behavior.
2750 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2751 MultiExprArg SubExprs,
2752 QualType RetTy,
2753 AtomicExpr::AtomicOp Op,
2754 SourceLocation RParenLoc) {
2755 // Just create the expression; there is not any interesting semantic
2756 // analysis here because we can't actually build an AtomicExpr until
2757 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002758 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002759 RParenLoc);
2760 }
2761
John McCall31f82722010-11-12 08:19:04 +00002762private:
Douglas Gregor14454802011-02-25 02:25:35 +00002763 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2764 QualType ObjectType,
2765 NamedDecl *FirstQualifierInScope,
2766 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002767
2768 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2769 QualType ObjectType,
2770 NamedDecl *FirstQualifierInScope,
2771 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002772
2773 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2774 NamedDecl *FirstQualifierInScope,
2775 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776};
Douglas Gregora16548e2009-08-11 05:31:07 +00002777
Douglas Gregorebe10102009-08-20 07:17:43 +00002778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002779StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002780 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002781 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002782
Douglas Gregorebe10102009-08-20 07:17:43 +00002783 switch (S->getStmtClass()) {
2784 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregorebe10102009-08-20 07:17:43 +00002786 // Transform individual statement nodes
2787#define STMT(Node, Parent) \
2788 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002789#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002790#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002791#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002792
Douglas Gregorebe10102009-08-20 07:17:43 +00002793 // Transform expressions by calling TransformExpr.
2794#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002795#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002796#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002797#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002798 {
John McCalldadc5752010-08-24 06:29:42 +00002799 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002800 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002801 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002802
Richard Smith945f8d32013-01-14 22:39:08 +00002803 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805 }
2806
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002807 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002808}
Mike Stump11289f42009-09-09 15:08:12 +00002809
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002810template<typename Derived>
2811OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2812 if (!S)
2813 return S;
2814
2815 switch (S->getClauseKind()) {
2816 default: break;
2817 // Transform individual clause nodes
2818#define OPENMP_CLAUSE(Name, Class) \
2819 case OMPC_ ## Name : \
2820 return getDerived().Transform ## Class(cast<Class>(S));
2821#include "clang/Basic/OpenMPKinds.def"
2822 }
2823
2824 return S;
2825}
2826
Mike Stump11289f42009-09-09 15:08:12 +00002827
Douglas Gregore922c772009-08-04 22:27:00 +00002828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002829ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002830 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002831 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002832
2833 switch (E->getStmtClass()) {
2834 case Stmt::NoStmtClass: break;
2835#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002836#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002837#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002838 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002839#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002840 }
2841
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002842 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002843}
2844
2845template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002846ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2847 bool CXXDirectInit) {
2848 // Initializers are instantiated like expressions, except that various outer
2849 // layers are stripped.
2850 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002851 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002852
2853 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2854 Init = ExprTemp->getSubExpr();
2855
Richard Smithe6ca4752013-05-30 22:40:16 +00002856 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2857 Init = MTE->GetTemporaryExpr();
2858
Richard Smithd59b8322012-12-19 01:39:02 +00002859 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2860 Init = Binder->getSubExpr();
2861
2862 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2863 Init = ICE->getSubExprAsWritten();
2864
Richard Smithcc1b96d2013-06-12 22:31:48 +00002865 if (CXXStdInitializerListExpr *ILE =
2866 dyn_cast<CXXStdInitializerListExpr>(Init))
2867 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2868
Richard Smith38a549b2012-12-21 08:13:35 +00002869 // If this is not a direct-initializer, we only need to reconstruct
2870 // InitListExprs. Other forms of copy-initialization will be a no-op if
2871 // the initializer is already the right type.
2872 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2873 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2874 return getDerived().TransformExpr(Init);
2875
2876 // Revert value-initialization back to empty parens.
2877 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2878 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002879 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002880 Parens.getEnd());
2881 }
2882
2883 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2884 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002885 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002886 SourceLocation());
2887
2888 // Revert initialization by constructor back to a parenthesized or braced list
2889 // of expressions. Any other form of initializer can just be reused directly.
2890 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002891 return getDerived().TransformExpr(Init);
2892
Richard Smithf8adcdc2014-07-17 05:12:35 +00002893 // If the initialization implicitly converted an initializer list to a
2894 // std::initializer_list object, unwrap the std::initializer_list too.
2895 if (Construct && Construct->isStdInitListInitialization())
2896 return TransformInitializer(Construct->getArg(0), CXXDirectInit);
2897
Richard Smithd59b8322012-12-19 01:39:02 +00002898 SmallVector<Expr*, 8> NewArgs;
2899 bool ArgChanged = false;
2900 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2901 /*IsCall*/true, NewArgs, &ArgChanged))
2902 return ExprError();
2903
2904 // If this was list initialization, revert to list form.
2905 if (Construct->isListInitialization())
2906 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2907 Construct->getLocEnd(),
2908 Construct->getType());
2909
Richard Smithd59b8322012-12-19 01:39:02 +00002910 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002911 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002912 if (Parens.isInvalid()) {
2913 // This was a variable declaration's initialization for which no initializer
2914 // was specified.
2915 assert(NewArgs.empty() &&
2916 "no parens or braces but have direct init with arguments?");
2917 return ExprEmpty();
2918 }
Richard Smithd59b8322012-12-19 01:39:02 +00002919 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2920 Parens.getEnd());
2921}
2922
2923template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002924bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2925 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002926 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002927 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002928 bool *ArgChanged) {
2929 for (unsigned I = 0; I != NumInputs; ++I) {
2930 // If requested, drop call arguments that need to be dropped.
2931 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2932 if (ArgChanged)
2933 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002934
Douglas Gregora3efea12011-01-03 19:04:46 +00002935 break;
2936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002937
Douglas Gregor968f23a2011-01-03 19:31:53 +00002938 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2939 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002940
Chris Lattner01cf8db2011-07-20 06:58:45 +00002941 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002942 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2943 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002944
Douglas Gregor968f23a2011-01-03 19:31:53 +00002945 // Determine whether the set of unexpanded parameter packs can and should
2946 // be expanded.
2947 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002948 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002949 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2950 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002951 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2952 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002953 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002954 Expand, RetainExpansion,
2955 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002956 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002957
Douglas Gregor968f23a2011-01-03 19:31:53 +00002958 if (!Expand) {
2959 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002960 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002961 // expansion.
2962 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2963 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2964 if (OutPattern.isInvalid())
2965 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002966
2967 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002968 Expansion->getEllipsisLoc(),
2969 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002970 if (Out.isInvalid())
2971 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002972
Douglas Gregor968f23a2011-01-03 19:31:53 +00002973 if (ArgChanged)
2974 *ArgChanged = true;
2975 Outputs.push_back(Out.get());
2976 continue;
2977 }
John McCall542e7c62011-07-06 07:30:07 +00002978
2979 // Record right away that the argument was changed. This needs
2980 // to happen even if the array expands to nothing.
2981 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002982
Douglas Gregor968f23a2011-01-03 19:31:53 +00002983 // The transform has determined that we should perform an elementwise
2984 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002985 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002986 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2987 ExprResult Out = getDerived().TransformExpr(Pattern);
2988 if (Out.isInvalid())
2989 return true;
2990
Richard Smith9467be42014-06-06 17:33:35 +00002991 // FIXME: Can this happen? We should not try to expand the pack
2992 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002993 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002994 Out = getDerived().RebuildPackExpansion(
2995 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002996 if (Out.isInvalid())
2997 return true;
2998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002999
Douglas Gregor968f23a2011-01-03 19:31:53 +00003000 Outputs.push_back(Out.get());
3001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003002
Richard Smith9467be42014-06-06 17:33:35 +00003003 // If we're supposed to retain a pack expansion, do so by temporarily
3004 // forgetting the partially-substituted parameter pack.
3005 if (RetainExpansion) {
3006 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3007
3008 ExprResult Out = getDerived().TransformExpr(Pattern);
3009 if (Out.isInvalid())
3010 return true;
3011
3012 Out = getDerived().RebuildPackExpansion(
3013 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3014 if (Out.isInvalid())
3015 return true;
3016
3017 Outputs.push_back(Out.get());
3018 }
3019
Douglas Gregor968f23a2011-01-03 19:31:53 +00003020 continue;
3021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003022
Richard Smithd59b8322012-12-19 01:39:02 +00003023 ExprResult Result =
3024 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3025 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003026 if (Result.isInvalid())
3027 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003028
Douglas Gregora3efea12011-01-03 19:04:46 +00003029 if (Result.get() != Inputs[I] && ArgChanged)
3030 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003031
3032 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003033 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003034
Douglas Gregora3efea12011-01-03 19:04:46 +00003035 return false;
3036}
3037
3038template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003039NestedNameSpecifierLoc
3040TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3041 NestedNameSpecifierLoc NNS,
3042 QualType ObjectType,
3043 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003044 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003045 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003046 Qualifier = Qualifier.getPrefix())
3047 Qualifiers.push_back(Qualifier);
3048
3049 CXXScopeSpec SS;
3050 while (!Qualifiers.empty()) {
3051 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3052 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
Douglas Gregor14454802011-02-25 02:25:35 +00003054 switch (QNNS->getKind()) {
3055 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003056 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003057 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003058 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003059 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003060 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003061 FirstQualifierInScope, false))
3062 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003063
Douglas Gregor14454802011-02-25 02:25:35 +00003064 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor14454802011-02-25 02:25:35 +00003066 case NestedNameSpecifier::Namespace: {
3067 NamespaceDecl *NS
3068 = cast_or_null<NamespaceDecl>(
3069 getDerived().TransformDecl(
3070 Q.getLocalBeginLoc(),
3071 QNNS->getAsNamespace()));
3072 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3073 break;
3074 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregor14454802011-02-25 02:25:35 +00003076 case NestedNameSpecifier::NamespaceAlias: {
3077 NamespaceAliasDecl *Alias
3078 = cast_or_null<NamespaceAliasDecl>(
3079 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3080 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003081 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003082 Q.getLocalEndLoc());
3083 break;
3084 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregor14454802011-02-25 02:25:35 +00003086 case NestedNameSpecifier::Global:
3087 // There is no meaningful transformation that one could perform on the
3088 // global scope.
3089 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3090 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003091
Douglas Gregor14454802011-02-25 02:25:35 +00003092 case NestedNameSpecifier::TypeSpecWithTemplate:
3093 case NestedNameSpecifier::TypeSpec: {
3094 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3095 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003096
Douglas Gregor14454802011-02-25 02:25:35 +00003097 if (!TL)
3098 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003099
Douglas Gregor14454802011-02-25 02:25:35 +00003100 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003101 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003102 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003103 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003104 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003105 if (TL.getType()->isEnumeralType())
3106 SemaRef.Diag(TL.getBeginLoc(),
3107 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003108 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3109 Q.getLocalEndLoc());
3110 break;
3111 }
Richard Trieude756fb2011-05-07 01:36:37 +00003112 // If the nested-name-specifier is an invalid type def, don't emit an
3113 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003114 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3115 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003116 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003117 << TL.getType() << SS.getRange();
3118 }
Douglas Gregor14454802011-02-25 02:25:35 +00003119 return NestedNameSpecifierLoc();
3120 }
Douglas Gregore16af532011-02-28 18:50:33 +00003121 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003122
Douglas Gregore16af532011-02-28 18:50:33 +00003123 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003124 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003125 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003126 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
Douglas Gregor14454802011-02-25 02:25:35 +00003128 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003129 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003130 !getDerived().AlwaysRebuild())
3131 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
3133 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003134 // nested-name-specifier, do so.
3135 if (SS.location_size() == NNS.getDataLength() &&
3136 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3137 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3138
3139 // Allocate new nested-name-specifier location information.
3140 return SS.getWithLocInContext(SemaRef.Context);
3141}
3142
3143template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003144DeclarationNameInfo
3145TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003146::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003147 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003148 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003149 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003150
3151 switch (Name.getNameKind()) {
3152 case DeclarationName::Identifier:
3153 case DeclarationName::ObjCZeroArgSelector:
3154 case DeclarationName::ObjCOneArgSelector:
3155 case DeclarationName::ObjCMultiArgSelector:
3156 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003157 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003158 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003159 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregorf816bd72009-09-03 22:13:48 +00003161 case DeclarationName::CXXConstructorName:
3162 case DeclarationName::CXXDestructorName:
3163 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003164 TypeSourceInfo *NewTInfo;
3165 CanQualType NewCanTy;
3166 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003167 NewTInfo = getDerived().TransformType(OldTInfo);
3168 if (!NewTInfo)
3169 return DeclarationNameInfo();
3170 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003171 }
3172 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003173 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003174 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003175 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003176 if (NewT.isNull())
3177 return DeclarationNameInfo();
3178 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3179 }
Mike Stump11289f42009-09-09 15:08:12 +00003180
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003181 DeclarationName NewName
3182 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3183 NewCanTy);
3184 DeclarationNameInfo NewNameInfo(NameInfo);
3185 NewNameInfo.setName(NewName);
3186 NewNameInfo.setNamedTypeInfo(NewTInfo);
3187 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003188 }
Mike Stump11289f42009-09-09 15:08:12 +00003189 }
3190
David Blaikie83d382b2011-09-23 05:06:16 +00003191 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003192}
3193
3194template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003195TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003196TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3197 TemplateName Name,
3198 SourceLocation NameLoc,
3199 QualType ObjectType,
3200 NamedDecl *FirstQualifierInScope) {
3201 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3202 TemplateDecl *Template = QTN->getTemplateDecl();
3203 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor9db53502011-03-02 18:07:45 +00003205 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003206 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003207 Template));
3208 if (!TransTemplate)
3209 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003210
Douglas Gregor9db53502011-03-02 18:07:45 +00003211 if (!getDerived().AlwaysRebuild() &&
3212 SS.getScopeRep() == QTN->getQualifier() &&
3213 TransTemplate == Template)
3214 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003215
Douglas Gregor9db53502011-03-02 18:07:45 +00003216 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3217 TransTemplate);
3218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003219
Douglas Gregor9db53502011-03-02 18:07:45 +00003220 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3221 if (SS.getScopeRep()) {
3222 // These apply to the scope specifier, not the template.
3223 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003224 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003225 }
3226
Douglas Gregor9db53502011-03-02 18:07:45 +00003227 if (!getDerived().AlwaysRebuild() &&
3228 SS.getScopeRep() == DTN->getQualifier() &&
3229 ObjectType.isNull())
3230 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
Douglas Gregor9db53502011-03-02 18:07:45 +00003232 if (DTN->isIdentifier()) {
3233 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003234 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003235 NameLoc,
3236 ObjectType,
3237 FirstQualifierInScope);
3238 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
Douglas Gregor9db53502011-03-02 18:07:45 +00003240 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3241 ObjectType);
3242 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003243
Douglas Gregor9db53502011-03-02 18:07:45 +00003244 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3245 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003246 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003247 Template));
3248 if (!TransTemplate)
3249 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregor9db53502011-03-02 18:07:45 +00003251 if (!getDerived().AlwaysRebuild() &&
3252 TransTemplate == Template)
3253 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003254
Douglas Gregor9db53502011-03-02 18:07:45 +00003255 return TemplateName(TransTemplate);
3256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003257
Douglas Gregor9db53502011-03-02 18:07:45 +00003258 if (SubstTemplateTemplateParmPackStorage *SubstPack
3259 = Name.getAsSubstTemplateTemplateParmPack()) {
3260 TemplateTemplateParmDecl *TransParam
3261 = cast_or_null<TemplateTemplateParmDecl>(
3262 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3263 if (!TransParam)
3264 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregor9db53502011-03-02 18:07:45 +00003266 if (!getDerived().AlwaysRebuild() &&
3267 TransParam == SubstPack->getParameterPack())
3268 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003269
3270 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003271 SubstPack->getArgumentPack());
3272 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
Douglas Gregor9db53502011-03-02 18:07:45 +00003274 // These should be getting filtered out before they reach the AST.
3275 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003276}
3277
3278template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003279void TreeTransform<Derived>::InventTemplateArgumentLoc(
3280 const TemplateArgument &Arg,
3281 TemplateArgumentLoc &Output) {
3282 SourceLocation Loc = getDerived().getBaseLocation();
3283 switch (Arg.getKind()) {
3284 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003285 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003286 break;
3287
3288 case TemplateArgument::Type:
3289 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003290 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003291
John McCall0ad16662009-10-29 08:12:44 +00003292 break;
3293
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003294 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003295 case TemplateArgument::TemplateExpansion: {
3296 NestedNameSpecifierLocBuilder Builder;
3297 TemplateName Template = Arg.getAsTemplate();
3298 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3299 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3300 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3301 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003302
Douglas Gregor9d802122011-03-02 17:09:35 +00003303 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003304 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003305 Builder.getWithLocInContext(SemaRef.Context),
3306 Loc);
3307 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003308 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003309 Builder.getWithLocInContext(SemaRef.Context),
3310 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003312 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003313 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003314
John McCall0ad16662009-10-29 08:12:44 +00003315 case TemplateArgument::Expression:
3316 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3317 break;
3318
3319 case TemplateArgument::Declaration:
3320 case TemplateArgument::Integral:
3321 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003322 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003323 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003324 break;
3325 }
3326}
3327
3328template<typename Derived>
3329bool TreeTransform<Derived>::TransformTemplateArgument(
3330 const TemplateArgumentLoc &Input,
3331 TemplateArgumentLoc &Output) {
3332 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003333 switch (Arg.getKind()) {
3334 case TemplateArgument::Null:
3335 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003336 case TemplateArgument::Pack:
3337 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003338 case TemplateArgument::NullPtr:
3339 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregore922c772009-08-04 22:27:00 +00003341 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003342 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003343 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003344 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003345
3346 DI = getDerived().TransformType(DI);
3347 if (!DI) return true;
3348
3349 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3350 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003351 }
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003353 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003354 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3355 if (QualifierLoc) {
3356 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3357 if (!QualifierLoc)
3358 return true;
3359 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregordf846d12011-03-02 18:46:51 +00003361 CXXScopeSpec SS;
3362 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003363 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003364 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3365 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003366 if (Template.isNull())
3367 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregor9d802122011-03-02 17:09:35 +00003369 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003370 Input.getTemplateNameLoc());
3371 return false;
3372 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003373
3374 case TemplateArgument::TemplateExpansion:
3375 llvm_unreachable("Caller should expand pack expansions");
3376
Douglas Gregore922c772009-08-04 22:27:00 +00003377 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003378 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003379 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003380 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003381
John McCall0ad16662009-10-29 08:12:44 +00003382 Expr *InputExpr = Input.getSourceExpression();
3383 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3384
Chris Lattnercdb591a2011-04-25 20:37:58 +00003385 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003386 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003387 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003388 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003389 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003390 }
Douglas Gregore922c772009-08-04 22:27:00 +00003391 }
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregore922c772009-08-04 22:27:00 +00003393 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003394 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003395}
3396
Douglas Gregorfe921a72010-12-20 23:36:19 +00003397/// \brief Iterator adaptor that invents template argument location information
3398/// for each of the template arguments in its underlying iterator.
3399template<typename Derived, typename InputIterator>
3400class TemplateArgumentLocInventIterator {
3401 TreeTransform<Derived> &Self;
3402 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregorfe921a72010-12-20 23:36:19 +00003404public:
3405 typedef TemplateArgumentLoc value_type;
3406 typedef TemplateArgumentLoc reference;
3407 typedef typename std::iterator_traits<InputIterator>::difference_type
3408 difference_type;
3409 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
Douglas Gregorfe921a72010-12-20 23:36:19 +00003411 class pointer {
3412 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Douglas Gregorfe921a72010-12-20 23:36:19 +00003414 public:
3415 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregorfe921a72010-12-20 23:36:19 +00003417 const TemplateArgumentLoc *operator->() const { return &Arg; }
3418 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregorfe921a72010-12-20 23:36:19 +00003420 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
Douglas Gregorfe921a72010-12-20 23:36:19 +00003422 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3423 InputIterator Iter)
3424 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregorfe921a72010-12-20 23:36:19 +00003426 TemplateArgumentLocInventIterator &operator++() {
3427 ++Iter;
3428 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregorfe921a72010-12-20 23:36:19 +00003431 TemplateArgumentLocInventIterator operator++(int) {
3432 TemplateArgumentLocInventIterator Old(*this);
3433 ++(*this);
3434 return Old;
3435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003436
Douglas Gregorfe921a72010-12-20 23:36:19 +00003437 reference operator*() const {
3438 TemplateArgumentLoc Result;
3439 Self.InventTemplateArgumentLoc(*Iter, Result);
3440 return Result;
3441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Douglas Gregorfe921a72010-12-20 23:36:19 +00003443 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregorfe921a72010-12-20 23:36:19 +00003445 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3446 const TemplateArgumentLocInventIterator &Y) {
3447 return X.Iter == Y.Iter;
3448 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003449
Douglas Gregorfe921a72010-12-20 23:36:19 +00003450 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3451 const TemplateArgumentLocInventIterator &Y) {
3452 return X.Iter != Y.Iter;
3453 }
3454};
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregor42cafa82010-12-20 17:42:22 +00003456template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003457template<typename InputIterator>
3458bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3459 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003460 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003461 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003462 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003463 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003465 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3466 // Unpack argument packs, which we translate them into separate
3467 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003468 // FIXME: We could do much better if we could guarantee that the
3469 // TemplateArgumentLocInfo for the pack expansion would be usable for
3470 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003471 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003472 TemplateArgument::pack_iterator>
3473 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003474 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003475 In.getArgument().pack_begin()),
3476 PackLocIterator(*this,
3477 In.getArgument().pack_end()),
3478 Outputs))
3479 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003480
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003481 continue;
3482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003484 if (In.getArgument().isPackExpansion()) {
3485 // We have a pack expansion, for which we will be substituting into
3486 // the pattern.
3487 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003488 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003489 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003490 = getSema().getTemplateArgumentPackExpansionPattern(
3491 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Chris Lattner01cf8db2011-07-20 06:58:45 +00003493 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003494 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3495 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003496
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003497 // Determine whether the set of unexpanded parameter packs can and should
3498 // be expanded.
3499 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003500 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003501 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003502 if (getDerived().TryExpandParameterPacks(Ellipsis,
3503 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003504 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003505 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003506 RetainExpansion,
3507 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003508 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003509
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003510 if (!Expand) {
3511 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003512 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003513 // expansion.
3514 TemplateArgumentLoc OutPattern;
3515 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3516 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3517 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003518
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003519 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3520 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003521 if (Out.getArgument().isNull())
3522 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003523
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003524 Outputs.addArgument(Out);
3525 continue;
3526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003528 // The transform has determined that we should perform an elementwise
3529 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003530 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003531 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3532
3533 if (getDerived().TransformTemplateArgument(Pattern, Out))
3534 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003536 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003537 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3538 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003539 if (Out.getArgument().isNull())
3540 return true;
3541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003543 Outputs.addArgument(Out);
3544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor48d24112011-01-10 20:53:55 +00003546 // If we're supposed to retain a pack expansion, do so by temporarily
3547 // forgetting the partially-substituted parameter pack.
3548 if (RetainExpansion) {
3549 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor48d24112011-01-10 20:53:55 +00003551 if (getDerived().TransformTemplateArgument(Pattern, Out))
3552 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003554 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3555 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003556 if (Out.getArgument().isNull())
3557 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003558
Douglas Gregor48d24112011-01-10 20:53:55 +00003559 Outputs.addArgument(Out);
3560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003562 continue;
3563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
3565 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003566 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003567 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003568
Douglas Gregor42cafa82010-12-20 17:42:22 +00003569 Outputs.addArgument(Out);
3570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Douglas Gregor42cafa82010-12-20 17:42:22 +00003572 return false;
3573
3574}
3575
Douglas Gregord6ff3322009-08-04 16:50:30 +00003576//===----------------------------------------------------------------------===//
3577// Type transformation
3578//===----------------------------------------------------------------------===//
3579
3580template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003581QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003582 if (getDerived().AlreadyTransformed(T))
3583 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003584
John McCall550e0c22009-10-21 00:40:46 +00003585 // Temporary workaround. All of these transformations should
3586 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003587 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3588 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
John McCall31f82722010-11-12 08:19:04 +00003590 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003591
John McCall550e0c22009-10-21 00:40:46 +00003592 if (!NewDI)
3593 return QualType();
3594
3595 return NewDI->getType();
3596}
3597
3598template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003599TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003600 // Refine the base location to the type's location.
3601 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3602 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003603 if (getDerived().AlreadyTransformed(DI->getType()))
3604 return DI;
3605
3606 TypeLocBuilder TLB;
3607
3608 TypeLoc TL = DI->getTypeLoc();
3609 TLB.reserve(TL.getFullDataSize());
3610
John McCall31f82722010-11-12 08:19:04 +00003611 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003612 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003613 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003614
John McCallbcd03502009-12-07 02:54:59 +00003615 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003616}
3617
3618template<typename Derived>
3619QualType
John McCall31f82722010-11-12 08:19:04 +00003620TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003621 switch (T.getTypeLocClass()) {
3622#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003623#define TYPELOC(CLASS, PARENT) \
3624 case TypeLoc::CLASS: \
3625 return getDerived().Transform##CLASS##Type(TLB, \
3626 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003627#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003628 }
Mike Stump11289f42009-09-09 15:08:12 +00003629
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003630 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003631}
3632
3633/// FIXME: By default, this routine adds type qualifiers only to types
3634/// that can have qualifiers, and silently suppresses those qualifiers
3635/// that are not permitted (e.g., qualifiers on reference or function
3636/// types). This is the right thing for template instantiation, but
3637/// probably not for other clients.
3638template<typename Derived>
3639QualType
3640TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003641 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003642 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003643
John McCall31f82722010-11-12 08:19:04 +00003644 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003645 if (Result.isNull())
3646 return QualType();
3647
3648 // Silently suppress qualifiers if the result type can't be qualified.
3649 // FIXME: this is the right thing for template instantiation, but
3650 // probably not for other clients.
3651 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003652 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003653
John McCall31168b02011-06-15 23:02:42 +00003654 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003655 // resulting type.
3656 if (Quals.hasObjCLifetime()) {
3657 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3658 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003659 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003660 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003661 // A lifetime qualifier applied to a substituted template parameter
3662 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003663 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003664 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003665 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3666 QualType Replacement = SubstTypeParam->getReplacementType();
3667 Qualifiers Qs = Replacement.getQualifiers();
3668 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003669 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003670 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3671 Qs);
3672 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003673 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003674 Replacement);
3675 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003676 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3677 // 'auto' types behave the same way as template parameters.
3678 QualType Deduced = AutoTy->getDeducedType();
3679 Qualifiers Qs = Deduced.getQualifiers();
3680 Qs.removeObjCLifetime();
3681 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3682 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003683 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3684 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003685 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003686 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003687 // Otherwise, complain about the addition of a qualifier to an
3688 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003689 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003690 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003691 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregore46db902011-06-17 22:11:49 +00003693 Quals.removeObjCLifetime();
3694 }
3695 }
3696 }
John McCallcb0f89a2010-06-05 06:41:15 +00003697 if (!Quals.empty()) {
3698 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003699 // BuildQualifiedType might not add qualifiers if they are invalid.
3700 if (Result.hasLocalQualifiers())
3701 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003702 // No location information to preserve.
3703 }
John McCall550e0c22009-10-21 00:40:46 +00003704
3705 return Result;
3706}
3707
Douglas Gregor14454802011-02-25 02:25:35 +00003708template<typename Derived>
3709TypeLoc
3710TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3711 QualType ObjectType,
3712 NamedDecl *UnqualLookup,
3713 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003714 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003715 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003716
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003717 TypeSourceInfo *TSI =
3718 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3719 if (TSI)
3720 return TSI->getTypeLoc();
3721 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003722}
3723
Douglas Gregor579c15f2011-03-02 18:32:08 +00003724template<typename Derived>
3725TypeSourceInfo *
3726TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3727 QualType ObjectType,
3728 NamedDecl *UnqualLookup,
3729 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003730 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003731 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003733 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3734 UnqualLookup, SS);
3735}
3736
3737template <typename Derived>
3738TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3739 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3740 CXXScopeSpec &SS) {
3741 QualType T = TL.getType();
3742 assert(!getDerived().AlreadyTransformed(T));
3743
Douglas Gregor579c15f2011-03-02 18:32:08 +00003744 TypeLocBuilder TLB;
3745 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Douglas Gregor579c15f2011-03-02 18:32:08 +00003747 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003748 TemplateSpecializationTypeLoc SpecTL =
3749 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003750
Douglas Gregor579c15f2011-03-02 18:32:08 +00003751 TemplateName Template
3752 = getDerived().TransformTemplateName(SS,
3753 SpecTL.getTypePtr()->getTemplateName(),
3754 SpecTL.getTemplateNameLoc(),
3755 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003756 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003757 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003758
3759 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003760 Template);
3761 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003762 DependentTemplateSpecializationTypeLoc SpecTL =
3763 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregor579c15f2011-03-02 18:32:08 +00003765 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003766 = getDerived().RebuildTemplateName(SS,
3767 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003768 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003769 ObjectType, UnqualLookup);
3770 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003771 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003772
3773 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003774 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003775 Template,
3776 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003777 } else {
3778 // Nothing special needs to be done for these.
3779 Result = getDerived().TransformType(TLB, TL);
3780 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003781
3782 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003783 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003784
Douglas Gregor579c15f2011-03-02 18:32:08 +00003785 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3786}
3787
John McCall550e0c22009-10-21 00:40:46 +00003788template <class TyLoc> static inline
3789QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3790 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3791 NewT.setNameLoc(T.getNameLoc());
3792 return T.getType();
3793}
3794
John McCall550e0c22009-10-21 00:40:46 +00003795template<typename Derived>
3796QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003797 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003798 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3799 NewT.setBuiltinLoc(T.getBuiltinLoc());
3800 if (T.needsExtraLocalData())
3801 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3802 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003803}
Mike Stump11289f42009-09-09 15:08:12 +00003804
Douglas Gregord6ff3322009-08-04 16:50:30 +00003805template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003806QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003807 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003808 // FIXME: recurse?
3809 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003810}
Mike Stump11289f42009-09-09 15:08:12 +00003811
Reid Kleckner0503a872013-12-05 01:23:43 +00003812template <typename Derived>
3813QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3814 AdjustedTypeLoc TL) {
3815 // Adjustments applied during transformation are handled elsewhere.
3816 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3817}
3818
Douglas Gregord6ff3322009-08-04 16:50:30 +00003819template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003820QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3821 DecayedTypeLoc TL) {
3822 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3823 if (OriginalType.isNull())
3824 return QualType();
3825
3826 QualType Result = TL.getType();
3827 if (getDerived().AlwaysRebuild() ||
3828 OriginalType != TL.getOriginalLoc().getType())
3829 Result = SemaRef.Context.getDecayedType(OriginalType);
3830 TLB.push<DecayedTypeLoc>(Result);
3831 // Nothing to set for DecayedTypeLoc.
3832 return Result;
3833}
3834
3835template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003836QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003837 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003838 QualType PointeeType
3839 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003840 if (PointeeType.isNull())
3841 return QualType();
3842
3843 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003844 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003845 // A dependent pointer type 'T *' has is being transformed such
3846 // that an Objective-C class type is being replaced for 'T'. The
3847 // resulting pointer type is an ObjCObjectPointerType, not a
3848 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003849 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
John McCall8b07ec22010-05-15 11:32:37 +00003851 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3852 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003853 return Result;
3854 }
John McCall31f82722010-11-12 08:19:04 +00003855
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003856 if (getDerived().AlwaysRebuild() ||
3857 PointeeType != TL.getPointeeLoc().getType()) {
3858 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3859 if (Result.isNull())
3860 return QualType();
3861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003862
John McCall31168b02011-06-15 23:02:42 +00003863 // Objective-C ARC can add lifetime qualifiers to the type that we're
3864 // pointing to.
3865 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003866
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003867 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3868 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003869 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003870}
Mike Stump11289f42009-09-09 15:08:12 +00003871
3872template<typename Derived>
3873QualType
John McCall550e0c22009-10-21 00:40:46 +00003874TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003875 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003876 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003877 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3878 if (PointeeType.isNull())
3879 return QualType();
3880
3881 QualType Result = TL.getType();
3882 if (getDerived().AlwaysRebuild() ||
3883 PointeeType != TL.getPointeeLoc().getType()) {
3884 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003885 TL.getSigilLoc());
3886 if (Result.isNull())
3887 return QualType();
3888 }
3889
Douglas Gregor049211a2010-04-22 16:50:51 +00003890 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003891 NewT.setSigilLoc(TL.getSigilLoc());
3892 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003893}
3894
John McCall70dd5f62009-10-30 00:06:24 +00003895/// Transforms a reference type. Note that somewhat paradoxically we
3896/// don't care whether the type itself is an l-value type or an r-value
3897/// type; we only care if the type was *written* as an l-value type
3898/// or an r-value type.
3899template<typename Derived>
3900QualType
3901TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003902 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003903 const ReferenceType *T = TL.getTypePtr();
3904
3905 // Note that this works with the pointee-as-written.
3906 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3907 if (PointeeType.isNull())
3908 return QualType();
3909
3910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 PointeeType != T->getPointeeTypeAsWritten()) {
3913 Result = getDerived().RebuildReferenceType(PointeeType,
3914 T->isSpelledAsLValue(),
3915 TL.getSigilLoc());
3916 if (Result.isNull())
3917 return QualType();
3918 }
3919
John McCall31168b02011-06-15 23:02:42 +00003920 // Objective-C ARC can add lifetime qualifiers to the type that we're
3921 // referring to.
3922 TLB.TypeWasModifiedSafely(
3923 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3924
John McCall70dd5f62009-10-30 00:06:24 +00003925 // r-value references can be rebuilt as l-value references.
3926 ReferenceTypeLoc NewTL;
3927 if (isa<LValueReferenceType>(Result))
3928 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3929 else
3930 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3931 NewTL.setSigilLoc(TL.getSigilLoc());
3932
3933 return Result;
3934}
3935
Mike Stump11289f42009-09-09 15:08:12 +00003936template<typename Derived>
3937QualType
John McCall550e0c22009-10-21 00:40:46 +00003938TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003939 LValueReferenceTypeLoc TL) {
3940 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003941}
3942
Mike Stump11289f42009-09-09 15:08:12 +00003943template<typename Derived>
3944QualType
John McCall550e0c22009-10-21 00:40:46 +00003945TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 RValueReferenceTypeLoc TL) {
3947 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003948}
Mike Stump11289f42009-09-09 15:08:12 +00003949
Douglas Gregord6ff3322009-08-04 16:50:30 +00003950template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003951QualType
John McCall550e0c22009-10-21 00:40:46 +00003952TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003953 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003954 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955 if (PointeeType.isNull())
3956 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003957
Abramo Bagnara509357842011-03-05 14:42:21 +00003958 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003959 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003960 if (OldClsTInfo) {
3961 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3962 if (!NewClsTInfo)
3963 return QualType();
3964 }
3965
3966 const MemberPointerType *T = TL.getTypePtr();
3967 QualType OldClsType = QualType(T->getClass(), 0);
3968 QualType NewClsType;
3969 if (NewClsTInfo)
3970 NewClsType = NewClsTInfo->getType();
3971 else {
3972 NewClsType = getDerived().TransformType(OldClsType);
3973 if (NewClsType.isNull())
3974 return QualType();
3975 }
Mike Stump11289f42009-09-09 15:08:12 +00003976
John McCall550e0c22009-10-21 00:40:46 +00003977 QualType Result = TL.getType();
3978 if (getDerived().AlwaysRebuild() ||
3979 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003980 NewClsType != OldClsType) {
3981 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003982 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003983 if (Result.isNull())
3984 return QualType();
3985 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986
Reid Kleckner0503a872013-12-05 01:23:43 +00003987 // If we had to adjust the pointee type when building a member pointer, make
3988 // sure to push TypeLoc info for it.
3989 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3990 if (MPT && PointeeType != MPT->getPointeeType()) {
3991 assert(isa<AdjustedType>(MPT->getPointeeType()));
3992 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3993 }
3994
John McCall550e0c22009-10-21 00:40:46 +00003995 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3996 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003997 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003998
3999 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004000}
4001
Mike Stump11289f42009-09-09 15:08:12 +00004002template<typename Derived>
4003QualType
John McCall550e0c22009-10-21 00:40:46 +00004004TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004005 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004006 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004007 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004008 if (ElementType.isNull())
4009 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004010
John McCall550e0c22009-10-21 00:40:46 +00004011 QualType Result = TL.getType();
4012 if (getDerived().AlwaysRebuild() ||
4013 ElementType != T->getElementType()) {
4014 Result = getDerived().RebuildConstantArrayType(ElementType,
4015 T->getSizeModifier(),
4016 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004017 T->getIndexTypeCVRQualifiers(),
4018 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004019 if (Result.isNull())
4020 return QualType();
4021 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004022
4023 // We might have either a ConstantArrayType or a VariableArrayType now:
4024 // a ConstantArrayType is allowed to have an element type which is a
4025 // VariableArrayType if the type is dependent. Fortunately, all array
4026 // types have the same location layout.
4027 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004028 NewTL.setLBracketLoc(TL.getLBracketLoc());
4029 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004030
John McCall550e0c22009-10-21 00:40:46 +00004031 Expr *Size = TL.getSizeExpr();
4032 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004033 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4034 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004035 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4036 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004037 }
4038 NewTL.setSizeExpr(Size);
4039
4040 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004041}
Mike Stump11289f42009-09-09 15:08:12 +00004042
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004044QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004045 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004046 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004047 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004048 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049 if (ElementType.isNull())
4050 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004051
John McCall550e0c22009-10-21 00:40:46 +00004052 QualType Result = TL.getType();
4053 if (getDerived().AlwaysRebuild() ||
4054 ElementType != T->getElementType()) {
4055 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004057 T->getIndexTypeCVRQualifiers(),
4058 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004059 if (Result.isNull())
4060 return QualType();
4061 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
John McCall550e0c22009-10-21 00:40:46 +00004063 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4064 NewTL.setLBracketLoc(TL.getLBracketLoc());
4065 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004066 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004067
4068 return Result;
4069}
4070
4071template<typename Derived>
4072QualType
4073TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004074 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004075 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004076 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4077 if (ElementType.isNull())
4078 return QualType();
4079
John McCalldadc5752010-08-24 06:29:42 +00004080 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004081 = getDerived().TransformExpr(T->getSizeExpr());
4082 if (SizeResult.isInvalid())
4083 return QualType();
4084
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004085 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004086
4087 QualType Result = TL.getType();
4088 if (getDerived().AlwaysRebuild() ||
4089 ElementType != T->getElementType() ||
4090 Size != T->getSizeExpr()) {
4091 Result = getDerived().RebuildVariableArrayType(ElementType,
4092 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004093 Size,
John McCall550e0c22009-10-21 00:40:46 +00004094 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004095 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004096 if (Result.isNull())
4097 return QualType();
4098 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004099
Serge Pavlov774c6d02014-02-06 03:49:11 +00004100 // We might have constant size array now, but fortunately it has the same
4101 // location layout.
4102 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004103 NewTL.setLBracketLoc(TL.getLBracketLoc());
4104 NewTL.setRBracketLoc(TL.getRBracketLoc());
4105 NewTL.setSizeExpr(Size);
4106
4107 return Result;
4108}
4109
4110template<typename Derived>
4111QualType
4112TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004113 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004114 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004115 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4116 if (ElementType.isNull())
4117 return QualType();
4118
Richard Smith764d2fe2011-12-20 02:08:33 +00004119 // Array bounds are constant expressions.
4120 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4121 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004122
John McCall33ddac02011-01-19 10:06:00 +00004123 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4124 Expr *origSize = TL.getSizeExpr();
4125 if (!origSize) origSize = T->getSizeExpr();
4126
4127 ExprResult sizeResult
4128 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004129 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004130 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004131 return QualType();
4132
John McCall33ddac02011-01-19 10:06:00 +00004133 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004134
4135 QualType Result = TL.getType();
4136 if (getDerived().AlwaysRebuild() ||
4137 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004138 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004139 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4140 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004141 size,
John McCall550e0c22009-10-21 00:40:46 +00004142 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004143 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004144 if (Result.isNull())
4145 return QualType();
4146 }
John McCall550e0c22009-10-21 00:40:46 +00004147
4148 // We might have any sort of array type now, but fortunately they
4149 // all have the same location layout.
4150 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4151 NewTL.setLBracketLoc(TL.getLBracketLoc());
4152 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004153 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004154
4155 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004156}
Mike Stump11289f42009-09-09 15:08:12 +00004157
4158template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004160 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004162 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004163
4164 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004165 QualType ElementType = getDerived().TransformType(T->getElementType());
4166 if (ElementType.isNull())
4167 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004168
Richard Smith764d2fe2011-12-20 02:08:33 +00004169 // Vector sizes are constant expressions.
4170 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4171 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004172
John McCalldadc5752010-08-24 06:29:42 +00004173 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004174 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175 if (Size.isInvalid())
4176 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004177
John McCall550e0c22009-10-21 00:40:46 +00004178 QualType Result = TL.getType();
4179 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004180 ElementType != T->getElementType() ||
4181 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004182 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004183 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004185 if (Result.isNull())
4186 return QualType();
4187 }
John McCall550e0c22009-10-21 00:40:46 +00004188
4189 // Result might be dependent or not.
4190 if (isa<DependentSizedExtVectorType>(Result)) {
4191 DependentSizedExtVectorTypeLoc NewTL
4192 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4193 NewTL.setNameLoc(TL.getNameLoc());
4194 } else {
4195 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4196 NewTL.setNameLoc(TL.getNameLoc());
4197 }
4198
4199 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004200}
Mike Stump11289f42009-09-09 15:08:12 +00004201
4202template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004203QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004204 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004205 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206 QualType ElementType = getDerived().TransformType(T->getElementType());
4207 if (ElementType.isNull())
4208 return QualType();
4209
John McCall550e0c22009-10-21 00:40:46 +00004210 QualType Result = TL.getType();
4211 if (getDerived().AlwaysRebuild() ||
4212 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004213 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004214 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004215 if (Result.isNull())
4216 return QualType();
4217 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004218
John McCall550e0c22009-10-21 00:40:46 +00004219 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4220 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004221
John McCall550e0c22009-10-21 00:40:46 +00004222 return Result;
4223}
4224
4225template<typename Derived>
4226QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004227 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004228 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004229 QualType ElementType = getDerived().TransformType(T->getElementType());
4230 if (ElementType.isNull())
4231 return QualType();
4232
4233 QualType Result = TL.getType();
4234 if (getDerived().AlwaysRebuild() ||
4235 ElementType != T->getElementType()) {
4236 Result = getDerived().RebuildExtVectorType(ElementType,
4237 T->getNumElements(),
4238 /*FIXME*/ SourceLocation());
4239 if (Result.isNull())
4240 return QualType();
4241 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004242
John McCall550e0c22009-10-21 00:40:46 +00004243 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4244 NewTL.setNameLoc(TL.getNameLoc());
4245
4246 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004247}
Mike Stump11289f42009-09-09 15:08:12 +00004248
David Blaikie05785d12013-02-20 22:23:23 +00004249template <typename Derived>
4250ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4251 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4252 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004253 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004254 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004255
Douglas Gregor715e4612011-01-14 22:40:04 +00004256 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004257 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004258 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004259 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004260 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004261
Douglas Gregor715e4612011-01-14 22:40:04 +00004262 TypeLocBuilder TLB;
4263 TypeLoc NewTL = OldDI->getTypeLoc();
4264 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004265
4266 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004267 OldExpansionTL.getPatternLoc());
4268 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004269 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004270
4271 Result = RebuildPackExpansionType(Result,
4272 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004273 OldExpansionTL.getEllipsisLoc(),
4274 NumExpansions);
4275 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004276 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004277
Douglas Gregor715e4612011-01-14 22:40:04 +00004278 PackExpansionTypeLoc NewExpansionTL
4279 = TLB.push<PackExpansionTypeLoc>(Result);
4280 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4281 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4282 } else
4283 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004284 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004285 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004286
John McCall8fb0d9d2011-05-01 22:35:37 +00004287 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004288 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004289
4290 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4291 OldParm->getDeclContext(),
4292 OldParm->getInnerLocStart(),
4293 OldParm->getLocation(),
4294 OldParm->getIdentifier(),
4295 NewDI->getType(),
4296 NewDI,
4297 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004298 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004299 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4300 OldParm->getFunctionScopeIndex() + indexAdjustment);
4301 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004302}
4303
4304template<typename Derived>
4305bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004306 TransformFunctionTypeParams(SourceLocation Loc,
4307 ParmVarDecl **Params, unsigned NumParams,
4308 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004309 SmallVectorImpl<QualType> &OutParamTypes,
4310 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004311 int indexAdjustment = 0;
4312
Douglas Gregordd472162011-01-07 00:20:55 +00004313 for (unsigned i = 0; i != NumParams; ++i) {
4314 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004315 assert(OldParm->getFunctionScopeIndex() == i);
4316
David Blaikie05785d12013-02-20 22:23:23 +00004317 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004318 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 if (OldParm->isParameterPack()) {
4320 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004321 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004322
Douglas Gregor5499af42011-01-05 23:12:31 +00004323 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004324 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004325 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004326 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4327 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004328 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4329
Douglas Gregor5499af42011-01-05 23:12:31 +00004330 // Determine whether we should expand the parameter packs.
4331 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004332 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004333 Optional<unsigned> OrigNumExpansions =
4334 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004335 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004336 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4337 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004338 Unexpanded,
4339 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004340 RetainExpansion,
4341 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004342 return true;
4343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004344
Douglas Gregor5499af42011-01-05 23:12:31 +00004345 if (ShouldExpand) {
4346 // Expand the function parameter pack into multiple, separate
4347 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004348 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004349 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004350 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004351 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004352 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004353 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004354 OrigNumExpansions,
4355 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004356 if (!NewParm)
4357 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004358
Douglas Gregordd472162011-01-07 00:20:55 +00004359 OutParamTypes.push_back(NewParm->getType());
4360 if (PVars)
4361 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004362 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004363
4364 // If we're supposed to retain a pack expansion, do so by temporarily
4365 // forgetting the partially-substituted parameter pack.
4366 if (RetainExpansion) {
4367 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004368 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004369 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004370 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004371 OrigNumExpansions,
4372 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004373 if (!NewParm)
4374 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004375
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004376 OutParamTypes.push_back(NewParm->getType());
4377 if (PVars)
4378 PVars->push_back(NewParm);
4379 }
4380
John McCall8fb0d9d2011-05-01 22:35:37 +00004381 // The next parameter should have the same adjustment as the
4382 // last thing we pushed, but we post-incremented indexAdjustment
4383 // on every push. Also, if we push nothing, the adjustment should
4384 // go down by one.
4385 indexAdjustment--;
4386
Douglas Gregor5499af42011-01-05 23:12:31 +00004387 // We're done with the pack expansion.
4388 continue;
4389 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004390
4391 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004392 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004393 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4394 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004395 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004396 NumExpansions,
4397 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004398 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004399 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004400 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004401 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004402
John McCall58f10c32010-03-11 09:03:00 +00004403 if (!NewParm)
4404 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004405
Douglas Gregordd472162011-01-07 00:20:55 +00004406 OutParamTypes.push_back(NewParm->getType());
4407 if (PVars)
4408 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004409 continue;
4410 }
John McCall58f10c32010-03-11 09:03:00 +00004411
4412 // Deal with the possibility that we don't have a parameter
4413 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004414 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004415 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004416 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004417 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004418 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004419 = dyn_cast<PackExpansionType>(OldType)) {
4420 // We have a function parameter pack that may need to be expanded.
4421 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004422 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004423 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Douglas Gregor5499af42011-01-05 23:12:31 +00004425 // Determine whether we should expand the parameter packs.
4426 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004427 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004428 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004429 Unexpanded,
4430 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004431 RetainExpansion,
4432 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004433 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004435
Douglas Gregor5499af42011-01-05 23:12:31 +00004436 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004437 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004438 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004439 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004440 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4441 QualType NewType = getDerived().TransformType(Pattern);
4442 if (NewType.isNull())
4443 return true;
John McCall58f10c32010-03-11 09:03:00 +00004444
Douglas Gregordd472162011-01-07 00:20:55 +00004445 OutParamTypes.push_back(NewType);
4446 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004447 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004449
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 // We're done with the pack expansion.
4451 continue;
4452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
Douglas Gregor48d24112011-01-10 20:53:55 +00004454 // If we're supposed to retain a pack expansion, do so by temporarily
4455 // forgetting the partially-substituted parameter pack.
4456 if (RetainExpansion) {
4457 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4458 QualType NewType = getDerived().TransformType(Pattern);
4459 if (NewType.isNull())
4460 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004461
Douglas Gregor48d24112011-01-10 20:53:55 +00004462 OutParamTypes.push_back(NewType);
4463 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004464 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004465 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004466
Chad Rosier1dcde962012-08-08 18:46:20 +00004467 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004468 // expansion.
4469 OldType = Expansion->getPattern();
4470 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004471 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4472 NewType = getDerived().TransformType(OldType);
4473 } else {
4474 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004476
Douglas Gregor5499af42011-01-05 23:12:31 +00004477 if (NewType.isNull())
4478 return true;
4479
4480 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004481 NewType = getSema().Context.getPackExpansionType(NewType,
4482 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004483
Douglas Gregordd472162011-01-07 00:20:55 +00004484 OutParamTypes.push_back(NewType);
4485 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004486 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004487 }
4488
John McCall8fb0d9d2011-05-01 22:35:37 +00004489#ifndef NDEBUG
4490 if (PVars) {
4491 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4492 if (ParmVarDecl *parm = (*PVars)[i])
4493 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004494 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004495#endif
4496
4497 return false;
4498}
John McCall58f10c32010-03-11 09:03:00 +00004499
4500template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004501QualType
John McCall550e0c22009-10-21 00:40:46 +00004502TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004503 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004504 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004505}
4506
4507template<typename Derived>
4508QualType
4509TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4510 FunctionProtoTypeLoc TL,
4511 CXXRecordDecl *ThisContext,
4512 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004513 // Transform the parameters and return type.
4514 //
Richard Smithf623c962012-04-17 00:58:00 +00004515 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004516 // When the function has a trailing return type, we instantiate the
4517 // parameters before the return type, since the return type can then refer
4518 // to the parameters themselves (via decltype, sizeof, etc.).
4519 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004520 SmallVector<QualType, 4> ParamTypes;
4521 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004522 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004523
Douglas Gregor7fb25412010-10-01 18:44:50 +00004524 QualType ResultType;
4525
Richard Smith1226c602012-08-14 22:51:13 +00004526 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004527 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004528 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004529 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004530 return QualType();
4531
Douglas Gregor3024f072012-04-16 07:05:22 +00004532 {
4533 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004534 // If a declaration declares a member function or member function
4535 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004536 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004537 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004538 // declarator.
4539 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004540
Alp Toker42a16a62014-01-25 23:51:36 +00004541 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004542 if (ResultType.isNull())
4543 return QualType();
4544 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004545 }
4546 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004547 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004548 if (ResultType.isNull())
4549 return QualType();
4550
Alp Toker9cacbab2014-01-20 20:26:09 +00004551 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004552 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004553 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004554 return QualType();
4555 }
4556
Richard Smithf623c962012-04-17 00:58:00 +00004557 // FIXME: Need to transform the exception-specification too.
4558
John McCall550e0c22009-10-21 00:40:46 +00004559 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004560 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004561 T->getNumParams() != ParamTypes.size() ||
4562 !std::equal(T->param_type_begin(), T->param_type_end(),
4563 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004564 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004565 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004566 if (Result.isNull())
4567 return QualType();
4568 }
Mike Stump11289f42009-09-09 15:08:12 +00004569
John McCall550e0c22009-10-21 00:40:46 +00004570 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004571 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004572 NewTL.setLParenLoc(TL.getLParenLoc());
4573 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004574 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004575 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4576 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004577
4578 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579}
Mike Stump11289f42009-09-09 15:08:12 +00004580
Douglas Gregord6ff3322009-08-04 16:50:30 +00004581template<typename Derived>
4582QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004583 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004584 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004585 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004586 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004587 if (ResultType.isNull())
4588 return QualType();
4589
4590 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004591 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004592 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4593
4594 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004595 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004596 NewTL.setLParenLoc(TL.getLParenLoc());
4597 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004598 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004599
4600 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004601}
Mike Stump11289f42009-09-09 15:08:12 +00004602
John McCallb96ec562009-12-04 22:46:56 +00004603template<typename Derived> QualType
4604TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004605 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004606 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004607 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004608 if (!D)
4609 return QualType();
4610
4611 QualType Result = TL.getType();
4612 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4613 Result = getDerived().RebuildUnresolvedUsingType(D);
4614 if (Result.isNull())
4615 return QualType();
4616 }
4617
4618 // We might get an arbitrary type spec type back. We should at
4619 // least always get a type spec type, though.
4620 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4621 NewTL.setNameLoc(TL.getNameLoc());
4622
4623 return Result;
4624}
4625
Douglas Gregord6ff3322009-08-04 16:50:30 +00004626template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004627QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004628 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004629 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004630 TypedefNameDecl *Typedef
4631 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4632 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004633 if (!Typedef)
4634 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004635
John McCall550e0c22009-10-21 00:40:46 +00004636 QualType Result = TL.getType();
4637 if (getDerived().AlwaysRebuild() ||
4638 Typedef != T->getDecl()) {
4639 Result = getDerived().RebuildTypedefType(Typedef);
4640 if (Result.isNull())
4641 return QualType();
4642 }
Mike Stump11289f42009-09-09 15:08:12 +00004643
John McCall550e0c22009-10-21 00:40:46 +00004644 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4645 NewTL.setNameLoc(TL.getNameLoc());
4646
4647 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004648}
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregord6ff3322009-08-04 16:50:30 +00004650template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004651QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004652 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004653 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004654 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4655 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004656
John McCalldadc5752010-08-24 06:29:42 +00004657 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004658 if (E.isInvalid())
4659 return QualType();
4660
Eli Friedmane4f22df2012-02-29 04:03:55 +00004661 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4662 if (E.isInvalid())
4663 return QualType();
4664
John McCall550e0c22009-10-21 00:40:46 +00004665 QualType Result = TL.getType();
4666 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004667 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004668 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004669 if (Result.isNull())
4670 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004671 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004672 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004673
John McCall550e0c22009-10-21 00:40:46 +00004674 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004675 NewTL.setTypeofLoc(TL.getTypeofLoc());
4676 NewTL.setLParenLoc(TL.getLParenLoc());
4677 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004678
4679 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004680}
Mike Stump11289f42009-09-09 15:08:12 +00004681
4682template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004683QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004684 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004685 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4686 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4687 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004688 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCall550e0c22009-10-21 00:40:46 +00004690 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004691 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4692 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004693 if (Result.isNull())
4694 return QualType();
4695 }
Mike Stump11289f42009-09-09 15:08:12 +00004696
John McCall550e0c22009-10-21 00:40:46 +00004697 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004698 NewTL.setTypeofLoc(TL.getTypeofLoc());
4699 NewTL.setLParenLoc(TL.getLParenLoc());
4700 NewTL.setRParenLoc(TL.getRParenLoc());
4701 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004702
4703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704}
Mike Stump11289f42009-09-09 15:08:12 +00004705
4706template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004707QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004708 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004709 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004710
Douglas Gregore922c772009-08-04 22:27:00 +00004711 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004712 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4713 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004714
John McCalldadc5752010-08-24 06:29:42 +00004715 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004716 if (E.isInvalid())
4717 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004718
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004719 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004720 if (E.isInvalid())
4721 return QualType();
4722
John McCall550e0c22009-10-21 00:40:46 +00004723 QualType Result = TL.getType();
4724 if (getDerived().AlwaysRebuild() ||
4725 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004726 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004727 if (Result.isNull())
4728 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004729 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004730 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004731
John McCall550e0c22009-10-21 00:40:46 +00004732 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4733 NewTL.setNameLoc(TL.getNameLoc());
4734
4735 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004736}
4737
4738template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004739QualType TreeTransform<Derived>::TransformUnaryTransformType(
4740 TypeLocBuilder &TLB,
4741 UnaryTransformTypeLoc TL) {
4742 QualType Result = TL.getType();
4743 if (Result->isDependentType()) {
4744 const UnaryTransformType *T = TL.getTypePtr();
4745 QualType NewBase =
4746 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4747 Result = getDerived().RebuildUnaryTransformType(NewBase,
4748 T->getUTTKind(),
4749 TL.getKWLoc());
4750 if (Result.isNull())
4751 return QualType();
4752 }
4753
4754 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4755 NewTL.setKWLoc(TL.getKWLoc());
4756 NewTL.setParensRange(TL.getParensRange());
4757 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4758 return Result;
4759}
4760
4761template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004762QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4763 AutoTypeLoc TL) {
4764 const AutoType *T = TL.getTypePtr();
4765 QualType OldDeduced = T->getDeducedType();
4766 QualType NewDeduced;
4767 if (!OldDeduced.isNull()) {
4768 NewDeduced = getDerived().TransformType(OldDeduced);
4769 if (NewDeduced.isNull())
4770 return QualType();
4771 }
4772
4773 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004774 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4775 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004776 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004777 if (Result.isNull())
4778 return QualType();
4779 }
4780
4781 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4782 NewTL.setNameLoc(TL.getNameLoc());
4783
4784 return Result;
4785}
4786
4787template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004788QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004789 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004790 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004791 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004792 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4793 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004794 if (!Record)
4795 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004796
John McCall550e0c22009-10-21 00:40:46 +00004797 QualType Result = TL.getType();
4798 if (getDerived().AlwaysRebuild() ||
4799 Record != T->getDecl()) {
4800 Result = getDerived().RebuildRecordType(Record);
4801 if (Result.isNull())
4802 return QualType();
4803 }
Mike Stump11289f42009-09-09 15:08:12 +00004804
John McCall550e0c22009-10-21 00:40:46 +00004805 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4806 NewTL.setNameLoc(TL.getNameLoc());
4807
4808 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004809}
Mike Stump11289f42009-09-09 15:08:12 +00004810
4811template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004812QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004813 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004814 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004815 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004816 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4817 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004818 if (!Enum)
4819 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004820
John McCall550e0c22009-10-21 00:40:46 +00004821 QualType Result = TL.getType();
4822 if (getDerived().AlwaysRebuild() ||
4823 Enum != T->getDecl()) {
4824 Result = getDerived().RebuildEnumType(Enum);
4825 if (Result.isNull())
4826 return QualType();
4827 }
Mike Stump11289f42009-09-09 15:08:12 +00004828
John McCall550e0c22009-10-21 00:40:46 +00004829 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4830 NewTL.setNameLoc(TL.getNameLoc());
4831
4832 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004833}
John McCallfcc33b02009-09-05 00:15:47 +00004834
John McCalle78aac42010-03-10 03:28:59 +00004835template<typename Derived>
4836QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4837 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004838 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004839 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4840 TL.getTypePtr()->getDecl());
4841 if (!D) return QualType();
4842
4843 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4844 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4845 return T;
4846}
4847
Douglas Gregord6ff3322009-08-04 16:50:30 +00004848template<typename Derived>
4849QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004850 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004851 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004852 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004853}
4854
Mike Stump11289f42009-09-09 15:08:12 +00004855template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004856QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004857 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004858 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004859 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004860
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004861 // Substitute into the replacement type, which itself might involve something
4862 // that needs to be transformed. This only tends to occur with default
4863 // template arguments of template template parameters.
4864 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4865 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4866 if (Replacement.isNull())
4867 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004868
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004869 // Always canonicalize the replacement type.
4870 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4871 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004872 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004873 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004874
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004875 // Propagate type-source information.
4876 SubstTemplateTypeParmTypeLoc NewTL
4877 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4878 NewTL.setNameLoc(TL.getNameLoc());
4879 return Result;
4880
John McCallcebee162009-10-18 09:09:24 +00004881}
4882
4883template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004884QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4885 TypeLocBuilder &TLB,
4886 SubstTemplateTypeParmPackTypeLoc TL) {
4887 return TransformTypeSpecType(TLB, TL);
4888}
4889
4890template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004891QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004892 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004893 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004894 const TemplateSpecializationType *T = TL.getTypePtr();
4895
Douglas Gregordf846d12011-03-02 18:46:51 +00004896 // The nested-name-specifier never matters in a TemplateSpecializationType,
4897 // because we can't have a dependent nested-name-specifier anyway.
4898 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004899 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004900 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4901 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004902 if (Template.isNull())
4903 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004904
John McCall31f82722010-11-12 08:19:04 +00004905 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4906}
4907
Eli Friedman0dfb8892011-10-06 23:00:33 +00004908template<typename Derived>
4909QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4910 AtomicTypeLoc TL) {
4911 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4912 if (ValueType.isNull())
4913 return QualType();
4914
4915 QualType Result = TL.getType();
4916 if (getDerived().AlwaysRebuild() ||
4917 ValueType != TL.getValueLoc().getType()) {
4918 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4919 if (Result.isNull())
4920 return QualType();
4921 }
4922
4923 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4924 NewTL.setKWLoc(TL.getKWLoc());
4925 NewTL.setLParenLoc(TL.getLParenLoc());
4926 NewTL.setRParenLoc(TL.getRParenLoc());
4927
4928 return Result;
4929}
4930
Chad Rosier1dcde962012-08-08 18:46:20 +00004931 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004932 /// container that provides a \c getArgLoc() member function.
4933 ///
4934 /// This iterator is intended to be used with the iterator form of
4935 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4936 template<typename ArgLocContainer>
4937 class TemplateArgumentLocContainerIterator {
4938 ArgLocContainer *Container;
4939 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004940
Douglas Gregorfe921a72010-12-20 23:36:19 +00004941 public:
4942 typedef TemplateArgumentLoc value_type;
4943 typedef TemplateArgumentLoc reference;
4944 typedef int difference_type;
4945 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
Douglas Gregorfe921a72010-12-20 23:36:19 +00004947 class pointer {
4948 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
Douglas Gregorfe921a72010-12-20 23:36:19 +00004950 public:
4951 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004952
Douglas Gregorfe921a72010-12-20 23:36:19 +00004953 const TemplateArgumentLoc *operator->() const {
4954 return &Arg;
4955 }
4956 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004957
4958
Douglas Gregorfe921a72010-12-20 23:36:19 +00004959 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004960
Douglas Gregorfe921a72010-12-20 23:36:19 +00004961 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4962 unsigned Index)
4963 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004964
Douglas Gregorfe921a72010-12-20 23:36:19 +00004965 TemplateArgumentLocContainerIterator &operator++() {
4966 ++Index;
4967 return *this;
4968 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004969
Douglas Gregorfe921a72010-12-20 23:36:19 +00004970 TemplateArgumentLocContainerIterator operator++(int) {
4971 TemplateArgumentLocContainerIterator Old(*this);
4972 ++(*this);
4973 return Old;
4974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004975
Douglas Gregorfe921a72010-12-20 23:36:19 +00004976 TemplateArgumentLoc operator*() const {
4977 return Container->getArgLoc(Index);
4978 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004979
Douglas Gregorfe921a72010-12-20 23:36:19 +00004980 pointer operator->() const {
4981 return pointer(Container->getArgLoc(Index));
4982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004983
Douglas Gregorfe921a72010-12-20 23:36:19 +00004984 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004985 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004986 return X.Container == Y.Container && X.Index == Y.Index;
4987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004988
Douglas Gregorfe921a72010-12-20 23:36:19 +00004989 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004990 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004991 return !(X == Y);
4992 }
4993 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004994
4995
John McCall31f82722010-11-12 08:19:04 +00004996template <typename Derived>
4997QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4998 TypeLocBuilder &TLB,
4999 TemplateSpecializationTypeLoc TL,
5000 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005001 TemplateArgumentListInfo NewTemplateArgs;
5002 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5003 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005004 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5005 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005006 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005007 ArgIterator(TL, TL.getNumArgs()),
5008 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005009 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005010
John McCall0ad16662009-10-29 08:12:44 +00005011 // FIXME: maybe don't rebuild if all the template arguments are the same.
5012
5013 QualType Result =
5014 getDerived().RebuildTemplateSpecializationType(Template,
5015 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005016 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005017
5018 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005019 // Specializations of template template parameters are represented as
5020 // TemplateSpecializationTypes, and substitution of type alias templates
5021 // within a dependent context can transform them into
5022 // DependentTemplateSpecializationTypes.
5023 if (isa<DependentTemplateSpecializationType>(Result)) {
5024 DependentTemplateSpecializationTypeLoc NewTL
5025 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005026 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005027 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005028 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005029 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005030 NewTL.setLAngleLoc(TL.getLAngleLoc());
5031 NewTL.setRAngleLoc(TL.getRAngleLoc());
5032 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5033 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5034 return Result;
5035 }
5036
John McCall0ad16662009-10-29 08:12:44 +00005037 TemplateSpecializationTypeLoc NewTL
5038 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005039 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005040 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5041 NewTL.setLAngleLoc(TL.getLAngleLoc());
5042 NewTL.setRAngleLoc(TL.getRAngleLoc());
5043 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5044 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005045 }
Mike Stump11289f42009-09-09 15:08:12 +00005046
John McCall0ad16662009-10-29 08:12:44 +00005047 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregor5a064722011-02-28 17:23:35 +00005050template <typename Derived>
5051QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5052 TypeLocBuilder &TLB,
5053 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005054 TemplateName Template,
5055 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005056 TemplateArgumentListInfo NewTemplateArgs;
5057 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5058 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5059 typedef TemplateArgumentLocContainerIterator<
5060 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005061 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005062 ArgIterator(TL, TL.getNumArgs()),
5063 NewTemplateArgs))
5064 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005065
Douglas Gregor5a064722011-02-28 17:23:35 +00005066 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005067
Douglas Gregor5a064722011-02-28 17:23:35 +00005068 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5069 QualType Result
5070 = getSema().Context.getDependentTemplateSpecializationType(
5071 TL.getTypePtr()->getKeyword(),
5072 DTN->getQualifier(),
5073 DTN->getIdentifier(),
5074 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005075
Douglas Gregor5a064722011-02-28 17:23:35 +00005076 DependentTemplateSpecializationTypeLoc NewTL
5077 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005078 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005079 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005080 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005081 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005082 NewTL.setLAngleLoc(TL.getLAngleLoc());
5083 NewTL.setRAngleLoc(TL.getRAngleLoc());
5084 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5085 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5086 return Result;
5087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005088
5089 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005090 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005091 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005092 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005093
Douglas Gregor5a064722011-02-28 17:23:35 +00005094 if (!Result.isNull()) {
5095 /// FIXME: Wrap this in an elaborated-type-specifier?
5096 TemplateSpecializationTypeLoc NewTL
5097 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005098 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005099 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005100 NewTL.setLAngleLoc(TL.getLAngleLoc());
5101 NewTL.setRAngleLoc(TL.getRAngleLoc());
5102 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5103 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5104 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005105
Douglas Gregor5a064722011-02-28 17:23:35 +00005106 return Result;
5107}
5108
Mike Stump11289f42009-09-09 15:08:12 +00005109template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005110QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005111TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005112 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005113 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005114
Douglas Gregor844cb502011-03-01 18:12:44 +00005115 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005116 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005117 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005118 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005119 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5120 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005121 return QualType();
5122 }
Mike Stump11289f42009-09-09 15:08:12 +00005123
John McCall31f82722010-11-12 08:19:04 +00005124 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5125 if (NamedT.isNull())
5126 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005127
Richard Smith3f1b5d02011-05-05 21:57:07 +00005128 // C++0x [dcl.type.elab]p2:
5129 // If the identifier resolves to a typedef-name or the simple-template-id
5130 // resolves to an alias template specialization, the
5131 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005132 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5133 if (const TemplateSpecializationType *TST =
5134 NamedT->getAs<TemplateSpecializationType>()) {
5135 TemplateName Template = TST->getTemplateName();
5136 if (TypeAliasTemplateDecl *TAT =
5137 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5138 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5139 diag::err_tag_reference_non_tag) << 4;
5140 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5141 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005142 }
5143 }
5144
John McCall550e0c22009-10-21 00:40:46 +00005145 QualType Result = TL.getType();
5146 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005147 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005148 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005149 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005150 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005151 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005152 if (Result.isNull())
5153 return QualType();
5154 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005155
Abramo Bagnara6150c882010-05-11 21:36:43 +00005156 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005157 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005158 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005159 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005160}
Mike Stump11289f42009-09-09 15:08:12 +00005161
5162template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005163QualType TreeTransform<Derived>::TransformAttributedType(
5164 TypeLocBuilder &TLB,
5165 AttributedTypeLoc TL) {
5166 const AttributedType *oldType = TL.getTypePtr();
5167 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5168 if (modifiedType.isNull())
5169 return QualType();
5170
5171 QualType result = TL.getType();
5172
5173 // FIXME: dependent operand expressions?
5174 if (getDerived().AlwaysRebuild() ||
5175 modifiedType != oldType->getModifiedType()) {
5176 // TODO: this is really lame; we should really be rebuilding the
5177 // equivalent type from first principles.
5178 QualType equivalentType
5179 = getDerived().TransformType(oldType->getEquivalentType());
5180 if (equivalentType.isNull())
5181 return QualType();
5182 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5183 modifiedType,
5184 equivalentType);
5185 }
5186
5187 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5188 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5189 if (TL.hasAttrOperand())
5190 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5191 if (TL.hasAttrExprOperand())
5192 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5193 else if (TL.hasAttrEnumOperand())
5194 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5195
5196 return result;
5197}
5198
5199template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005200QualType
5201TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5202 ParenTypeLoc TL) {
5203 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5204 if (Inner.isNull())
5205 return QualType();
5206
5207 QualType Result = TL.getType();
5208 if (getDerived().AlwaysRebuild() ||
5209 Inner != TL.getInnerLoc().getType()) {
5210 Result = getDerived().RebuildParenType(Inner);
5211 if (Result.isNull())
5212 return QualType();
5213 }
5214
5215 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5216 NewTL.setLParenLoc(TL.getLParenLoc());
5217 NewTL.setRParenLoc(TL.getRParenLoc());
5218 return Result;
5219}
5220
5221template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005222QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005223 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005224 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005225
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005226 NestedNameSpecifierLoc QualifierLoc
5227 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5228 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005229 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005230
John McCallc392f372010-06-11 00:33:02 +00005231 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005232 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005233 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005234 QualifierLoc,
5235 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005236 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005237 if (Result.isNull())
5238 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005239
Abramo Bagnarad7548482010-05-19 21:37:53 +00005240 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5241 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005242 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5243
Abramo Bagnarad7548482010-05-19 21:37:53 +00005244 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005245 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005246 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005247 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005248 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005249 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005250 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005251 NewTL.setNameLoc(TL.getNameLoc());
5252 }
John McCall550e0c22009-10-21 00:40:46 +00005253 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005254}
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005257QualType TreeTransform<Derived>::
5258 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005259 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005260 NestedNameSpecifierLoc QualifierLoc;
5261 if (TL.getQualifierLoc()) {
5262 QualifierLoc
5263 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5264 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005265 return QualType();
5266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005267
John McCall31f82722010-11-12 08:19:04 +00005268 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005269 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005270}
5271
5272template<typename Derived>
5273QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005274TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5275 DependentTemplateSpecializationTypeLoc TL,
5276 NestedNameSpecifierLoc QualifierLoc) {
5277 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005278
Douglas Gregora7a795b2011-03-01 20:11:18 +00005279 TemplateArgumentListInfo NewTemplateArgs;
5280 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5281 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregora7a795b2011-03-01 20:11:18 +00005283 typedef TemplateArgumentLocContainerIterator<
5284 DependentTemplateSpecializationTypeLoc> ArgIterator;
5285 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5286 ArgIterator(TL, TL.getNumArgs()),
5287 NewTemplateArgs))
5288 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005289
Douglas Gregora7a795b2011-03-01 20:11:18 +00005290 QualType Result
5291 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5292 QualifierLoc,
5293 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005294 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005295 NewTemplateArgs);
5296 if (Result.isNull())
5297 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005298
Douglas Gregora7a795b2011-03-01 20:11:18 +00005299 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5300 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005301
Douglas Gregora7a795b2011-03-01 20:11:18 +00005302 // Copy information relevant to the template specialization.
5303 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005304 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005305 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005306 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005307 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5308 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005309 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005310 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005311
Douglas Gregora7a795b2011-03-01 20:11:18 +00005312 // Copy information relevant to the elaborated type.
5313 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005314 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005315 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005316 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5317 DependentTemplateSpecializationTypeLoc SpecTL
5318 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005319 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005320 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005321 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005322 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005323 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5324 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005325 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005326 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005327 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005328 TemplateSpecializationTypeLoc SpecTL
5329 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005330 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005331 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005332 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5333 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005334 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005335 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005336 }
5337 return Result;
5338}
5339
5340template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005341QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5342 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005343 QualType Pattern
5344 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005345 if (Pattern.isNull())
5346 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005347
5348 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005349 if (getDerived().AlwaysRebuild() ||
5350 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005351 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005352 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005353 TL.getEllipsisLoc(),
5354 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005355 if (Result.isNull())
5356 return QualType();
5357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005358
Douglas Gregor822d0302011-01-12 17:07:58 +00005359 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5360 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5361 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005362}
5363
5364template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005365QualType
5366TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005367 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005368 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005369 TLB.pushFullCopy(TL);
5370 return TL.getType();
5371}
5372
5373template<typename Derived>
5374QualType
5375TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005376 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005377 // ObjCObjectType is never dependent.
5378 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005379 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380}
Mike Stump11289f42009-09-09 15:08:12 +00005381
5382template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005383QualType
5384TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005385 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005386 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005387 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005388 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005389}
5390
Douglas Gregord6ff3322009-08-04 16:50:30 +00005391//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005392// Statement transformation
5393//===----------------------------------------------------------------------===//
5394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005397 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005398}
5399
5400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005401StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005402TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5403 return getDerived().TransformCompoundStmt(S, false);
5404}
5405
5406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005407StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005408TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005409 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005410 Sema::CompoundScopeRAII CompoundScope(getSema());
5411
John McCall1ababa62010-08-27 19:56:05 +00005412 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005413 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005414 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005415 for (auto *B : S->body()) {
5416 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005417 if (Result.isInvalid()) {
5418 // Immediately fail if this was a DeclStmt, since it's very
5419 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005420 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005421 return StmtError();
5422
5423 // Otherwise, just keep processing substatements and fail later.
5424 SubStmtInvalid = true;
5425 continue;
5426 }
Mike Stump11289f42009-09-09 15:08:12 +00005427
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005428 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005429 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005430 }
Mike Stump11289f42009-09-09 15:08:12 +00005431
John McCall1ababa62010-08-27 19:56:05 +00005432 if (SubStmtInvalid)
5433 return StmtError();
5434
Douglas Gregorebe10102009-08-20 07:17:43 +00005435 if (!getDerived().AlwaysRebuild() &&
5436 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005437 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005438
5439 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005440 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 S->getRBracLoc(),
5442 IsStmtExpr);
5443}
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregorebe10102009-08-20 07:17:43 +00005445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005446StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005447TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005448 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005449 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005450 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5451 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005452
Eli Friedman06577382009-11-19 03:14:00 +00005453 // Transform the left-hand case value.
5454 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005455 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005456 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005458
Eli Friedman06577382009-11-19 03:14:00 +00005459 // Transform the right-hand case value (for the GNU case-range extension).
5460 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005461 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005462 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005463 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005464 }
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 // Build the case statement.
5467 // Case statements are always rebuilt so that they will attached to their
5468 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005469 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005470 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005471 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005472 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005473 S->getColonLoc());
5474 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005475 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005476
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005478 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005480 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregorebe10102009-08-20 07:17:43 +00005482 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005483 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005484}
5485
5486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005487StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005488TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005489 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005490 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005491 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 // Default statements are always rebuilt
5495 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005496 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005497}
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregorebe10102009-08-20 07:17:43 +00005499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005500StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005501TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005502 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005505
Chris Lattnercab02a62011-02-17 20:34:02 +00005506 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5507 S->getDecl());
5508 if (!LD)
5509 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005510
5511
Douglas Gregorebe10102009-08-20 07:17:43 +00005512 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005513 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005514 cast<LabelDecl>(LD), SourceLocation(),
5515 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005516}
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregorebe10102009-08-20 07:17:43 +00005518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005519StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005520TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5521 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5522 if (SubStmt.isInvalid())
5523 return StmtError();
5524
5525 // TODO: transform attributes
5526 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5527 return S;
5528
5529 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5530 S->getAttrs(),
5531 SubStmt.get());
5532}
5533
5534template<typename Derived>
5535StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005536TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005537 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005538 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005539 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005540 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005541 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005542 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005543 getDerived().TransformDefinition(
5544 S->getConditionVariable()->getLocation(),
5545 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005546 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005547 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005548 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005549 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005550
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005551 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005552 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005553
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005554 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005555 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005556 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005557 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005558 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005559 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005560
John McCallb268a282010-08-23 23:25:46 +00005561 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005562 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005564
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005565 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005566 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005568
Douglas Gregorebe10102009-08-20 07:17:43 +00005569 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005570 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005572 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregorebe10102009-08-20 07:17:43 +00005574 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005575 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005576 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005577 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregorebe10102009-08-20 07:17:43 +00005579 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005580 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005581 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005582 Then.get() == S->getThen() &&
5583 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005584 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005586 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005587 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005588 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005589}
5590
5591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005592StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005593TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005594 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005595 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005596 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005597 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005598 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005599 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005600 getDerived().TransformDefinition(
5601 S->getConditionVariable()->getLocation(),
5602 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005603 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005605 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005606 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005607
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005608 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005610 }
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005613 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005614 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005615 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005616 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005617 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregorebe10102009-08-20 07:17:43 +00005619 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005620 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005622 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005625 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5626 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005627}
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregorebe10102009-08-20 07:17:43 +00005629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005630StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005632 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005633 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005634 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005635 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005636 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005637 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005638 getDerived().TransformDefinition(
5639 S->getConditionVariable()->getLocation(),
5640 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005641 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005642 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005643 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005644 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005645
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005646 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005648
5649 if (S->getCond()) {
5650 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005651 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5652 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005653 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005654 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005655 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005656 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005657 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005660 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005661 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005663
Douglas Gregorebe10102009-08-20 07:17:43 +00005664 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005665 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005667 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregorebe10102009-08-20 07:17:43 +00005669 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005670 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005671 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005672 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005673 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005674
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005675 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005676 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005677}
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregorebe10102009-08-20 07:17:43 +00005679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005680StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005681TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005682 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005683 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005685 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005687 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005688 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005689 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005691
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 if (!getDerived().AlwaysRebuild() &&
5693 Cond.get() == S->getCond() &&
5694 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005695 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005696
John McCallb268a282010-08-23 23:25:46 +00005697 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5698 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005699 S->getRParenLoc());
5700}
Mike Stump11289f42009-09-09 15:08:12 +00005701
Douglas Gregorebe10102009-08-20 07:17:43 +00005702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005703StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005704TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005705 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005706 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005707 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005708 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005711 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005712 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005713 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005714 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005715 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005716 getDerived().TransformDefinition(
5717 S->getConditionVariable()->getLocation(),
5718 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005719 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005721 } else {
5722 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005724 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005725 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005726
5727 if (S->getCond()) {
5728 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005729 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5730 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005731 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005732 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005733 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005734
John McCallb268a282010-08-23 23:25:46 +00005735 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005736 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005737 }
Mike Stump11289f42009-09-09 15:08:12 +00005738
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005739 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005740 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005742
Douglas Gregorebe10102009-08-20 07:17:43 +00005743 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005744 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005745 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005746 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005747
Richard Smith945f8d32013-01-14 22:39:08 +00005748 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005749 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005751
Douglas Gregorebe10102009-08-20 07:17:43 +00005752 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005753 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005754 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005755 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005756
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 if (!getDerived().AlwaysRebuild() &&
5758 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005759 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005760 Inc.get() == S->getInc() &&
5761 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005762 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregorebe10102009-08-20 07:17:43 +00005764 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005765 Init.get(), FullCond, ConditionVar,
5766 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005767}
5768
5769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005770StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005771TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005772 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5773 S->getLabel());
5774 if (!LD)
5775 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005776
Douglas Gregorebe10102009-08-20 07:17:43 +00005777 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005778 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005779 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005780}
5781
5782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005783StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005784TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005785 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005786 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005787 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005788 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregorebe10102009-08-20 07:17:43 +00005790 if (!getDerived().AlwaysRebuild() &&
5791 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005792 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005793
5794 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005795 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005796}
5797
5798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005799StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005800TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005801 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005802}
Mike Stump11289f42009-09-09 15:08:12 +00005803
Douglas Gregorebe10102009-08-20 07:17:43 +00005804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005805StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005806TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005807 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005808}
Mike Stump11289f42009-09-09 15:08:12 +00005809
Douglas Gregorebe10102009-08-20 07:17:43 +00005810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005811StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005812TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005813 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005814 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005816
Mike Stump11289f42009-09-09 15:08:12 +00005817 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005819 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005820}
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregorebe10102009-08-20 07:17:43 +00005822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005824TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005826 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005827 for (auto *D : S->decls()) {
5828 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005829 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005830 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005831
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005832 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005833 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregorebe10102009-08-20 07:17:43 +00005835 Decls.push_back(Transformed);
5836 }
Mike Stump11289f42009-09-09 15:08:12 +00005837
Douglas Gregorebe10102009-08-20 07:17:43 +00005838 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005839 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005840
Rafael Espindolaab417692013-07-09 12:05:01 +00005841 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005842}
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregorebe10102009-08-20 07:17:43 +00005844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005845StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005846TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005847
Benjamin Kramerf0623432012-08-23 22:51:59 +00005848 SmallVector<Expr*, 8> Constraints;
5849 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005850 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005851
John McCalldadc5752010-08-24 06:29:42 +00005852 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005853 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005854
5855 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005856
Anders Carlssonaaeef072010-01-24 05:50:09 +00005857 // Go through the outputs.
5858 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005859 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005860
Anders Carlssonaaeef072010-01-24 05:50:09 +00005861 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005862 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Anders Carlssonaaeef072010-01-24 05:50:09 +00005864 // Transform the output expr.
5865 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005866 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005867 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005869
Anders Carlssonaaeef072010-01-24 05:50:09 +00005870 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
John McCallb268a282010-08-23 23:25:46 +00005872 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
Anders Carlssonaaeef072010-01-24 05:50:09 +00005875 // Go through the inputs.
5876 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005877 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005878
Anders Carlssonaaeef072010-01-24 05:50:09 +00005879 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005880 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
Anders Carlssonaaeef072010-01-24 05:50:09 +00005882 // Transform the input expr.
5883 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005884 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005885 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005887
Anders Carlssonaaeef072010-01-24 05:50:09 +00005888 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005889
John McCallb268a282010-08-23 23:25:46 +00005890 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Anders Carlssonaaeef072010-01-24 05:50:09 +00005893 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005894 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005895
5896 // Go through the clobbers.
5897 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005898 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005899
5900 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005901 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005902 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5903 S->isVolatile(), S->getNumOutputs(),
5904 S->getNumInputs(), Names.data(),
5905 Constraints, Exprs, AsmString.get(),
5906 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005907}
5908
Chad Rosier32503022012-06-11 20:47:18 +00005909template<typename Derived>
5910StmtResult
5911TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005912 ArrayRef<Token> AsmToks =
5913 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005914
John McCallf413f5e2013-05-03 00:10:13 +00005915 bool HadError = false, HadChange = false;
5916
5917 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5918 SmallVector<Expr*, 8> TransformedExprs;
5919 TransformedExprs.reserve(SrcExprs.size());
5920 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5921 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5922 if (!Result.isUsable()) {
5923 HadError = true;
5924 } else {
5925 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005926 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005927 }
5928 }
5929
5930 if (HadError) return StmtError();
5931 if (!HadChange && !getDerived().AlwaysRebuild())
5932 return Owned(S);
5933
Chad Rosierb6f46c12012-08-15 16:53:30 +00005934 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005935 AsmToks, S->getAsmString(),
5936 S->getNumOutputs(), S->getNumInputs(),
5937 S->getAllConstraints(), S->getClobbers(),
5938 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005939}
Douglas Gregorebe10102009-08-20 07:17:43 +00005940
5941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005942StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005943TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005944 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005945 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005946 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005948
Douglas Gregor96c79492010-04-23 22:50:49 +00005949 // Transform the @catch statements (if present).
5950 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005951 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005952 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005953 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005954 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005955 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005956 if (Catch.get() != S->getCatchStmt(I))
5957 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005958 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005960
Douglas Gregor306de2f2010-04-22 23:59:56 +00005961 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005962 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005963 if (S->getFinallyStmt()) {
5964 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5965 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005966 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005967 }
5968
5969 // If nothing changed, just retain this statement.
5970 if (!getDerived().AlwaysRebuild() &&
5971 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005972 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005973 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005974 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005975
Douglas Gregor306de2f2010-04-22 23:59:56 +00005976 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005977 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005978 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005979}
Mike Stump11289f42009-09-09 15:08:12 +00005980
Douglas Gregorebe10102009-08-20 07:17:43 +00005981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005982StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005983TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005984 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005985 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005986 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005987 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005988 if (FromVar->getTypeSourceInfo()) {
5989 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5990 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005993
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005994 QualType T;
5995 if (TSInfo)
5996 T = TSInfo->getType();
5997 else {
5998 T = getDerived().TransformType(FromVar->getType());
5999 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006000 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006002
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006003 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6004 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
John McCalldadc5752010-08-24 06:29:42 +00006008 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006009 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006010 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006011
6012 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006013 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006014 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006015}
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregorebe10102009-08-20 07:17:43 +00006017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006018StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006019TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006020 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006021 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006022 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006023 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006024
Douglas Gregor306de2f2010-04-22 23:59:56 +00006025 // If nothing changed, just retain this statement.
6026 if (!getDerived().AlwaysRebuild() &&
6027 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006028 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006029
6030 // Build a new statement.
6031 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006032 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregorebe10102009-08-20 07:17:43 +00006035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006036StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006037TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006038 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006039 if (S->getThrowExpr()) {
6040 Operand = getDerived().TransformExpr(S->getThrowExpr());
6041 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006043 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006044
Douglas Gregor2900c162010-04-22 21:44:01 +00006045 if (!getDerived().AlwaysRebuild() &&
6046 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006047 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006048
John McCallb268a282010-08-23 23:25:46 +00006049 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006050}
Mike Stump11289f42009-09-09 15:08:12 +00006051
Douglas Gregorebe10102009-08-20 07:17:43 +00006052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006053StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006054TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006055 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006056 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006057 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006058 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006059 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006060 Object =
6061 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6062 Object.get());
6063 if (Object.isInvalid())
6064 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006065
Douglas Gregor6148de72010-04-22 22:01:21 +00006066 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006067 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006068 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006069 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006070
Douglas Gregor6148de72010-04-22 22:01:21 +00006071 // If nothing change, just retain the current statement.
6072 if (!getDerived().AlwaysRebuild() &&
6073 Object.get() == S->getSynchExpr() &&
6074 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006075 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006076
6077 // Build a new statement.
6078 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006079 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006080}
6081
6082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006083StmtResult
John McCall31168b02011-06-15 23:02:42 +00006084TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6085 ObjCAutoreleasePoolStmt *S) {
6086 // Transform the body.
6087 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6088 if (Body.isInvalid())
6089 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006090
John McCall31168b02011-06-15 23:02:42 +00006091 // If nothing changed, just retain this statement.
6092 if (!getDerived().AlwaysRebuild() &&
6093 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006094 return S;
John McCall31168b02011-06-15 23:02:42 +00006095
6096 // Build a new statement.
6097 return getDerived().RebuildObjCAutoreleasePoolStmt(
6098 S->getAtLoc(), Body.get());
6099}
6100
6101template<typename Derived>
6102StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006103TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006104 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006105 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006106 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006107 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006108 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006109
Douglas Gregorf68a5082010-04-22 23:10:45 +00006110 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006111 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006112 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006114
Douglas Gregorf68a5082010-04-22 23:10:45 +00006115 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006116 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006117 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
Douglas Gregorf68a5082010-04-22 23:10:45 +00006120 // If nothing changed, just retain this statement.
6121 if (!getDerived().AlwaysRebuild() &&
6122 Element.get() == S->getElement() &&
6123 Collection.get() == S->getCollection() &&
6124 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006125 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
Douglas Gregorf68a5082010-04-22 23:10:45 +00006127 // Build a new statement.
6128 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006129 Element.get(),
6130 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006131 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006132 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006133}
6134
David Majnemer5f7efef2013-10-15 09:50:08 +00006135template <typename Derived>
6136StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006138 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006139 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6140 TypeSourceInfo *T =
6141 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006142 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006144
David Majnemer5f7efef2013-10-15 09:50:08 +00006145 Var = getDerived().RebuildExceptionDecl(
6146 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6147 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006148 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006150 }
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregorebe10102009-08-20 07:17:43 +00006152 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006153 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006154 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006156
David Majnemer5f7efef2013-10-15 09:50:08 +00006157 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006158 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006159 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006160
David Majnemer5f7efef2013-10-15 09:50:08 +00006161 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006162}
Mike Stump11289f42009-09-09 15:08:12 +00006163
David Majnemer5f7efef2013-10-15 09:50:08 +00006164template <typename Derived>
6165StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006167 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006168 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006170
Douglas Gregorebe10102009-08-20 07:17:43 +00006171 // Transform the handlers.
6172 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006173 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006174 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006175 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006176 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006177 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006178
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006180 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 }
Mike Stump11289f42009-09-09 15:08:12 +00006182
David Majnemer5f7efef2013-10-15 09:50:08 +00006183 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006184 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006185 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006186
John McCallb268a282010-08-23 23:25:46 +00006187 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006188 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006189}
Mike Stump11289f42009-09-09 15:08:12 +00006190
Richard Smith02e85f32011-04-14 22:09:26 +00006191template<typename Derived>
6192StmtResult
6193TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6194 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6195 if (Range.isInvalid())
6196 return StmtError();
6197
6198 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6199 if (BeginEnd.isInvalid())
6200 return StmtError();
6201
6202 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6203 if (Cond.isInvalid())
6204 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006205 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006206 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006207 if (Cond.isInvalid())
6208 return StmtError();
6209 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006210 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006211
6212 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6213 if (Inc.isInvalid())
6214 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006215 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006216 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006217
6218 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6219 if (LoopVar.isInvalid())
6220 return StmtError();
6221
6222 StmtResult NewStmt = S;
6223 if (getDerived().AlwaysRebuild() ||
6224 Range.get() != S->getRangeStmt() ||
6225 BeginEnd.get() != S->getBeginEndStmt() ||
6226 Cond.get() != S->getCond() ||
6227 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006228 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006229 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6230 S->getColonLoc(), Range.get(),
6231 BeginEnd.get(), Cond.get(),
6232 Inc.get(), LoopVar.get(),
6233 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006234 if (NewStmt.isInvalid())
6235 return StmtError();
6236 }
Richard Smith02e85f32011-04-14 22:09:26 +00006237
6238 StmtResult Body = getDerived().TransformStmt(S->getBody());
6239 if (Body.isInvalid())
6240 return StmtError();
6241
6242 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6243 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006244 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006245 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6246 S->getColonLoc(), Range.get(),
6247 BeginEnd.get(), Cond.get(),
6248 Inc.get(), LoopVar.get(),
6249 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006250 if (NewStmt.isInvalid())
6251 return StmtError();
6252 }
Richard Smith02e85f32011-04-14 22:09:26 +00006253
6254 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006255 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006256
6257 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6258}
6259
John Wiegley1c0675e2011-04-28 01:08:34 +00006260template<typename Derived>
6261StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006262TreeTransform<Derived>::TransformMSDependentExistsStmt(
6263 MSDependentExistsStmt *S) {
6264 // Transform the nested-name-specifier, if any.
6265 NestedNameSpecifierLoc QualifierLoc;
6266 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006267 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006268 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6269 if (!QualifierLoc)
6270 return StmtError();
6271 }
6272
6273 // Transform the declaration name.
6274 DeclarationNameInfo NameInfo = S->getNameInfo();
6275 if (NameInfo.getName()) {
6276 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6277 if (!NameInfo.getName())
6278 return StmtError();
6279 }
6280
6281 // Check whether anything changed.
6282 if (!getDerived().AlwaysRebuild() &&
6283 QualifierLoc == S->getQualifierLoc() &&
6284 NameInfo.getName() == S->getNameInfo().getName())
6285 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006286
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006287 // Determine whether this name exists, if we can.
6288 CXXScopeSpec SS;
6289 SS.Adopt(QualifierLoc);
6290 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006291 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006292 case Sema::IER_Exists:
6293 if (S->isIfExists())
6294 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006295
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006296 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6297
6298 case Sema::IER_DoesNotExist:
6299 if (S->isIfNotExists())
6300 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006301
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006302 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006303
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006304 case Sema::IER_Dependent:
6305 Dependent = true;
6306 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006307
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006308 case Sema::IER_Error:
6309 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006310 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006311
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006312 // We need to continue with the instantiation, so do so now.
6313 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6314 if (SubStmt.isInvalid())
6315 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006316
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006317 // If we have resolved the name, just transform to the substatement.
6318 if (!Dependent)
6319 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006320
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006321 // The name is still dependent, so build a dependent expression again.
6322 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6323 S->isIfExists(),
6324 QualifierLoc,
6325 NameInfo,
6326 SubStmt.get());
6327}
6328
6329template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006330ExprResult
6331TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6332 NestedNameSpecifierLoc QualifierLoc;
6333 if (E->getQualifierLoc()) {
6334 QualifierLoc
6335 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6336 if (!QualifierLoc)
6337 return ExprError();
6338 }
6339
6340 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6341 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6342 if (!PD)
6343 return ExprError();
6344
6345 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6346 if (Base.isInvalid())
6347 return ExprError();
6348
6349 return new (SemaRef.getASTContext())
6350 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6351 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6352 QualifierLoc, E->getMemberLoc());
6353}
6354
David Majnemerfad8f482013-10-15 09:33:02 +00006355template <typename Derived>
6356StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006357 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006358 if (TryBlock.isInvalid())
6359 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006360
6361 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006362 if (Handler.isInvalid())
6363 return StmtError();
6364
David Majnemerfad8f482013-10-15 09:33:02 +00006365 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6366 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006367 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006368
David Majnemerfad8f482013-10-15 09:33:02 +00006369 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006370 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006371}
6372
David Majnemerfad8f482013-10-15 09:33:02 +00006373template <typename Derived>
6374StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006375 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006376 if (Block.isInvalid())
6377 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006378
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006379 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006380}
6381
David Majnemerfad8f482013-10-15 09:33:02 +00006382template <typename Derived>
6383StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006384 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006385 if (FilterExpr.isInvalid())
6386 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006387
David Majnemer7e755502013-10-15 09:30:14 +00006388 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006389 if (Block.isInvalid())
6390 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006391
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006392 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6393 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006394}
6395
David Majnemerfad8f482013-10-15 09:33:02 +00006396template <typename Derived>
6397StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6398 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006399 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6400 else
6401 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6402}
6403
Nico Weber9b982072014-07-07 00:12:30 +00006404template<typename Derived>
6405StmtResult
6406TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6407 return S;
6408}
6409
Alexander Musman64d33f12014-06-04 07:53:32 +00006410//===----------------------------------------------------------------------===//
6411// OpenMP directive transformation
6412//===----------------------------------------------------------------------===//
6413template <typename Derived>
6414StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6415 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006416
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006417 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006418 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006419 ArrayRef<OMPClause *> Clauses = D->clauses();
6420 TClauses.reserve(Clauses.size());
6421 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6422 I != E; ++I) {
6423 if (*I) {
6424 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006425 if (Clause)
6426 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006427 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006428 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006429 }
6430 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006431 StmtResult AssociatedStmt;
6432 if (D->hasAssociatedStmt()) {
6433 if (!D->getAssociatedStmt()) {
6434 return StmtError();
6435 }
6436 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6437 if (AssociatedStmt.isInvalid()) {
6438 return StmtError();
6439 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006440 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006441 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006442 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006443 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006444
Alexander Musman64d33f12014-06-04 07:53:32 +00006445 return getDerived().RebuildOMPExecutableDirective(
6446 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6447 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006448}
6449
Alexander Musman64d33f12014-06-04 07:53:32 +00006450template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006451StmtResult
6452TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6453 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006454 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6455 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006456 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6457 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6458 return Res;
6459}
6460
Alexander Musman64d33f12014-06-04 07:53:32 +00006461template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006462StmtResult
6463TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6464 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006465 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6466 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006467 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6468 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006469 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006470}
6471
Alexey Bataevf29276e2014-06-18 04:14:57 +00006472template <typename Derived>
6473StmtResult
6474TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6475 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006476 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6477 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006478 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6479 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6480 return Res;
6481}
6482
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006483template <typename Derived>
6484StmtResult
6485TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6486 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006487 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6488 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006489 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6490 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6491 return Res;
6492}
6493
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006494template <typename Derived>
6495StmtResult
6496TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6497 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006498 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6499 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006500 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6501 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6502 return Res;
6503}
6504
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006505template <typename Derived>
6506StmtResult
6507TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6508 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006509 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6510 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006511 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6512 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6513 return Res;
6514}
6515
Alexey Bataev4acb8592014-07-07 13:01:15 +00006516template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006517StmtResult
6518TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6519 DeclarationNameInfo DirName;
6520 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6521 D->getLocStart());
6522 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6523 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6524 return Res;
6525}
6526
6527template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006528StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6529 OMPParallelForDirective *D) {
6530 DeclarationNameInfo DirName;
6531 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6532 nullptr, D->getLocStart());
6533 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6534 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6535 return Res;
6536}
6537
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006538template <typename Derived>
6539StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6540 OMPParallelSectionsDirective *D) {
6541 DeclarationNameInfo DirName;
6542 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6543 nullptr, D->getLocStart());
6544 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6545 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6546 return Res;
6547}
6548
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006549template <typename Derived>
6550StmtResult
6551TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6552 DeclarationNameInfo DirName;
6553 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6554 D->getLocStart());
6555 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6556 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6557 return Res;
6558}
6559
Alexey Bataev68446b72014-07-18 07:47:19 +00006560template <typename Derived>
6561StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6562 OMPTaskyieldDirective *D) {
6563 DeclarationNameInfo DirName;
6564 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6565 D->getLocStart());
6566 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6567 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6568 return Res;
6569}
6570
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006571template <typename Derived>
6572StmtResult
6573TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6574 DeclarationNameInfo DirName;
6575 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6576 D->getLocStart());
6577 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6578 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6579 return Res;
6580}
6581
Alexander Musman64d33f12014-06-04 07:53:32 +00006582//===----------------------------------------------------------------------===//
6583// OpenMP clause transformation
6584//===----------------------------------------------------------------------===//
6585template <typename Derived>
6586OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006587 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6588 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006589 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006590 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006591 C->getLParenLoc(), C->getLocEnd());
6592}
6593
Alexander Musman64d33f12014-06-04 07:53:32 +00006594template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006595OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6596 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6597 if (Cond.isInvalid())
6598 return nullptr;
6599 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6600 C->getLParenLoc(), C->getLocEnd());
6601}
6602
6603template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006604OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006605TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6606 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6607 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006608 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006609 return getDerived().RebuildOMPNumThreadsClause(
6610 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006611}
6612
Alexey Bataev62c87d22014-03-21 04:51:18 +00006613template <typename Derived>
6614OMPClause *
6615TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6616 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6617 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006618 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006619 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006620 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006621}
6622
Alexander Musman8bd31e62014-05-27 15:12:19 +00006623template <typename Derived>
6624OMPClause *
6625TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6626 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6627 if (E.isInvalid())
6628 return 0;
6629 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006630 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006631}
6632
Alexander Musman64d33f12014-06-04 07:53:32 +00006633template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006634OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006635TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006636 return getDerived().RebuildOMPDefaultClause(
6637 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6638 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006639}
6640
Alexander Musman64d33f12014-06-04 07:53:32 +00006641template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006642OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006643TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006644 return getDerived().RebuildOMPProcBindClause(
6645 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6646 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006647}
6648
Alexander Musman64d33f12014-06-04 07:53:32 +00006649template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006650OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006651TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6652 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6653 if (E.isInvalid())
6654 return nullptr;
6655 return getDerived().RebuildOMPScheduleClause(
6656 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6657 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6658}
6659
6660template <typename Derived>
6661OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006662TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6663 // No need to rebuild this clause, no template-dependent parameters.
6664 return C;
6665}
6666
6667template <typename Derived>
6668OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006669TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6670 // No need to rebuild this clause, no template-dependent parameters.
6671 return C;
6672}
6673
6674template <typename Derived>
6675OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006676TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6677 // No need to rebuild this clause, no template-dependent parameters.
6678 return C;
6679}
6680
6681template <typename Derived>
6682OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006683TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6684 // No need to rebuild this clause, no template-dependent parameters.
6685 return C;
6686}
6687
6688template <typename Derived>
6689OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006690TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006691 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006692 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006693 for (auto *VE : C->varlists()) {
6694 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006695 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006696 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006697 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006698 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006699 return getDerived().RebuildOMPPrivateClause(
6700 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006701}
6702
Alexander Musman64d33f12014-06-04 07:53:32 +00006703template <typename Derived>
6704OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6705 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006706 llvm::SmallVector<Expr *, 16> Vars;
6707 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006708 for (auto *VE : C->varlists()) {
6709 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006710 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006711 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006712 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006713 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006714 return getDerived().RebuildOMPFirstprivateClause(
6715 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006716}
6717
Alexander Musman64d33f12014-06-04 07:53:32 +00006718template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006719OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006720TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6721 llvm::SmallVector<Expr *, 16> Vars;
6722 Vars.reserve(C->varlist_size());
6723 for (auto *VE : C->varlists()) {
6724 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6725 if (EVar.isInvalid())
6726 return nullptr;
6727 Vars.push_back(EVar.get());
6728 }
6729 return getDerived().RebuildOMPLastprivateClause(
6730 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6731}
6732
6733template <typename Derived>
6734OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006735TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6736 llvm::SmallVector<Expr *, 16> Vars;
6737 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006738 for (auto *VE : C->varlists()) {
6739 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006740 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006741 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006742 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006743 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006744 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6745 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006746}
6747
Alexander Musman64d33f12014-06-04 07:53:32 +00006748template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006749OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006750TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6751 llvm::SmallVector<Expr *, 16> Vars;
6752 Vars.reserve(C->varlist_size());
6753 for (auto *VE : C->varlists()) {
6754 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6755 if (EVar.isInvalid())
6756 return nullptr;
6757 Vars.push_back(EVar.get());
6758 }
6759 CXXScopeSpec ReductionIdScopeSpec;
6760 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6761
6762 DeclarationNameInfo NameInfo = C->getNameInfo();
6763 if (NameInfo.getName()) {
6764 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6765 if (!NameInfo.getName())
6766 return nullptr;
6767 }
6768 return getDerived().RebuildOMPReductionClause(
6769 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6770 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6771}
6772
6773template <typename Derived>
6774OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006775TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6776 llvm::SmallVector<Expr *, 16> Vars;
6777 Vars.reserve(C->varlist_size());
6778 for (auto *VE : C->varlists()) {
6779 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6780 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006781 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006782 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006783 }
6784 ExprResult Step = getDerived().TransformExpr(C->getStep());
6785 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006786 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006787 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6788 C->getLParenLoc(),
6789 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006790}
6791
Alexander Musman64d33f12014-06-04 07:53:32 +00006792template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006793OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006794TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6795 llvm::SmallVector<Expr *, 16> Vars;
6796 Vars.reserve(C->varlist_size());
6797 for (auto *VE : C->varlists()) {
6798 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6799 if (EVar.isInvalid())
6800 return nullptr;
6801 Vars.push_back(EVar.get());
6802 }
6803 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6804 if (Alignment.isInvalid())
6805 return nullptr;
6806 return getDerived().RebuildOMPAlignedClause(
6807 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6808 C->getColonLoc(), C->getLocEnd());
6809}
6810
Alexander Musman64d33f12014-06-04 07:53:32 +00006811template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006812OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006813TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6814 llvm::SmallVector<Expr *, 16> Vars;
6815 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006816 for (auto *VE : C->varlists()) {
6817 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006818 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006819 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006820 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006821 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006822 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6823 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006824}
6825
Alexey Bataevbae9a792014-06-27 10:37:06 +00006826template <typename Derived>
6827OMPClause *
6828TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6829 llvm::SmallVector<Expr *, 16> Vars;
6830 Vars.reserve(C->varlist_size());
6831 for (auto *VE : C->varlists()) {
6832 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6833 if (EVar.isInvalid())
6834 return nullptr;
6835 Vars.push_back(EVar.get());
6836 }
6837 return getDerived().RebuildOMPCopyprivateClause(
6838 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6839}
6840
Douglas Gregorebe10102009-08-20 07:17:43 +00006841//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006842// Expression transformation
6843//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006846TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006847 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006848}
Mike Stump11289f42009-09-09 15:08:12 +00006849
6850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006852TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006853 NestedNameSpecifierLoc QualifierLoc;
6854 if (E->getQualifierLoc()) {
6855 QualifierLoc
6856 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6857 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006859 }
John McCallce546572009-12-08 09:08:17 +00006860
6861 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006862 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6863 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006864 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006866
John McCall815039a2010-08-17 21:27:17 +00006867 DeclarationNameInfo NameInfo = E->getNameInfo();
6868 if (NameInfo.getName()) {
6869 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6870 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006872 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006873
6874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006875 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006876 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006877 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006878 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006879
6880 // Mark it referenced in the new context regardless.
6881 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006882 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006883
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006884 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006885 }
John McCallce546572009-12-08 09:08:17 +00006886
Craig Topperc3ec1492014-05-26 06:22:03 +00006887 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006888 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006889 TemplateArgs = &TransArgs;
6890 TransArgs.setLAngleLoc(E->getLAngleLoc());
6891 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006892 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6893 E->getNumTemplateArgs(),
6894 TransArgs))
6895 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006896 }
6897
Chad Rosier1dcde962012-08-08 18:46:20 +00006898 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006899 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006900}
Mike Stump11289f42009-09-09 15:08:12 +00006901
Douglas Gregora16548e2009-08-11 05:31:07 +00006902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006904TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006905 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006906}
Mike Stump11289f42009-09-09 15:08:12 +00006907
Douglas Gregora16548e2009-08-11 05:31:07 +00006908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006909ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006910TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006911 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006912}
Mike Stump11289f42009-09-09 15:08:12 +00006913
Douglas Gregora16548e2009-08-11 05:31:07 +00006914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006916TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006917 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006918}
Mike Stump11289f42009-09-09 15:08:12 +00006919
Douglas Gregora16548e2009-08-11 05:31:07 +00006920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006922TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006923 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006924}
Mike Stump11289f42009-09-09 15:08:12 +00006925
Douglas Gregora16548e2009-08-11 05:31:07 +00006926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006928TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006929 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006930}
6931
6932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006933ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006934TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006935 if (FunctionDecl *FD = E->getDirectCallee())
6936 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006937 return SemaRef.MaybeBindToTemporary(E);
6938}
6939
6940template<typename Derived>
6941ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006942TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6943 ExprResult ControllingExpr =
6944 getDerived().TransformExpr(E->getControllingExpr());
6945 if (ControllingExpr.isInvalid())
6946 return ExprError();
6947
Chris Lattner01cf8db2011-07-20 06:58:45 +00006948 SmallVector<Expr *, 4> AssocExprs;
6949 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006950 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6951 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6952 if (TS) {
6953 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6954 if (!AssocType)
6955 return ExprError();
6956 AssocTypes.push_back(AssocType);
6957 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006958 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006959 }
6960
6961 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6962 if (AssocExpr.isInvalid())
6963 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006964 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006965 }
6966
6967 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6968 E->getDefaultLoc(),
6969 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006970 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006971 AssocTypes,
6972 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006973}
6974
6975template<typename Derived>
6976ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006977TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006978 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006979 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006981
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006983 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006984
John McCallb268a282010-08-23 23:25:46 +00006985 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006986 E->getRParen());
6987}
6988
Richard Smithdb2630f2012-10-21 03:28:35 +00006989/// \brief The operand of a unary address-of operator has special rules: it's
6990/// allowed to refer to a non-static member of a class even if there's no 'this'
6991/// object available.
6992template<typename Derived>
6993ExprResult
6994TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6995 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00006996 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00006997 else
6998 return getDerived().TransformExpr(E);
6999}
7000
Mike Stump11289f42009-09-09 15:08:12 +00007001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007003TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007004 ExprResult SubExpr;
7005 if (E->getOpcode() == UO_AddrOf)
7006 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7007 else
7008 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007009 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007011
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007013 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007014
Douglas Gregora16548e2009-08-11 05:31:07 +00007015 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7016 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007017 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007018}
Mike Stump11289f42009-09-09 15:08:12 +00007019
Douglas Gregora16548e2009-08-11 05:31:07 +00007020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007021ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007022TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7023 // Transform the type.
7024 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7025 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007027
Douglas Gregor882211c2010-04-28 22:16:22 +00007028 // Transform all of the components into components similar to what the
7029 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007030 // FIXME: It would be slightly more efficient in the non-dependent case to
7031 // just map FieldDecls, rather than requiring the rebuilder to look for
7032 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007033 // template code that we don't care.
7034 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007035 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007036 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007037 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007038 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7039 const Node &ON = E->getComponent(I);
7040 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007041 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007042 Comp.LocStart = ON.getSourceRange().getBegin();
7043 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007044 switch (ON.getKind()) {
7045 case Node::Array: {
7046 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007047 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007048 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007049 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007050
Douglas Gregor882211c2010-04-28 22:16:22 +00007051 ExprChanged = ExprChanged || Index.get() != FromIndex;
7052 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007053 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007054 break;
7055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007056
Douglas Gregor882211c2010-04-28 22:16:22 +00007057 case Node::Field:
7058 case Node::Identifier:
7059 Comp.isBrackets = false;
7060 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007061 if (!Comp.U.IdentInfo)
7062 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007063
Douglas Gregor882211c2010-04-28 22:16:22 +00007064 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007065
Douglas Gregord1702062010-04-29 00:18:15 +00007066 case Node::Base:
7067 // Will be recomputed during the rebuild.
7068 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007069 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007070
Douglas Gregor882211c2010-04-28 22:16:22 +00007071 Components.push_back(Comp);
7072 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007073
Douglas Gregor882211c2010-04-28 22:16:22 +00007074 // If nothing changed, retain the existing expression.
7075 if (!getDerived().AlwaysRebuild() &&
7076 Type == E->getTypeSourceInfo() &&
7077 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007078 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007079
Douglas Gregor882211c2010-04-28 22:16:22 +00007080 // Build a new offsetof expression.
7081 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7082 Components.data(), Components.size(),
7083 E->getRParenLoc());
7084}
7085
7086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007087ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007088TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7089 assert(getDerived().AlreadyTransformed(E->getType()) &&
7090 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007091 return E;
John McCall8d69a212010-11-15 23:31:06 +00007092}
7093
7094template<typename Derived>
7095ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007096TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007097 // Rebuild the syntactic form. The original syntactic form has
7098 // opaque-value expressions in it, so strip those away and rebuild
7099 // the result. This is a really awful way of doing this, but the
7100 // better solution (rebuilding the semantic expressions and
7101 // rebinding OVEs as necessary) doesn't work; we'd need
7102 // TreeTransform to not strip away implicit conversions.
7103 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7104 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007105 if (result.isInvalid()) return ExprError();
7106
7107 // If that gives us a pseudo-object result back, the pseudo-object
7108 // expression must have been an lvalue-to-rvalue conversion which we
7109 // should reapply.
7110 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007111 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007112
7113 return result;
7114}
7115
7116template<typename Derived>
7117ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007118TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7119 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007120 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007121 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007122
John McCallbcd03502009-12-07 02:54:59 +00007123 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007124 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007126
John McCall4c98fd82009-11-04 07:28:41 +00007127 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007128 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007129
Peter Collingbournee190dee2011-03-11 19:24:49 +00007130 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7131 E->getKind(),
7132 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007133 }
Mike Stump11289f42009-09-09 15:08:12 +00007134
Eli Friedmane4f22df2012-02-29 04:03:55 +00007135 // C++0x [expr.sizeof]p1:
7136 // The operand is either an expression, which is an unevaluated operand
7137 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007138 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7139 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007140
Reid Kleckner32506ed2014-06-12 23:03:48 +00007141 // Try to recover if we have something like sizeof(T::X) where X is a type.
7142 // Notably, there must be *exactly* one set of parens if X is a type.
7143 TypeSourceInfo *RecoveryTSI = nullptr;
7144 ExprResult SubExpr;
7145 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7146 if (auto *DRE =
7147 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7148 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7149 PE, DRE, false, &RecoveryTSI);
7150 else
7151 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7152
7153 if (RecoveryTSI) {
7154 return getDerived().RebuildUnaryExprOrTypeTrait(
7155 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7156 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007158
Eli Friedmane4f22df2012-02-29 04:03:55 +00007159 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007160 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007161
Peter Collingbournee190dee2011-03-11 19:24:49 +00007162 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7163 E->getOperatorLoc(),
7164 E->getKind(),
7165 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007166}
Mike Stump11289f42009-09-09 15:08:12 +00007167
Douglas Gregora16548e2009-08-11 05:31:07 +00007168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007170TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007171 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007172 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007174
John McCalldadc5752010-08-24 06:29:42 +00007175 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007176 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007178
7179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 if (!getDerived().AlwaysRebuild() &&
7181 LHS.get() == E->getLHS() &&
7182 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007183 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007184
John McCallb268a282010-08-23 23:25:46 +00007185 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007187 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007188 E->getRBracketLoc());
7189}
Mike Stump11289f42009-09-09 15:08:12 +00007190
7191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007193TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007195 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007196 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007197 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007198
7199 // Transform arguments.
7200 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007201 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007202 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007203 &ArgChanged))
7204 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007205
Douglas Gregora16548e2009-08-11 05:31:07 +00007206 if (!getDerived().AlwaysRebuild() &&
7207 Callee.get() == E->getCallee() &&
7208 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007209 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007210
Douglas Gregora16548e2009-08-11 05:31:07 +00007211 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007212 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007213 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007214 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007215 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007216 E->getRParenLoc());
7217}
Mike Stump11289f42009-09-09 15:08:12 +00007218
7219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007221TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007222 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregorea972d32011-02-28 21:54:11 +00007226 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007227 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007228 QualifierLoc
7229 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007230
Douglas Gregorea972d32011-02-28 21:54:11 +00007231 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007232 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007233 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007234 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007235
Eli Friedman2cfcef62009-12-04 06:40:45 +00007236 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007237 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7238 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007239 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007241
John McCall16df1e52010-03-30 21:47:33 +00007242 NamedDecl *FoundDecl = E->getFoundDecl();
7243 if (FoundDecl == E->getMemberDecl()) {
7244 FoundDecl = Member;
7245 } else {
7246 FoundDecl = cast_or_null<NamedDecl>(
7247 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7248 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007249 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007250 }
7251
Douglas Gregora16548e2009-08-11 05:31:07 +00007252 if (!getDerived().AlwaysRebuild() &&
7253 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007254 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007255 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007256 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007257 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007258
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007259 // Mark it referenced in the new context regardless.
7260 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007261 SemaRef.MarkMemberReferenced(E);
7262
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007263 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007264 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007265
John McCall6b51f282009-11-23 01:53:49 +00007266 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007267 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007268 TransArgs.setLAngleLoc(E->getLAngleLoc());
7269 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007270 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7271 E->getNumTemplateArgs(),
7272 TransArgs))
7273 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007274 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007275
Douglas Gregora16548e2009-08-11 05:31:07 +00007276 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007277 SourceLocation FakeOperatorLoc =
7278 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007279
John McCall38836f02010-01-15 08:34:02 +00007280 // FIXME: to do this check properly, we will need to preserve the
7281 // first-qualifier-in-scope here, just in case we had a dependent
7282 // base (and therefore couldn't do the check) and a
7283 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007284 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007285
John McCallb268a282010-08-23 23:25:46 +00007286 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007287 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007288 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007289 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007290 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007291 Member,
John McCall16df1e52010-03-30 21:47:33 +00007292 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007293 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007294 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007295 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007296}
Mike Stump11289f42009-09-09 15:08:12 +00007297
Douglas Gregora16548e2009-08-11 05:31:07 +00007298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007299ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007300TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007301 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007302 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007304
John McCalldadc5752010-08-24 06:29:42 +00007305 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007306 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007308
Douglas Gregora16548e2009-08-11 05:31:07 +00007309 if (!getDerived().AlwaysRebuild() &&
7310 LHS.get() == E->getLHS() &&
7311 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007312 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007313
Lang Hames5de91cc2012-10-02 04:45:10 +00007314 Sema::FPContractStateRAII FPContractState(getSema());
7315 getSema().FPFeatures.fp_contract = E->isFPContractable();
7316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007318 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007319}
7320
Mike Stump11289f42009-09-09 15:08:12 +00007321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007322ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007323TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007324 CompoundAssignOperator *E) {
7325 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007326}
Mike Stump11289f42009-09-09 15:08:12 +00007327
Douglas Gregora16548e2009-08-11 05:31:07 +00007328template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007329ExprResult TreeTransform<Derived>::
7330TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7331 // Just rebuild the common and RHS expressions and see whether we
7332 // get any changes.
7333
7334 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7335 if (commonExpr.isInvalid())
7336 return ExprError();
7337
7338 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7339 if (rhs.isInvalid())
7340 return ExprError();
7341
7342 if (!getDerived().AlwaysRebuild() &&
7343 commonExpr.get() == e->getCommon() &&
7344 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007345 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007346
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007347 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007348 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007349 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007350 e->getColonLoc(),
7351 rhs.get());
7352}
7353
7354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007356TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007357 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007360
John McCalldadc5752010-08-24 06:29:42 +00007361 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007364
John McCalldadc5752010-08-24 06:29:42 +00007365 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007366 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007368
Douglas Gregora16548e2009-08-11 05:31:07 +00007369 if (!getDerived().AlwaysRebuild() &&
7370 Cond.get() == E->getCond() &&
7371 LHS.get() == E->getLHS() &&
7372 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007373 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007374
John McCallb268a282010-08-23 23:25:46 +00007375 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007376 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007377 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007378 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007379 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007380}
Mike Stump11289f42009-09-09 15:08:12 +00007381
7382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007384TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007385 // Implicit casts are eliminated during transformation, since they
7386 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007387 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007388}
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007392TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007393 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7394 if (!Type)
7395 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007396
John McCalldadc5752010-08-24 06:29:42 +00007397 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007398 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007401
Douglas Gregora16548e2009-08-11 05:31:07 +00007402 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007403 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007404 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007405 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007406
John McCall97513962010-01-15 18:39:57 +00007407 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007408 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007409 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007410 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007411}
Mike Stump11289f42009-09-09 15:08:12 +00007412
Douglas Gregora16548e2009-08-11 05:31:07 +00007413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007415TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007416 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7417 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7418 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007420
John McCalldadc5752010-08-24 06:29:42 +00007421 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007424
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007426 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007427 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007428 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007429
John McCall5d7aa7f2010-01-19 22:33:45 +00007430 // Note: the expression type doesn't necessarily match the
7431 // type-as-written, but that's okay, because it should always be
7432 // derivable from the initializer.
7433
John McCalle15bbff2010-01-18 19:35:47 +00007434 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007435 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007436 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007437}
Mike Stump11289f42009-09-09 15:08:12 +00007438
Douglas Gregora16548e2009-08-11 05:31:07 +00007439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007441TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007442 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007443 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007445
Douglas Gregora16548e2009-08-11 05:31:07 +00007446 if (!getDerived().AlwaysRebuild() &&
7447 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007448 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007449
Douglas Gregora16548e2009-08-11 05:31:07 +00007450 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007451 SourceLocation FakeOperatorLoc =
7452 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007453 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007454 E->getAccessorLoc(),
7455 E->getAccessor());
7456}
Mike Stump11289f42009-09-09 15:08:12 +00007457
Douglas Gregora16548e2009-08-11 05:31:07 +00007458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007460TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007462
Benjamin Kramerf0623432012-08-23 22:51:59 +00007463 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007464 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007465 Inits, &InitChanged))
7466 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007467
Douglas Gregora16548e2009-08-11 05:31:07 +00007468 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007469 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007470
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007471 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007472 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007473}
Mike Stump11289f42009-09-09 15:08:12 +00007474
Douglas Gregora16548e2009-08-11 05:31:07 +00007475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007476ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007477TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007478 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007479
Douglas Gregorebe10102009-08-20 07:17:43 +00007480 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007481 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007482 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007484
Douglas Gregorebe10102009-08-20 07:17:43 +00007485 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007486 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007487 bool ExprChanged = false;
7488 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7489 DEnd = E->designators_end();
7490 D != DEnd; ++D) {
7491 if (D->isFieldDesignator()) {
7492 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7493 D->getDotLoc(),
7494 D->getFieldLoc()));
7495 continue;
7496 }
Mike Stump11289f42009-09-09 15:08:12 +00007497
Douglas Gregora16548e2009-08-11 05:31:07 +00007498 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007499 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007500 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007502
7503 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007504 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007505
Douglas Gregora16548e2009-08-11 05:31:07 +00007506 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007507 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007508 continue;
7509 }
Mike Stump11289f42009-09-09 15:08:12 +00007510
Douglas Gregora16548e2009-08-11 05:31:07 +00007511 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007512 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007513 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7514 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007516
John McCalldadc5752010-08-24 06:29:42 +00007517 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007520
7521 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007522 End.get(),
7523 D->getLBracketLoc(),
7524 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007525
Douglas Gregora16548e2009-08-11 05:31:07 +00007526 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7527 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007528
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007529 ArrayExprs.push_back(Start.get());
7530 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007531 }
Mike Stump11289f42009-09-09 15:08:12 +00007532
Douglas Gregora16548e2009-08-11 05:31:07 +00007533 if (!getDerived().AlwaysRebuild() &&
7534 Init.get() == E->getInit() &&
7535 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007536 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007537
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007538 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007539 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007540 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007541}
Mike Stump11289f42009-09-09 15:08:12 +00007542
Douglas Gregora16548e2009-08-11 05:31:07 +00007543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007544ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007545TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007546 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007547 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007548
Douglas Gregor3da3c062009-10-28 00:29:27 +00007549 // FIXME: Will we ever have proper type location here? Will we actually
7550 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 QualType T = getDerived().TransformType(E->getType());
7552 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 if (!getDerived().AlwaysRebuild() &&
7556 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007557 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007558
Douglas Gregora16548e2009-08-11 05:31:07 +00007559 return getDerived().RebuildImplicitValueInitExpr(T);
7560}
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregora16548e2009-08-11 05:31:07 +00007562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007563ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007564TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007565 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7566 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007568
John McCalldadc5752010-08-24 06:29:42 +00007569 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007572
Douglas Gregora16548e2009-08-11 05:31:07 +00007573 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007574 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007576 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007577
John McCallb268a282010-08-23 23:25:46 +00007578 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007579 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007580}
7581
7582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007584TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007585 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007586 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007587 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7588 &ArgumentChanged))
7589 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007590
Douglas Gregora16548e2009-08-11 05:31:07 +00007591 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007592 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007593 E->getRParenLoc());
7594}
Mike Stump11289f42009-09-09 15:08:12 +00007595
Douglas Gregora16548e2009-08-11 05:31:07 +00007596/// \brief Transform an address-of-label expression.
7597///
7598/// By default, the transformation of an address-of-label expression always
7599/// rebuilds the expression, so that the label identifier can be resolved to
7600/// the corresponding label statement by semantic analysis.
7601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007602ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007603TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007604 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7605 E->getLabel());
7606 if (!LD)
7607 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007608
Douglas Gregora16548e2009-08-11 05:31:07 +00007609 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007610 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007611}
Mike Stump11289f42009-09-09 15:08:12 +00007612
7613template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007614ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007615TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007616 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007617 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007618 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007619 if (SubStmt.isInvalid()) {
7620 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007621 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007622 }
Mike Stump11289f42009-09-09 15:08:12 +00007623
Douglas Gregora16548e2009-08-11 05:31:07 +00007624 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007625 SubStmt.get() == E->getSubStmt()) {
7626 // Calling this an 'error' is unintuitive, but it does the right thing.
7627 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007628 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007629 }
Mike Stump11289f42009-09-09 15:08:12 +00007630
7631 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007632 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007633 E->getRParenLoc());
7634}
Mike Stump11289f42009-09-09 15:08:12 +00007635
Douglas Gregora16548e2009-08-11 05:31:07 +00007636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007638TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007639 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007640 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007642
John McCalldadc5752010-08-24 06:29:42 +00007643 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007644 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007646
John McCalldadc5752010-08-24 06:29:42 +00007647 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007649 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007650
Douglas Gregora16548e2009-08-11 05:31:07 +00007651 if (!getDerived().AlwaysRebuild() &&
7652 Cond.get() == E->getCond() &&
7653 LHS.get() == E->getLHS() &&
7654 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007655 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007656
Douglas Gregora16548e2009-08-11 05:31:07 +00007657 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007658 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 E->getRParenLoc());
7660}
Mike Stump11289f42009-09-09 15:08:12 +00007661
Douglas Gregora16548e2009-08-11 05:31:07 +00007662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007664TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007665 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007666}
7667
7668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007669ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007670TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007671 switch (E->getOperator()) {
7672 case OO_New:
7673 case OO_Delete:
7674 case OO_Array_New:
7675 case OO_Array_Delete:
7676 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007677
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007678 case OO_Call: {
7679 // This is a call to an object's operator().
7680 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7681
7682 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007683 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007684 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007685 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007686
7687 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007688 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7689 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007690
7691 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007692 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007693 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007694 Args))
7695 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007696
John McCallb268a282010-08-23 23:25:46 +00007697 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007698 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007699 E->getLocEnd());
7700 }
7701
7702#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7703 case OO_##Name:
7704#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7705#include "clang/Basic/OperatorKinds.def"
7706 case OO_Subscript:
7707 // Handled below.
7708 break;
7709
7710 case OO_Conditional:
7711 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007712
7713 case OO_None:
7714 case NUM_OVERLOADED_OPERATORS:
7715 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007716 }
7717
John McCalldadc5752010-08-24 06:29:42 +00007718 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007719 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007720 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007721
Richard Smithdb2630f2012-10-21 03:28:35 +00007722 ExprResult First;
7723 if (E->getOperator() == OO_Amp)
7724 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7725 else
7726 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007728 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007729
John McCalldadc5752010-08-24 06:29:42 +00007730 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007731 if (E->getNumArgs() == 2) {
7732 Second = getDerived().TransformExpr(E->getArg(1));
7733 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007734 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007735 }
Mike Stump11289f42009-09-09 15:08:12 +00007736
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 if (!getDerived().AlwaysRebuild() &&
7738 Callee.get() == E->getCallee() &&
7739 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007740 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007741 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007742
Lang Hames5de91cc2012-10-02 04:45:10 +00007743 Sema::FPContractStateRAII FPContractState(getSema());
7744 getSema().FPFeatures.fp_contract = E->isFPContractable();
7745
Douglas Gregora16548e2009-08-11 05:31:07 +00007746 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7747 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007748 Callee.get(),
7749 First.get(),
7750 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007751}
Mike Stump11289f42009-09-09 15:08:12 +00007752
Douglas Gregora16548e2009-08-11 05:31:07 +00007753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007754ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007755TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7756 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007757}
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007760ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007761TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7762 // Transform the callee.
7763 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7764 if (Callee.isInvalid())
7765 return ExprError();
7766
7767 // Transform exec config.
7768 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7769 if (EC.isInvalid())
7770 return ExprError();
7771
7772 // Transform arguments.
7773 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007774 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007775 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007776 &ArgChanged))
7777 return ExprError();
7778
7779 if (!getDerived().AlwaysRebuild() &&
7780 Callee.get() == E->getCallee() &&
7781 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007782 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007783
7784 // FIXME: Wrong source location information for the '('.
7785 SourceLocation FakeLParenLoc
7786 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7787 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007788 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007789 E->getRParenLoc(), EC.get());
7790}
7791
7792template<typename Derived>
7793ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007794TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007795 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7796 if (!Type)
7797 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007798
John McCalldadc5752010-08-24 06:29:42 +00007799 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007800 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007801 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007803
Douglas Gregora16548e2009-08-11 05:31:07 +00007804 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007805 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007806 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007807 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007808 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007809 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007810 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007811 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007812 E->getAngleBrackets().getEnd(),
7813 // FIXME. this should be '(' location
7814 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007815 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007816 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007817}
Mike Stump11289f42009-09-09 15:08:12 +00007818
Douglas Gregora16548e2009-08-11 05:31:07 +00007819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7822 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007823}
Mike Stump11289f42009-09-09 15:08:12 +00007824
7825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007826ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007827TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7828 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007829}
7830
Douglas Gregora16548e2009-08-11 05:31:07 +00007831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007832ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007833TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007834 CXXReinterpretCastExpr *E) {
7835 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007836}
Mike Stump11289f42009-09-09 15:08:12 +00007837
Douglas Gregora16548e2009-08-11 05:31:07 +00007838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007840TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7841 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007842}
Mike Stump11289f42009-09-09 15:08:12 +00007843
Douglas Gregora16548e2009-08-11 05:31:07 +00007844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007845ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007846TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007847 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007848 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7849 if (!Type)
7850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007851
John McCalldadc5752010-08-24 06:29:42 +00007852 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007853 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007856
Douglas Gregora16548e2009-08-11 05:31:07 +00007857 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007858 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007859 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007860 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007861
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007862 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007863 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007864 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007865 E->getRParenLoc());
7866}
Mike Stump11289f42009-09-09 15:08:12 +00007867
Douglas Gregora16548e2009-08-11 05:31:07 +00007868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007870TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007871 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007872 TypeSourceInfo *TInfo
7873 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7874 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007875 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007876
Douglas Gregora16548e2009-08-11 05:31:07 +00007877 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007878 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007879 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007880
Douglas Gregor9da64192010-04-26 22:37:10 +00007881 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7882 E->getLocStart(),
7883 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007884 E->getLocEnd());
7885 }
Mike Stump11289f42009-09-09 15:08:12 +00007886
Eli Friedman456f0182012-01-20 01:26:23 +00007887 // We don't know whether the subexpression is potentially evaluated until
7888 // after we perform semantic analysis. We speculatively assume it is
7889 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007890 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007891 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7892 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007893
John McCalldadc5752010-08-24 06:29:42 +00007894 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007895 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 if (!getDerived().AlwaysRebuild() &&
7899 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007900 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007901
Douglas Gregor9da64192010-04-26 22:37:10 +00007902 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7903 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007904 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007905 E->getLocEnd());
7906}
7907
7908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007909ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007910TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7911 if (E->isTypeOperand()) {
7912 TypeSourceInfo *TInfo
7913 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7914 if (!TInfo)
7915 return ExprError();
7916
7917 if (!getDerived().AlwaysRebuild() &&
7918 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007919 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007920
Douglas Gregor69735112011-03-06 17:40:41 +00007921 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007922 E->getLocStart(),
7923 TInfo,
7924 E->getLocEnd());
7925 }
7926
Francois Pichet9f4f2072010-09-08 12:20:18 +00007927 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7928
7929 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7930 if (SubExpr.isInvalid())
7931 return ExprError();
7932
7933 if (!getDerived().AlwaysRebuild() &&
7934 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007935 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007936
7937 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7938 E->getLocStart(),
7939 SubExpr.get(),
7940 E->getLocEnd());
7941}
7942
7943template<typename Derived>
7944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007945TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007946 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007947}
Mike Stump11289f42009-09-09 15:08:12 +00007948
Douglas Gregora16548e2009-08-11 05:31:07 +00007949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007950ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007951TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007952 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007953 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007954}
Mike Stump11289f42009-09-09 15:08:12 +00007955
Douglas Gregora16548e2009-08-11 05:31:07 +00007956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007957ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007958TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007959 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007960
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007961 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7962 // Make sure that we capture 'this'.
7963 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007964 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007966
Douglas Gregorb15af892010-01-07 23:12:05 +00007967 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007968}
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregora16548e2009-08-11 05:31:07 +00007970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007972TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007973 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregora16548e2009-08-11 05:31:07 +00007977 if (!getDerived().AlwaysRebuild() &&
7978 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007979 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007980
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007981 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7982 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007983}
Mike Stump11289f42009-09-09 15:08:12 +00007984
Douglas Gregora16548e2009-08-11 05:31:07 +00007985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007987TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007988 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007989 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7990 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007993
Chandler Carruth794da4c2010-02-08 06:42:49 +00007994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007996 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007997
Douglas Gregor033f6752009-12-23 23:03:06 +00007998 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007999}
Mike Stump11289f42009-09-09 15:08:12 +00008000
Douglas Gregora16548e2009-08-11 05:31:07 +00008001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008002ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008003TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8004 FieldDecl *Field
8005 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8006 E->getField()));
8007 if (!Field)
8008 return ExprError();
8009
8010 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008011 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008012
8013 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8014}
8015
8016template<typename Derived>
8017ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008018TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8019 CXXScalarValueInitExpr *E) {
8020 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8021 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008022 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008023
Douglas Gregora16548e2009-08-11 05:31:07 +00008024 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008025 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008026 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008027
Chad Rosier1dcde962012-08-08 18:46:20 +00008028 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008029 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008030 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008031}
Mike Stump11289f42009-09-09 15:08:12 +00008032
Douglas Gregora16548e2009-08-11 05:31:07 +00008033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008034ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008035TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008036 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008037 TypeSourceInfo *AllocTypeInfo
8038 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8039 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008040 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008041
Douglas Gregora16548e2009-08-11 05:31:07 +00008042 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008043 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008044 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008046
Douglas Gregora16548e2009-08-11 05:31:07 +00008047 // Transform the placement arguments (if any).
8048 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008049 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008050 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008051 E->getNumPlacementArgs(), true,
8052 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008054
Sebastian Redl6047f072012-02-16 12:22:20 +00008055 // Transform the initializer (if any).
8056 Expr *OldInit = E->getInitializer();
8057 ExprResult NewInit;
8058 if (OldInit)
8059 NewInit = getDerived().TransformExpr(OldInit);
8060 if (NewInit.isInvalid())
8061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008062
Sebastian Redl6047f072012-02-16 12:22:20 +00008063 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008064 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008065 if (E->getOperatorNew()) {
8066 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008067 getDerived().TransformDecl(E->getLocStart(),
8068 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008069 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008070 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008071 }
8072
Craig Topperc3ec1492014-05-26 06:22:03 +00008073 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008074 if (E->getOperatorDelete()) {
8075 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008076 getDerived().TransformDecl(E->getLocStart(),
8077 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008078 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008079 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008081
Douglas Gregora16548e2009-08-11 05:31:07 +00008082 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008083 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008084 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008085 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008086 OperatorNew == E->getOperatorNew() &&
8087 OperatorDelete == E->getOperatorDelete() &&
8088 !ArgumentChanged) {
8089 // Mark any declarations we need as referenced.
8090 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008091 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008092 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008093 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008094 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008095
Sebastian Redl6047f072012-02-16 12:22:20 +00008096 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008097 QualType ElementType
8098 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8099 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8100 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8101 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008102 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008103 }
8104 }
8105 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008106
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008107 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008108 }
Mike Stump11289f42009-09-09 15:08:12 +00008109
Douglas Gregor0744ef62010-09-07 21:49:58 +00008110 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008111 if (!ArraySize.get()) {
8112 // If no array size was specified, but the new expression was
8113 // instantiated with an array type (e.g., "new T" where T is
8114 // instantiated with "int[4]"), extract the outer bound from the
8115 // array type as our array size. We do this with constant and
8116 // dependently-sized array types.
8117 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8118 if (!ArrayT) {
8119 // Do nothing
8120 } else if (const ConstantArrayType *ConsArrayT
8121 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008122 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8123 SemaRef.Context.getSizeType(),
8124 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008125 AllocType = ConsArrayT->getElementType();
8126 } else if (const DependentSizedArrayType *DepArrayT
8127 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8128 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008129 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008130 AllocType = DepArrayT->getElementType();
8131 }
8132 }
8133 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008134
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8136 E->isGlobalNew(),
8137 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008138 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008140 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008141 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008142 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008143 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008144 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008145 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008146}
Mike Stump11289f42009-09-09 15:08:12 +00008147
Douglas Gregora16548e2009-08-11 05:31:07 +00008148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008150TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008151 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008152 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008154
Douglas Gregord2d9da02010-02-26 00:38:10 +00008155 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008156 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008157 if (E->getOperatorDelete()) {
8158 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008159 getDerived().TransformDecl(E->getLocStart(),
8160 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008161 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008162 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008163 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008164
Douglas Gregora16548e2009-08-11 05:31:07 +00008165 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008166 Operand.get() == E->getArgument() &&
8167 OperatorDelete == E->getOperatorDelete()) {
8168 // Mark any declarations we need as referenced.
8169 // FIXME: instantiation-specific.
8170 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008171 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008172
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008173 if (!E->getArgument()->isTypeDependent()) {
8174 QualType Destroyed = SemaRef.Context.getBaseElementType(
8175 E->getDestroyedType());
8176 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8177 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008178 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008179 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008180 }
8181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008182
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008183 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008184 }
Mike Stump11289f42009-09-09 15:08:12 +00008185
Douglas Gregora16548e2009-08-11 05:31:07 +00008186 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8187 E->isGlobalDelete(),
8188 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008189 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008190}
Mike Stump11289f42009-09-09 15:08:12 +00008191
Douglas Gregora16548e2009-08-11 05:31:07 +00008192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008193ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008194TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008195 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008196 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008197 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008199
John McCallba7bf592010-08-24 05:47:05 +00008200 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008201 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008202 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008203 E->getOperatorLoc(),
8204 E->isArrow()? tok::arrow : tok::period,
8205 ObjectTypePtr,
8206 MayBePseudoDestructor);
8207 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008208 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008209
John McCallba7bf592010-08-24 05:47:05 +00008210 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008211 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8212 if (QualifierLoc) {
8213 QualifierLoc
8214 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8215 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008216 return ExprError();
8217 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008218 CXXScopeSpec SS;
8219 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008220
Douglas Gregor678f90d2010-02-25 01:56:36 +00008221 PseudoDestructorTypeStorage Destroyed;
8222 if (E->getDestroyedTypeInfo()) {
8223 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008224 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008225 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008226 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008227 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008228 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008229 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008230 // We aren't likely to be able to resolve the identifier down to a type
8231 // now anyway, so just retain the identifier.
8232 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8233 E->getDestroyedTypeLoc());
8234 } else {
8235 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008236 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008237 *E->getDestroyedTypeIdentifier(),
8238 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008239 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008240 SS, ObjectTypePtr,
8241 false);
8242 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008243 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008244
Douglas Gregor678f90d2010-02-25 01:56:36 +00008245 Destroyed
8246 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8247 E->getDestroyedTypeLoc());
8248 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008249
Craig Topperc3ec1492014-05-26 06:22:03 +00008250 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008251 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008252 CXXScopeSpec EmptySS;
8253 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008254 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008255 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008256 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008258
John McCallb268a282010-08-23 23:25:46 +00008259 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008260 E->getOperatorLoc(),
8261 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008262 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008263 ScopeTypeInfo,
8264 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008265 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008266 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008267}
Mike Stump11289f42009-09-09 15:08:12 +00008268
Douglas Gregorad8a3362009-09-04 17:36:40 +00008269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008270ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008271TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008272 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008273 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8274 Sema::LookupOrdinaryName);
8275
8276 // Transform all the decls.
8277 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8278 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008279 NamedDecl *InstD = static_cast<NamedDecl*>(
8280 getDerived().TransformDecl(Old->getNameLoc(),
8281 *I));
John McCall84d87672009-12-10 09:41:52 +00008282 if (!InstD) {
8283 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8284 // This can happen because of dependent hiding.
8285 if (isa<UsingShadowDecl>(*I))
8286 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008287 else {
8288 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008289 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008290 }
John McCall84d87672009-12-10 09:41:52 +00008291 }
John McCalle66edc12009-11-24 19:00:30 +00008292
8293 // Expand using declarations.
8294 if (isa<UsingDecl>(InstD)) {
8295 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008296 for (auto *I : UD->shadows())
8297 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008298 continue;
8299 }
8300
8301 R.addDecl(InstD);
8302 }
8303
8304 // Resolve a kind, but don't do any further analysis. If it's
8305 // ambiguous, the callee needs to deal with it.
8306 R.resolveKind();
8307
8308 // Rebuild the nested-name qualifier, if present.
8309 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008310 if (Old->getQualifierLoc()) {
8311 NestedNameSpecifierLoc QualifierLoc
8312 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8313 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008314 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008315
Douglas Gregor0da1d432011-02-28 20:01:57 +00008316 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008317 }
8318
Douglas Gregor9262f472010-04-27 18:19:34 +00008319 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008320 CXXRecordDecl *NamingClass
8321 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8322 Old->getNameLoc(),
8323 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008324 if (!NamingClass) {
8325 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008326 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008328
Douglas Gregorda7be082010-04-27 16:10:10 +00008329 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008330 }
8331
Abramo Bagnara7945c982012-01-27 09:46:47 +00008332 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8333
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008334 // If we have neither explicit template arguments, nor the template keyword,
8335 // it's a normal declaration name.
8336 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008337 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8338
8339 // If we have template arguments, rebuild them, then rebuild the
8340 // templateid expression.
8341 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008342 if (Old->hasExplicitTemplateArgs() &&
8343 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008344 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008345 TransArgs)) {
8346 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008347 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008348 }
John McCalle66edc12009-11-24 19:00:30 +00008349
Abramo Bagnara7945c982012-01-27 09:46:47 +00008350 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008351 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008352}
Mike Stump11289f42009-09-09 15:08:12 +00008353
Douglas Gregora16548e2009-08-11 05:31:07 +00008354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008355ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008356TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8357 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008358 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008359 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8360 TypeSourceInfo *From = E->getArg(I);
8361 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008362 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008363 TypeLocBuilder TLB;
8364 TLB.reserve(FromTL.getFullDataSize());
8365 QualType To = getDerived().TransformType(TLB, FromTL);
8366 if (To.isNull())
8367 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008368
Douglas Gregor29c42f22012-02-24 07:38:34 +00008369 if (To == From->getType())
8370 Args.push_back(From);
8371 else {
8372 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8373 ArgChanged = true;
8374 }
8375 continue;
8376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008377
Douglas Gregor29c42f22012-02-24 07:38:34 +00008378 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008379
Douglas Gregor29c42f22012-02-24 07:38:34 +00008380 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008381 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008382 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8383 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8384 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008385
Douglas Gregor29c42f22012-02-24 07:38:34 +00008386 // Determine whether the set of unexpanded parameter packs can and should
8387 // be expanded.
8388 bool Expand = true;
8389 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008390 Optional<unsigned> OrigNumExpansions =
8391 ExpansionTL.getTypePtr()->getNumExpansions();
8392 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008393 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8394 PatternTL.getSourceRange(),
8395 Unexpanded,
8396 Expand, RetainExpansion,
8397 NumExpansions))
8398 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008399
Douglas Gregor29c42f22012-02-24 07:38:34 +00008400 if (!Expand) {
8401 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008402 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008403 // expansion.
8404 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008405
Douglas Gregor29c42f22012-02-24 07:38:34 +00008406 TypeLocBuilder TLB;
8407 TLB.reserve(From->getTypeLoc().getFullDataSize());
8408
8409 QualType To = getDerived().TransformType(TLB, PatternTL);
8410 if (To.isNull())
8411 return ExprError();
8412
Chad Rosier1dcde962012-08-08 18:46:20 +00008413 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008414 PatternTL.getSourceRange(),
8415 ExpansionTL.getEllipsisLoc(),
8416 NumExpansions);
8417 if (To.isNull())
8418 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008419
Douglas Gregor29c42f22012-02-24 07:38:34 +00008420 PackExpansionTypeLoc ToExpansionTL
8421 = TLB.push<PackExpansionTypeLoc>(To);
8422 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8423 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8424 continue;
8425 }
8426
8427 // Expand the pack expansion by substituting for each argument in the
8428 // pack(s).
8429 for (unsigned I = 0; I != *NumExpansions; ++I) {
8430 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8431 TypeLocBuilder TLB;
8432 TLB.reserve(PatternTL.getFullDataSize());
8433 QualType To = getDerived().TransformType(TLB, PatternTL);
8434 if (To.isNull())
8435 return ExprError();
8436
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008437 if (To->containsUnexpandedParameterPack()) {
8438 To = getDerived().RebuildPackExpansionType(To,
8439 PatternTL.getSourceRange(),
8440 ExpansionTL.getEllipsisLoc(),
8441 NumExpansions);
8442 if (To.isNull())
8443 return ExprError();
8444
8445 PackExpansionTypeLoc ToExpansionTL
8446 = TLB.push<PackExpansionTypeLoc>(To);
8447 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8448 }
8449
Douglas Gregor29c42f22012-02-24 07:38:34 +00008450 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008452
Douglas Gregor29c42f22012-02-24 07:38:34 +00008453 if (!RetainExpansion)
8454 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008455
Douglas Gregor29c42f22012-02-24 07:38:34 +00008456 // If we're supposed to retain a pack expansion, do so by temporarily
8457 // forgetting the partially-substituted parameter pack.
8458 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8459
8460 TypeLocBuilder TLB;
8461 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008462
Douglas Gregor29c42f22012-02-24 07:38:34 +00008463 QualType To = getDerived().TransformType(TLB, PatternTL);
8464 if (To.isNull())
8465 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008466
8467 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008468 PatternTL.getSourceRange(),
8469 ExpansionTL.getEllipsisLoc(),
8470 NumExpansions);
8471 if (To.isNull())
8472 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008473
Douglas Gregor29c42f22012-02-24 07:38:34 +00008474 PackExpansionTypeLoc ToExpansionTL
8475 = TLB.push<PackExpansionTypeLoc>(To);
8476 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8477 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008479
Douglas Gregor29c42f22012-02-24 07:38:34 +00008480 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008481 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008482
8483 return getDerived().RebuildTypeTrait(E->getTrait(),
8484 E->getLocStart(),
8485 Args,
8486 E->getLocEnd());
8487}
8488
8489template<typename Derived>
8490ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008491TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8492 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8493 if (!T)
8494 return ExprError();
8495
8496 if (!getDerived().AlwaysRebuild() &&
8497 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008498 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008499
8500 ExprResult SubExpr;
8501 {
8502 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8503 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8504 if (SubExpr.isInvalid())
8505 return ExprError();
8506
8507 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008508 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008509 }
8510
8511 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8512 E->getLocStart(),
8513 T,
8514 SubExpr.get(),
8515 E->getLocEnd());
8516}
8517
8518template<typename Derived>
8519ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008520TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8521 ExprResult SubExpr;
8522 {
8523 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8524 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8525 if (SubExpr.isInvalid())
8526 return ExprError();
8527
8528 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008529 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008530 }
8531
8532 return getDerived().RebuildExpressionTrait(
8533 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8534}
8535
Reid Kleckner32506ed2014-06-12 23:03:48 +00008536template <typename Derived>
8537ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8538 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8539 TypeSourceInfo **RecoveryTSI) {
8540 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8541 DRE, AddrTaken, RecoveryTSI);
8542
8543 // Propagate both errors and recovered types, which return ExprEmpty.
8544 if (!NewDRE.isUsable())
8545 return NewDRE;
8546
8547 // We got an expr, wrap it up in parens.
8548 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8549 return PE;
8550 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8551 PE->getRParen());
8552}
8553
8554template <typename Derived>
8555ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8556 DependentScopeDeclRefExpr *E) {
8557 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8558 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008559}
8560
8561template<typename Derived>
8562ExprResult
8563TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8564 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008565 bool IsAddressOfOperand,
8566 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008567 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008568 NestedNameSpecifierLoc QualifierLoc
8569 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8570 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008571 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008572 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008573
John McCall31f82722010-11-12 08:19:04 +00008574 // TODO: If this is a conversion-function-id, verify that the
8575 // destination type name (if present) resolves the same way after
8576 // instantiation as it did in the local scope.
8577
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008578 DeclarationNameInfo NameInfo
8579 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8580 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008582
John McCalle66edc12009-11-24 19:00:30 +00008583 if (!E->hasExplicitTemplateArgs()) {
8584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008585 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008586 // Note: it is sufficient to compare the Name component of NameInfo:
8587 // if name has not changed, DNLoc has not changed either.
8588 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008589 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008590
Reid Kleckner32506ed2014-06-12 23:03:48 +00008591 return getDerived().RebuildDependentScopeDeclRefExpr(
8592 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8593 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008594 }
John McCall6b51f282009-11-23 01:53:49 +00008595
8596 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008597 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8598 E->getNumTemplateArgs(),
8599 TransArgs))
8600 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008601
Reid Kleckner32506ed2014-06-12 23:03:48 +00008602 return getDerived().RebuildDependentScopeDeclRefExpr(
8603 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8604 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008605}
8606
8607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008609TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008610 // CXXConstructExprs other than for list-initialization and
8611 // CXXTemporaryObjectExpr are always implicit, so when we have
8612 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008613 if ((E->getNumArgs() == 1 ||
8614 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008615 (!getDerived().DropCallArgument(E->getArg(0))) &&
8616 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008617 return getDerived().TransformExpr(E->getArg(0));
8618
Douglas Gregora16548e2009-08-11 05:31:07 +00008619 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8620
8621 QualType T = getDerived().TransformType(E->getType());
8622 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008623 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008624
8625 CXXConstructorDecl *Constructor
8626 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008627 getDerived().TransformDecl(E->getLocStart(),
8628 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008631
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008633 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008634 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008635 &ArgumentChanged))
8636 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008637
Douglas Gregora16548e2009-08-11 05:31:07 +00008638 if (!getDerived().AlwaysRebuild() &&
8639 T == E->getType() &&
8640 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008641 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008642 // Mark the constructor as referenced.
8643 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008644 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008645 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008646 }
Mike Stump11289f42009-09-09 15:08:12 +00008647
Douglas Gregordb121ba2009-12-14 16:27:04 +00008648 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8649 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008650 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008651 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008652 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008653 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008654 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008655 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008656 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008657}
Mike Stump11289f42009-09-09 15:08:12 +00008658
Douglas Gregora16548e2009-08-11 05:31:07 +00008659/// \brief Transform a C++ temporary-binding expression.
8660///
Douglas Gregor363b1512009-12-24 18:51:59 +00008661/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8662/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008665TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008666 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008667}
Mike Stump11289f42009-09-09 15:08:12 +00008668
John McCall5d413782010-12-06 08:20:24 +00008669/// \brief Transform a C++ expression that contains cleanups that should
8670/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008671///
John McCall5d413782010-12-06 08:20:24 +00008672/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008673/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008675ExprResult
John McCall5d413782010-12-06 08:20:24 +00008676TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008677 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008678}
Mike Stump11289f42009-09-09 15:08:12 +00008679
Douglas Gregora16548e2009-08-11 05:31:07 +00008680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008681ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008682TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008683 CXXTemporaryObjectExpr *E) {
8684 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8685 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008687
Douglas Gregora16548e2009-08-11 05:31:07 +00008688 CXXConstructorDecl *Constructor
8689 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008690 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008691 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008692 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008694
Douglas Gregora16548e2009-08-11 05:31:07 +00008695 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008696 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008697 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008698 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008699 &ArgumentChanged))
8700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008701
Douglas Gregora16548e2009-08-11 05:31:07 +00008702 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008703 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008704 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008705 !ArgumentChanged) {
8706 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008707 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008708 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008710
Richard Smithd59b8322012-12-19 01:39:02 +00008711 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008712 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8713 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008714 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008715 E->getLocEnd());
8716}
Mike Stump11289f42009-09-09 15:08:12 +00008717
Douglas Gregora16548e2009-08-11 05:31:07 +00008718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008719ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008720TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008721
8722 // Transform any init-capture expressions before entering the scope of the
8723 // lambda body, because they are not semantically within that scope.
8724 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8725 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8726 E->explicit_capture_begin());
8727
8728 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8729 CEnd = E->capture_end();
8730 C != CEnd; ++C) {
8731 if (!C->isInitCapture())
8732 continue;
8733 EnterExpressionEvaluationContext EEEC(getSema(),
8734 Sema::PotentiallyEvaluated);
8735 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8736 C->getCapturedVar()->getInit(),
8737 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8738
8739 if (NewExprInitResult.isInvalid())
8740 return ExprError();
8741 Expr *NewExprInit = NewExprInitResult.get();
8742
8743 VarDecl *OldVD = C->getCapturedVar();
8744 QualType NewInitCaptureType =
8745 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8746 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8747 NewExprInit);
8748 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008749 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8750 std::make_pair(NewExprInitResult, NewInitCaptureType);
8751
8752 }
8753
Faisal Vali524ca282013-11-12 01:40:44 +00008754 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008755 // Transform the template parameters, and add them to the current
8756 // instantiation scope. The null case is handled correctly.
8757 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8758 E->getTemplateParameterList());
8759
8760 // Check to see if the TypeSourceInfo of the call operator needs to
8761 // be transformed, and if so do the transformation in the
8762 // CurrentInstantiationScope.
8763
8764 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8765 FunctionProtoTypeLoc OldCallOpFPTL =
8766 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008767 TypeSourceInfo *NewCallOpTSI = nullptr;
8768
Faisal Vali2cba1332013-10-23 06:44:28 +00008769 const bool CallOpWasAlreadyTransformed =
8770 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8771
8772 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8773 if (CallOpWasAlreadyTransformed)
8774 NewCallOpTSI = OldCallOpTSI;
8775 else {
8776 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8777 // The transformation MUST be done in the CurrentInstantiationScope since
8778 // it introduces a mapping of the original to the newly created
8779 // transformed parameters.
8780
8781 TypeLocBuilder NewCallOpTLBuilder;
8782 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8783 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008784 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008785 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8786 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008787 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008788 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8789 // the vector below - this will be used to synthesize the
8790 // NewCallOperator. Additionally, add the parameters of the untransformed
8791 // lambda call operator to the CurrentInstantiationScope.
8792 SmallVector<ParmVarDecl *, 4> Params;
8793 {
8794 FunctionProtoTypeLoc NewCallOpFPTL =
8795 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8796 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008797 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008798
8799 for (unsigned I = 0; I < NewNumArgs; ++I) {
8800 // If this call operator's type does not require transformation,
8801 // the parameters do not get added to the current instantiation scope,
8802 // - so ADD them! This allows the following to compile when the enclosing
8803 // template is specialized and the entire lambda expression has to be
8804 // transformed.
8805 // template<class T> void foo(T t) {
8806 // auto L = [](auto a) {
8807 // auto M = [](char b) { <-- note: non-generic lambda
8808 // auto N = [](auto c) {
8809 // int x = sizeof(a);
8810 // x = sizeof(b); <-- specifically this line
8811 // x = sizeof(c);
8812 // };
8813 // };
8814 // };
8815 // }
8816 // foo('a')
8817 if (CallOpWasAlreadyTransformed)
8818 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8819 NewParamDeclArray[I]);
8820 // Add to Params array, so these parameters can be used to create
8821 // the newly transformed call operator.
8822 Params.push_back(NewParamDeclArray[I]);
8823 }
8824 }
8825
8826 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008827 return ExprError();
8828
Eli Friedmand564afb2012-09-19 01:18:11 +00008829 // Create the local class that will describe the lambda.
8830 CXXRecordDecl *Class
8831 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008832 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008833 /*KnownDependent=*/false,
8834 E->getCaptureDefault());
8835
Eli Friedmand564afb2012-09-19 01:18:11 +00008836 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8837
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008838 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008839 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008840 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008841 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008842 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008843 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008844 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008845
Faisal Vali2cba1332013-10-23 06:44:28 +00008846 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8847
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008848 return getDerived().TransformLambdaScope(E, NewCallOperator,
8849 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008850}
8851
8852template<typename Derived>
8853ExprResult
8854TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008855 CXXMethodDecl *CallOperator,
8856 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008857 bool Invalid = false;
8858
Douglas Gregorb4328232012-02-14 00:00:48 +00008859 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008860 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8861 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008862
Faisal Vali2b391ab2013-09-26 19:54:12 +00008863 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008864 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008865 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008866 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008867 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008868 E->hasExplicitParameters(),
8869 E->hasExplicitResultType(),
8870 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008871
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008872 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008873 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008874 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008875 CEnd = E->capture_end();
8876 C != CEnd; ++C) {
8877 // When we hit the first implicit capture, tell Sema that we've finished
8878 // the list of explicit captures.
8879 if (!FinishedExplicitCaptures && C->isImplicit()) {
8880 getSema().finishLambdaExplicitCaptures(LSI);
8881 FinishedExplicitCaptures = true;
8882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008884 // Capturing 'this' is trivial.
8885 if (C->capturesThis()) {
8886 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8887 continue;
8888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008889
Richard Smithba71c082013-05-16 06:20:58 +00008890 // Rebuild init-captures, including the implied field declaration.
8891 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008892
8893 InitCaptureInfoTy InitExprTypePair =
8894 InitCaptureExprsAndTypes[C - E->capture_begin()];
8895 ExprResult Init = InitExprTypePair.first;
8896 QualType InitQualType = InitExprTypePair.second;
8897 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008898 Invalid = true;
8899 continue;
8900 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008901 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008902 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8903 OldVD->getLocation(), InitExprTypePair.second,
8904 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008905 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008906 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008907 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008908 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008909 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008910 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008911 continue;
8912 }
8913
8914 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8915
Douglas Gregor3e308b12012-02-14 19:27:52 +00008916 // Determine the capture kind for Sema.
8917 Sema::TryCaptureKind Kind
8918 = C->isImplicit()? Sema::TryCapture_Implicit
8919 : C->getCaptureKind() == LCK_ByCopy
8920 ? Sema::TryCapture_ExplicitByVal
8921 : Sema::TryCapture_ExplicitByRef;
8922 SourceLocation EllipsisLoc;
8923 if (C->isPackExpansion()) {
8924 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8925 bool ShouldExpand = false;
8926 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008927 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008928 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8929 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008930 Unexpanded,
8931 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008932 NumExpansions)) {
8933 Invalid = true;
8934 continue;
8935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008936
Douglas Gregor3e308b12012-02-14 19:27:52 +00008937 if (ShouldExpand) {
8938 // The transform has determined that we should perform an expansion;
8939 // transform and capture each of the arguments.
8940 // expansion of the pattern. Do so.
8941 VarDecl *Pack = C->getCapturedVar();
8942 for (unsigned I = 0; I != *NumExpansions; ++I) {
8943 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8944 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008945 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008946 Pack));
8947 if (!CapturedVar) {
8948 Invalid = true;
8949 continue;
8950 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008951
Douglas Gregor3e308b12012-02-14 19:27:52 +00008952 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008953 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8954 }
Richard Smith9467be42014-06-06 17:33:35 +00008955
8956 // FIXME: Retain a pack expansion if RetainExpansion is true.
8957
Douglas Gregor3e308b12012-02-14 19:27:52 +00008958 continue;
8959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008960
Douglas Gregor3e308b12012-02-14 19:27:52 +00008961 EllipsisLoc = C->getEllipsisLoc();
8962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008963
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008964 // Transform the captured variable.
8965 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008966 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008967 C->getCapturedVar()));
8968 if (!CapturedVar) {
8969 Invalid = true;
8970 continue;
8971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008972
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008973 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008974 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008975 }
8976 if (!FinishedExplicitCaptures)
8977 getSema().finishLambdaExplicitCaptures(LSI);
8978
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008979
8980 // Enter a new evaluation context to insulate the lambda from any
8981 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008982 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008983
8984 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008985 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008986 /*IsInstantiation=*/true);
8987 return ExprError();
8988 }
8989
8990 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008991 StmtResult Body = getDerived().TransformStmt(E->getBody());
8992 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008993 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008994 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008995 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008996 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008997
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008998 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008999 /*CurScope=*/nullptr,
9000 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009001}
9002
9003template<typename Derived>
9004ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009005TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009006 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009007 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9008 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009010
Douglas Gregora16548e2009-08-11 05:31:07 +00009011 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009012 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009013 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009014 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009015 &ArgumentChanged))
9016 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009017
Douglas Gregora16548e2009-08-11 05:31:07 +00009018 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009019 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009020 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009021 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009022
Douglas Gregora16548e2009-08-11 05:31:07 +00009023 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009024 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009025 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009026 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009027 E->getRParenLoc());
9028}
Mike Stump11289f42009-09-09 15:08:12 +00009029
Douglas Gregora16548e2009-08-11 05:31:07 +00009030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009031ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009032TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009033 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009034 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009035 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009036 Expr *OldBase;
9037 QualType BaseType;
9038 QualType ObjectType;
9039 if (!E->isImplicitAccess()) {
9040 OldBase = E->getBase();
9041 Base = getDerived().TransformExpr(OldBase);
9042 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009043 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009044
John McCall2d74de92009-12-01 22:10:20 +00009045 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009046 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009047 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009048 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009049 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009050 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009051 ObjectTy,
9052 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009053 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009054 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009055
John McCallba7bf592010-08-24 05:47:05 +00009056 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009057 BaseType = ((Expr*) Base.get())->getType();
9058 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009059 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009060 BaseType = getDerived().TransformType(E->getBaseType());
9061 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9062 }
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009064 // Transform the first part of the nested-name-specifier that qualifies
9065 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009066 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009067 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009068 E->getFirstQualifierFoundInScope(),
9069 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009070
Douglas Gregore16af532011-02-28 18:50:33 +00009071 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009072 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009073 QualifierLoc
9074 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9075 ObjectType,
9076 FirstQualifierInScope);
9077 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009078 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009079 }
Mike Stump11289f42009-09-09 15:08:12 +00009080
Abramo Bagnara7945c982012-01-27 09:46:47 +00009081 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9082
John McCall31f82722010-11-12 08:19:04 +00009083 // TODO: If this is a conversion-function-id, verify that the
9084 // destination type name (if present) resolves the same way after
9085 // instantiation as it did in the local scope.
9086
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009087 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009088 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009089 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009091
John McCall2d74de92009-12-01 22:10:20 +00009092 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009093 // This is a reference to a member without an explicitly-specified
9094 // template argument list. Optimize for this common case.
9095 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009096 Base.get() == OldBase &&
9097 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009098 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009099 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009100 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009101 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009102
John McCallb268a282010-08-23 23:25:46 +00009103 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009104 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009105 E->isArrow(),
9106 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009107 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009108 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009109 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009110 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009111 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009112 }
9113
John McCall6b51f282009-11-23 01:53:49 +00009114 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009115 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9116 E->getNumTemplateArgs(),
9117 TransArgs))
9118 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009119
John McCallb268a282010-08-23 23:25:46 +00009120 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009121 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009122 E->isArrow(),
9123 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009124 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009125 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009126 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009127 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009128 &TransArgs);
9129}
9130
9131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009133TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009134 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009135 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009136 QualType BaseType;
9137 if (!Old->isImplicitAccess()) {
9138 Base = getDerived().TransformExpr(Old->getBase());
9139 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009140 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009141 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009142 Old->isArrow());
9143 if (Base.isInvalid())
9144 return ExprError();
9145 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009146 } else {
9147 BaseType = getDerived().TransformType(Old->getBaseType());
9148 }
John McCall10eae182009-11-30 22:42:35 +00009149
Douglas Gregor0da1d432011-02-28 20:01:57 +00009150 NestedNameSpecifierLoc QualifierLoc;
9151 if (Old->getQualifierLoc()) {
9152 QualifierLoc
9153 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9154 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009155 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009156 }
9157
Abramo Bagnara7945c982012-01-27 09:46:47 +00009158 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9159
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009160 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009161 Sema::LookupOrdinaryName);
9162
9163 // Transform all the decls.
9164 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9165 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009166 NamedDecl *InstD = static_cast<NamedDecl*>(
9167 getDerived().TransformDecl(Old->getMemberLoc(),
9168 *I));
John McCall84d87672009-12-10 09:41:52 +00009169 if (!InstD) {
9170 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9171 // This can happen because of dependent hiding.
9172 if (isa<UsingShadowDecl>(*I))
9173 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009174 else {
9175 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009176 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009177 }
John McCall84d87672009-12-10 09:41:52 +00009178 }
John McCall10eae182009-11-30 22:42:35 +00009179
9180 // Expand using declarations.
9181 if (isa<UsingDecl>(InstD)) {
9182 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009183 for (auto *I : UD->shadows())
9184 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009185 continue;
9186 }
9187
9188 R.addDecl(InstD);
9189 }
9190
9191 R.resolveKind();
9192
Douglas Gregor9262f472010-04-27 18:19:34 +00009193 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009194 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009195 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009196 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009197 Old->getMemberLoc(),
9198 Old->getNamingClass()));
9199 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009200 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009201
Douglas Gregorda7be082010-04-27 16:10:10 +00009202 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009204
John McCall10eae182009-11-30 22:42:35 +00009205 TemplateArgumentListInfo TransArgs;
9206 if (Old->hasExplicitTemplateArgs()) {
9207 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9208 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009209 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9210 Old->getNumTemplateArgs(),
9211 TransArgs))
9212 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009213 }
John McCall38836f02010-01-15 08:34:02 +00009214
9215 // FIXME: to do this check properly, we will need to preserve the
9216 // first-qualifier-in-scope here, just in case we had a dependent
9217 // base (and therefore couldn't do the check) and a
9218 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009219 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009220
John McCallb268a282010-08-23 23:25:46 +00009221 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009222 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009223 Old->getOperatorLoc(),
9224 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009225 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009226 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009227 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009228 R,
9229 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009230 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
9232
9233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009235TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009236 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009237 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9238 if (SubExpr.isInvalid())
9239 return ExprError();
9240
9241 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009242 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009243
9244 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9245}
9246
9247template<typename Derived>
9248ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009249TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009250 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9251 if (Pattern.isInvalid())
9252 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009253
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009254 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009255 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009256
Douglas Gregorb8840002011-01-14 21:20:45 +00009257 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9258 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009259}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009260
9261template<typename Derived>
9262ExprResult
9263TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9264 // If E is not value-dependent, then nothing will change when we transform it.
9265 // Note: This is an instantiation-centric view.
9266 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009267 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009268
9269 // Note: None of the implementations of TryExpandParameterPacks can ever
9270 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009271 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009272 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9273 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009274 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009275 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009276 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009277 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009278 ShouldExpand, RetainExpansion,
9279 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009280 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009281
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009282 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009283 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009284
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009285 NamedDecl *Pack = E->getPack();
9286 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009287 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009288 Pack));
9289 if (!Pack)
9290 return ExprError();
9291 }
9292
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009294 // We now know the length of the parameter pack, so build a new expression
9295 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009296 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9297 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009298 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009299}
9300
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009301template<typename Derived>
9302ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009303TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9304 SubstNonTypeTemplateParmPackExpr *E) {
9305 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009306 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009307}
9308
9309template<typename Derived>
9310ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009311TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9312 SubstNonTypeTemplateParmExpr *E) {
9313 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009314 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009315}
9316
9317template<typename Derived>
9318ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009319TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9320 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009321 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009322}
9323
9324template<typename Derived>
9325ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009326TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9327 MaterializeTemporaryExpr *E) {
9328 return getDerived().TransformExpr(E->GetTemporaryExpr());
9329}
Chad Rosier1dcde962012-08-08 18:46:20 +00009330
Douglas Gregorfe314812011-06-21 17:03:29 +00009331template<typename Derived>
9332ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009333TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9334 CXXStdInitializerListExpr *E) {
9335 return getDerived().TransformExpr(E->getSubExpr());
9336}
9337
9338template<typename Derived>
9339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009340TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009341 return SemaRef.MaybeBindToTemporary(E);
9342}
9343
9344template<typename Derived>
9345ExprResult
9346TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009347 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009348}
9349
9350template<typename Derived>
9351ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009352TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9353 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9354 if (SubExpr.isInvalid())
9355 return ExprError();
9356
9357 if (!getDerived().AlwaysRebuild() &&
9358 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009359 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009360
9361 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009362}
9363
9364template<typename Derived>
9365ExprResult
9366TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9367 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009368 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009369 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009370 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009371 /*IsCall=*/false, Elements, &ArgChanged))
9372 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009373
Ted Kremeneke65b0862012-03-06 20:05:56 +00009374 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9375 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009376
Ted Kremeneke65b0862012-03-06 20:05:56 +00009377 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9378 Elements.data(),
9379 Elements.size());
9380}
9381
9382template<typename Derived>
9383ExprResult
9384TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009385 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009386 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009387 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009388 bool ArgChanged = false;
9389 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9390 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009391
Ted Kremeneke65b0862012-03-06 20:05:56 +00009392 if (OrigElement.isPackExpansion()) {
9393 // This key/value element is a pack expansion.
9394 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9395 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9396 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9397 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9398
9399 // Determine whether the set of unexpanded parameter packs can
9400 // and should be expanded.
9401 bool Expand = true;
9402 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009403 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9404 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009405 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9406 OrigElement.Value->getLocEnd());
9407 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9408 PatternRange,
9409 Unexpanded,
9410 Expand, RetainExpansion,
9411 NumExpansions))
9412 return ExprError();
9413
9414 if (!Expand) {
9415 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009416 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009417 // expansion.
9418 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9419 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9420 if (Key.isInvalid())
9421 return ExprError();
9422
9423 if (Key.get() != OrigElement.Key)
9424 ArgChanged = true;
9425
9426 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9427 if (Value.isInvalid())
9428 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009429
Ted Kremeneke65b0862012-03-06 20:05:56 +00009430 if (Value.get() != OrigElement.Value)
9431 ArgChanged = true;
9432
Chad Rosier1dcde962012-08-08 18:46:20 +00009433 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009434 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9435 };
9436 Elements.push_back(Expansion);
9437 continue;
9438 }
9439
9440 // Record right away that the argument was changed. This needs
9441 // to happen even if the array expands to nothing.
9442 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009443
Ted Kremeneke65b0862012-03-06 20:05:56 +00009444 // The transform has determined that we should perform an elementwise
9445 // expansion of the pattern. Do so.
9446 for (unsigned I = 0; I != *NumExpansions; ++I) {
9447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9448 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9449 if (Key.isInvalid())
9450 return ExprError();
9451
9452 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9453 if (Value.isInvalid())
9454 return ExprError();
9455
Chad Rosier1dcde962012-08-08 18:46:20 +00009456 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009457 Key.get(), Value.get(), SourceLocation(), NumExpansions
9458 };
9459
9460 // If any unexpanded parameter packs remain, we still have a
9461 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009462 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009463 if (Key.get()->containsUnexpandedParameterPack() ||
9464 Value.get()->containsUnexpandedParameterPack())
9465 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009466
Ted Kremeneke65b0862012-03-06 20:05:56 +00009467 Elements.push_back(Element);
9468 }
9469
Richard Smith9467be42014-06-06 17:33:35 +00009470 // FIXME: Retain a pack expansion if RetainExpansion is true.
9471
Ted Kremeneke65b0862012-03-06 20:05:56 +00009472 // We've finished with this pack expansion.
9473 continue;
9474 }
9475
9476 // Transform and check key.
9477 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9478 if (Key.isInvalid())
9479 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009480
Ted Kremeneke65b0862012-03-06 20:05:56 +00009481 if (Key.get() != OrigElement.Key)
9482 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009483
Ted Kremeneke65b0862012-03-06 20:05:56 +00009484 // Transform and check value.
9485 ExprResult Value
9486 = getDerived().TransformExpr(OrigElement.Value);
9487 if (Value.isInvalid())
9488 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009489
Ted Kremeneke65b0862012-03-06 20:05:56 +00009490 if (Value.get() != OrigElement.Value)
9491 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009492
9493 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009494 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009495 };
9496 Elements.push_back(Element);
9497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009498
Ted Kremeneke65b0862012-03-06 20:05:56 +00009499 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9500 return SemaRef.MaybeBindToTemporary(E);
9501
9502 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9503 Elements.data(),
9504 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009505}
9506
Mike Stump11289f42009-09-09 15:08:12 +00009507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009509TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009510 TypeSourceInfo *EncodedTypeInfo
9511 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9512 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009514
Douglas Gregora16548e2009-08-11 05:31:07 +00009515 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009516 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009517 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009518
9519 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009520 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009521 E->getRParenLoc());
9522}
Mike Stump11289f42009-09-09 15:08:12 +00009523
Douglas Gregora16548e2009-08-11 05:31:07 +00009524template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009525ExprResult TreeTransform<Derived>::
9526TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009527 // This is a kind of implicit conversion, and it needs to get dropped
9528 // and recomputed for the same general reasons that ImplicitCastExprs
9529 // do, as well a more specific one: this expression is only valid when
9530 // it appears *immediately* as an argument expression.
9531 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009532}
9533
9534template<typename Derived>
9535ExprResult TreeTransform<Derived>::
9536TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009537 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009538 = getDerived().TransformType(E->getTypeInfoAsWritten());
9539 if (!TSInfo)
9540 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009541
John McCall31168b02011-06-15 23:02:42 +00009542 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009543 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009544 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009545
John McCall31168b02011-06-15 23:02:42 +00009546 if (!getDerived().AlwaysRebuild() &&
9547 TSInfo == E->getTypeInfoAsWritten() &&
9548 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009549 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009550
John McCall31168b02011-06-15 23:02:42 +00009551 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009552 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009553 Result.get());
9554}
9555
9556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009558TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009559 // Transform arguments.
9560 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009561 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009562 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009563 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009564 &ArgChanged))
9565 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009566
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009567 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9568 // Class message: transform the receiver type.
9569 TypeSourceInfo *ReceiverTypeInfo
9570 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9571 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009572 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009573
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009574 // If nothing changed, just retain the existing message send.
9575 if (!getDerived().AlwaysRebuild() &&
9576 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009577 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009578
9579 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009580 SmallVector<SourceLocation, 16> SelLocs;
9581 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009582 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9583 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009584 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009585 E->getMethodDecl(),
9586 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009587 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009588 E->getRightLoc());
9589 }
9590
9591 // Instance message: transform the receiver
9592 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9593 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009594 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009595 = getDerived().TransformExpr(E->getInstanceReceiver());
9596 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009597 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009598
9599 // If nothing changed, just retain the existing message send.
9600 if (!getDerived().AlwaysRebuild() &&
9601 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009602 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009603
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009604 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009605 SmallVector<SourceLocation, 16> SelLocs;
9606 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009607 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009608 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009609 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009610 E->getMethodDecl(),
9611 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009612 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009613 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009614}
9615
Mike Stump11289f42009-09-09 15:08:12 +00009616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009618TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009619 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009620}
9621
Mike Stump11289f42009-09-09 15:08:12 +00009622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009624TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009625 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009626}
9627
Mike Stump11289f42009-09-09 15:08:12 +00009628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009630TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009631 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009632 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009633 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009634 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009635
9636 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009637
Douglas Gregord51d90d2010-04-26 20:11:03 +00009638 // If nothing changed, just retain the existing expression.
9639 if (!getDerived().AlwaysRebuild() &&
9640 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009641 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009642
John McCallb268a282010-08-23 23:25:46 +00009643 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009644 E->getLocation(),
9645 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009646}
9647
Mike Stump11289f42009-09-09 15:08:12 +00009648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009650TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009651 // 'super' and types never change. Property never changes. Just
9652 // retain the existing expression.
9653 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009654 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009655
Douglas Gregor9faee212010-04-26 20:47:02 +00009656 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009657 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009658 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009659 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009660
Douglas Gregor9faee212010-04-26 20:47:02 +00009661 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009662
Douglas Gregor9faee212010-04-26 20:47:02 +00009663 // If nothing changed, just retain the existing expression.
9664 if (!getDerived().AlwaysRebuild() &&
9665 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009666 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009667
John McCallb7bd14f2010-12-02 01:19:52 +00009668 if (E->isExplicitProperty())
9669 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9670 E->getExplicitProperty(),
9671 E->getLocation());
9672
9673 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009674 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009675 E->getImplicitPropertyGetter(),
9676 E->getImplicitPropertySetter(),
9677 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009678}
9679
Mike Stump11289f42009-09-09 15:08:12 +00009680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009681ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009682TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9683 // Transform the base expression.
9684 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9685 if (Base.isInvalid())
9686 return ExprError();
9687
9688 // Transform the key expression.
9689 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9690 if (Key.isInvalid())
9691 return ExprError();
9692
9693 // If nothing changed, just retain the existing expression.
9694 if (!getDerived().AlwaysRebuild() &&
9695 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009696 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009697
Chad Rosier1dcde962012-08-08 18:46:20 +00009698 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009699 Base.get(), Key.get(),
9700 E->getAtIndexMethodDecl(),
9701 E->setAtIndexMethodDecl());
9702}
9703
9704template<typename Derived>
9705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009706TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009707 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009708 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009709 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009710 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009711
Douglas Gregord51d90d2010-04-26 20:11:03 +00009712 // If nothing changed, just retain the existing expression.
9713 if (!getDerived().AlwaysRebuild() &&
9714 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009715 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009716
John McCallb268a282010-08-23 23:25:46 +00009717 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009718 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009719 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009720}
9721
Mike Stump11289f42009-09-09 15:08:12 +00009722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009724TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009725 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009726 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009727 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009728 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009729 SubExprs, &ArgumentChanged))
9730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009731
Douglas Gregora16548e2009-08-11 05:31:07 +00009732 if (!getDerived().AlwaysRebuild() &&
9733 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009734 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009735
Douglas Gregora16548e2009-08-11 05:31:07 +00009736 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009737 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009738 E->getRParenLoc());
9739}
9740
Mike Stump11289f42009-09-09 15:08:12 +00009741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009742ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009743TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9744 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9745 if (SrcExpr.isInvalid())
9746 return ExprError();
9747
9748 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9749 if (!Type)
9750 return ExprError();
9751
9752 if (!getDerived().AlwaysRebuild() &&
9753 Type == E->getTypeSourceInfo() &&
9754 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009755 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009756
9757 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9758 SrcExpr.get(), Type,
9759 E->getRParenLoc());
9760}
9761
9762template<typename Derived>
9763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009764TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009765 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009766
Craig Topperc3ec1492014-05-26 06:22:03 +00009767 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009768 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9769
9770 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009771 blockScope->TheDecl->setBlockMissingReturnType(
9772 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009773
Chris Lattner01cf8db2011-07-20 06:58:45 +00009774 SmallVector<ParmVarDecl*, 4> params;
9775 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009776
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009777 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009778 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9779 oldBlock->param_begin(),
9780 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009781 nullptr, paramTypes, &params)) {
9782 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009783 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009784 }
John McCall490112f2011-02-04 18:33:18 +00009785
Jordan Rosea0a86be2013-03-08 22:25:36 +00009786 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009787 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009788 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009789
Jordan Rose5c382722013-03-08 21:51:21 +00009790 QualType functionType =
9791 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009792 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009793 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009794
9795 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009796 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009797 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009798
9799 if (!oldBlock->blockMissingReturnType()) {
9800 blockScope->HasImplicitReturnType = false;
9801 blockScope->ReturnType = exprResultType;
9802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009803
John McCall3882ace2011-01-05 12:14:39 +00009804 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009805 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009806 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009807 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009808 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009809 }
John McCall3882ace2011-01-05 12:14:39 +00009810
John McCall490112f2011-02-04 18:33:18 +00009811#ifndef NDEBUG
9812 // In builds with assertions, make sure that we captured everything we
9813 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009814 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009815 for (const auto &I : oldBlock->captures()) {
9816 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009817
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009818 // Ignore parameter packs.
9819 if (isa<ParmVarDecl>(oldCapture) &&
9820 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9821 continue;
John McCall490112f2011-02-04 18:33:18 +00009822
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009823 VarDecl *newCapture =
9824 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9825 oldCapture));
9826 assert(blockScope->CaptureMap.count(newCapture));
9827 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009828 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009829 }
9830#endif
9831
9832 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009833 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009834}
9835
Mike Stump11289f42009-09-09 15:08:12 +00009836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009837ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009838TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009839 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009840}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009841
9842template<typename Derived>
9843ExprResult
9844TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009845 QualType RetTy = getDerived().TransformType(E->getType());
9846 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009847 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009848 SubExprs.reserve(E->getNumSubExprs());
9849 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9850 SubExprs, &ArgumentChanged))
9851 return ExprError();
9852
9853 if (!getDerived().AlwaysRebuild() &&
9854 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009855 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009856
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009857 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009858 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009859}
Chad Rosier1dcde962012-08-08 18:46:20 +00009860
Douglas Gregora16548e2009-08-11 05:31:07 +00009861//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009862// Type reconstruction
9863//===----------------------------------------------------------------------===//
9864
Mike Stump11289f42009-09-09 15:08:12 +00009865template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009866QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9867 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009868 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009869 getDerived().getBaseEntity());
9870}
9871
Mike Stump11289f42009-09-09 15:08:12 +00009872template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009873QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9874 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009875 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009876 getDerived().getBaseEntity());
9877}
9878
Mike Stump11289f42009-09-09 15:08:12 +00009879template<typename Derived>
9880QualType
John McCall70dd5f62009-10-30 00:06:24 +00009881TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9882 bool WrittenAsLValue,
9883 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009884 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009885 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009886}
9887
9888template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009889QualType
John McCall70dd5f62009-10-30 00:06:24 +00009890TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9891 QualType ClassType,
9892 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009893 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9894 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009895}
9896
9897template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009898QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009899TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9900 ArrayType::ArraySizeModifier SizeMod,
9901 const llvm::APInt *Size,
9902 Expr *SizeExpr,
9903 unsigned IndexTypeQuals,
9904 SourceRange BracketsRange) {
9905 if (SizeExpr || !Size)
9906 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9907 IndexTypeQuals, BracketsRange,
9908 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009909
9910 QualType Types[] = {
9911 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9912 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9913 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009914 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009915 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009916 QualType SizeType;
9917 for (unsigned I = 0; I != NumTypes; ++I)
9918 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9919 SizeType = Types[I];
9920 break;
9921 }
Mike Stump11289f42009-09-09 15:08:12 +00009922
Eli Friedman9562f392012-01-25 23:20:27 +00009923 // Note that we can return a VariableArrayType here in the case where
9924 // the element type was a dependent VariableArrayType.
9925 IntegerLiteral *ArraySize
9926 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9927 /*FIXME*/BracketsRange.getBegin());
9928 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009929 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009930 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009931}
Mike Stump11289f42009-09-09 15:08:12 +00009932
Douglas Gregord6ff3322009-08-04 16:50:30 +00009933template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009934QualType
9935TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009936 ArrayType::ArraySizeModifier SizeMod,
9937 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009938 unsigned IndexTypeQuals,
9939 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009940 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009941 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009942}
9943
9944template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009945QualType
Mike Stump11289f42009-09-09 15:08:12 +00009946TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009947 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009948 unsigned IndexTypeQuals,
9949 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009950 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009951 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009952}
Mike Stump11289f42009-09-09 15:08:12 +00009953
Douglas Gregord6ff3322009-08-04 16:50:30 +00009954template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009955QualType
9956TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009957 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009958 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009959 unsigned IndexTypeQuals,
9960 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009961 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009962 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009963 IndexTypeQuals, BracketsRange);
9964}
9965
9966template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009967QualType
9968TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009969 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009970 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009971 unsigned IndexTypeQuals,
9972 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009973 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009974 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009975 IndexTypeQuals, BracketsRange);
9976}
9977
9978template<typename Derived>
9979QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009980 unsigned NumElements,
9981 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009982 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009983 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009984}
Mike Stump11289f42009-09-09 15:08:12 +00009985
Douglas Gregord6ff3322009-08-04 16:50:30 +00009986template<typename Derived>
9987QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9988 unsigned NumElements,
9989 SourceLocation AttributeLoc) {
9990 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9991 NumElements, true);
9992 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009993 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9994 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009995 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009996}
Mike Stump11289f42009-09-09 15:08:12 +00009997
Douglas Gregord6ff3322009-08-04 16:50:30 +00009998template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009999QualType
10000TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010001 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010002 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010003 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010004}
Mike Stump11289f42009-09-09 15:08:12 +000010005
Douglas Gregord6ff3322009-08-04 16:50:30 +000010006template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010007QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10008 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010009 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010010 const FunctionProtoType::ExtProtoInfo &EPI) {
10011 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010012 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010013 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010014 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010015}
Mike Stump11289f42009-09-09 15:08:12 +000010016
Douglas Gregord6ff3322009-08-04 16:50:30 +000010017template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010018QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10019 return SemaRef.Context.getFunctionNoProtoType(T);
10020}
10021
10022template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010023QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10024 assert(D && "no decl found");
10025 if (D->isInvalidDecl()) return QualType();
10026
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010027 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010028 TypeDecl *Ty;
10029 if (isa<UsingDecl>(D)) {
10030 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010031 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010032 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10033
10034 // A valid resolved using typename decl points to exactly one type decl.
10035 assert(++Using->shadow_begin() == Using->shadow_end());
10036 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010037
John McCallb96ec562009-12-04 22:46:56 +000010038 } else {
10039 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10040 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10041 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10042 }
10043
10044 return SemaRef.Context.getTypeDeclType(Ty);
10045}
10046
10047template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010048QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10049 SourceLocation Loc) {
10050 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010051}
10052
10053template<typename Derived>
10054QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10055 return SemaRef.Context.getTypeOfType(Underlying);
10056}
10057
10058template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010059QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10060 SourceLocation Loc) {
10061 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010062}
10063
10064template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010065QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10066 UnaryTransformType::UTTKind UKind,
10067 SourceLocation Loc) {
10068 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10069}
10070
10071template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010072QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010073 TemplateName Template,
10074 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010075 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010076 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010077}
Mike Stump11289f42009-09-09 15:08:12 +000010078
Douglas Gregor1135c352009-08-06 05:28:30 +000010079template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010080QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10081 SourceLocation KWLoc) {
10082 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10083}
10084
10085template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010086TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010087TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010088 bool TemplateKW,
10089 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010090 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010091 Template);
10092}
10093
10094template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010095TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010096TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10097 const IdentifierInfo &Name,
10098 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010099 QualType ObjectType,
10100 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010101 UnqualifiedId TemplateName;
10102 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010103 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010104 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010105 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010106 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010107 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010108 /*EnteringContext=*/false,
10109 Template);
John McCall31f82722010-11-12 08:19:04 +000010110 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010111}
Mike Stump11289f42009-09-09 15:08:12 +000010112
Douglas Gregora16548e2009-08-11 05:31:07 +000010113template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010114TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010115TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010116 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010117 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010118 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010119 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010120 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010121 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010122 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010123 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010124 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010125 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010126 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010127 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010128 /*EnteringContext=*/false,
10129 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010130 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010131}
Chad Rosier1dcde962012-08-08 18:46:20 +000010132
Douglas Gregor71395fa2009-11-04 00:56:37 +000010133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010134ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010135TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10136 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010137 Expr *OrigCallee,
10138 Expr *First,
10139 Expr *Second) {
10140 Expr *Callee = OrigCallee->IgnoreParenCasts();
10141 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010142
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010143 if (First->getObjectKind() == OK_ObjCProperty) {
10144 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10145 if (BinaryOperator::isAssignmentOp(Opc))
10146 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10147 First, Second);
10148 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10149 if (Result.isInvalid())
10150 return ExprError();
10151 First = Result.get();
10152 }
10153
10154 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10155 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10156 if (Result.isInvalid())
10157 return ExprError();
10158 Second = Result.get();
10159 }
10160
Douglas Gregora16548e2009-08-11 05:31:07 +000010161 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010162 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010163 if (!First->getType()->isOverloadableType() &&
10164 !Second->getType()->isOverloadableType())
10165 return getSema().CreateBuiltinArraySubscriptExpr(First,
10166 Callee->getLocStart(),
10167 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010168 } else if (Op == OO_Arrow) {
10169 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010170 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10171 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010172 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010173 // The argument is not of overloadable type, so try to create a
10174 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010175 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010176 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010177
John McCallb268a282010-08-23 23:25:46 +000010178 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010179 }
10180 } else {
John McCallb268a282010-08-23 23:25:46 +000010181 if (!First->getType()->isOverloadableType() &&
10182 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010183 // Neither of the arguments is an overloadable type, so try to
10184 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010185 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010186 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010187 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010188 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010190
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010191 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010192 }
10193 }
Mike Stump11289f42009-09-09 15:08:12 +000010194
10195 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010196 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010197 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010198
John McCallb268a282010-08-23 23:25:46 +000010199 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010200 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010201 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010202 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010203 // If we've resolved this to a particular non-member function, just call
10204 // that function. If we resolved it to a member function,
10205 // CreateOverloaded* will find that function for us.
10206 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10207 if (!isa<CXXMethodDecl>(ND))
10208 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010209 }
Mike Stump11289f42009-09-09 15:08:12 +000010210
Douglas Gregora16548e2009-08-11 05:31:07 +000010211 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010212 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010213 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010214
Douglas Gregora16548e2009-08-11 05:31:07 +000010215 // Create the overloaded operator invocation for unary operators.
10216 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010217 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010218 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010219 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010220 }
Mike Stump11289f42009-09-09 15:08:12 +000010221
Douglas Gregore9d62932011-07-15 16:25:15 +000010222 if (Op == OO_Subscript) {
10223 SourceLocation LBrace;
10224 SourceLocation RBrace;
10225
10226 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10227 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10228 LBrace = SourceLocation::getFromRawEncoding(
10229 NameLoc.CXXOperatorName.BeginOpNameLoc);
10230 RBrace = SourceLocation::getFromRawEncoding(
10231 NameLoc.CXXOperatorName.EndOpNameLoc);
10232 } else {
10233 LBrace = Callee->getLocStart();
10234 RBrace = OpLoc;
10235 }
10236
10237 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10238 First, Second);
10239 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010240
Douglas Gregora16548e2009-08-11 05:31:07 +000010241 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010242 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010243 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010244 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10245 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010247
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010248 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010249}
Mike Stump11289f42009-09-09 15:08:12 +000010250
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010251template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010252ExprResult
John McCallb268a282010-08-23 23:25:46 +000010253TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010254 SourceLocation OperatorLoc,
10255 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010256 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010257 TypeSourceInfo *ScopeType,
10258 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010259 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010260 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010261 QualType BaseType = Base->getType();
10262 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010263 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010264 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010265 !BaseType->getAs<PointerType>()->getPointeeType()
10266 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010267 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010268 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010269 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010270 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010271 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010272 /*FIXME?*/true);
10273 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010274
Douglas Gregor678f90d2010-02-25 01:56:36 +000010275 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010276 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10277 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10278 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10279 NameInfo.setNamedTypeInfo(DestroyedType);
10280
Richard Smith8e4a3862012-05-15 06:15:11 +000010281 // The scope type is now known to be a valid nested name specifier
10282 // component. Tack it on to the end of the nested name specifier.
10283 if (ScopeType)
10284 SS.Extend(SemaRef.Context, SourceLocation(),
10285 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010286
Abramo Bagnara7945c982012-01-27 09:46:47 +000010287 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010288 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010289 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010290 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010291 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010292 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010293 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010294}
10295
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010296template<typename Derived>
10297StmtResult
10298TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010299 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010300 CapturedDecl *CD = S->getCapturedDecl();
10301 unsigned NumParams = CD->getNumParams();
10302 unsigned ContextParamPos = CD->getContextParamPosition();
10303 SmallVector<Sema::CapturedParamNameType, 4> Params;
10304 for (unsigned I = 0; I < NumParams; ++I) {
10305 if (I != ContextParamPos) {
10306 Params.push_back(
10307 std::make_pair(
10308 CD->getParam(I)->getName(),
10309 getDerived().TransformType(CD->getParam(I)->getType())));
10310 } else {
10311 Params.push_back(std::make_pair(StringRef(), QualType()));
10312 }
10313 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010314 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010315 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010316 StmtResult Body;
10317 {
10318 Sema::CompoundScopeRAII CompoundScope(getSema());
10319 Body = getDerived().TransformStmt(S->getCapturedStmt());
10320 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010321
10322 if (Body.isInvalid()) {
10323 getSema().ActOnCapturedRegionError();
10324 return StmtError();
10325 }
10326
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010327 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010328}
10329
Douglas Gregord6ff3322009-08-04 16:50:30 +000010330} // end namespace clang
10331
10332#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H