blob: 1a71c0a4a5ec80070a5d16ae5a2897d99ce2a3f7 [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 Bataev568a8332014-03-06 06:15:19 +00001321 /// \brief Build a new OpenMP 'num_threads' clause.
1322 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001323 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1326 SourceLocation StartLoc,
1327 SourceLocation LParenLoc,
1328 SourceLocation EndLoc) {
1329 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1330 LParenLoc, EndLoc);
1331 }
1332
Alexey Bataev62c87d22014-03-21 04:51:18 +00001333 /// \brief Build a new OpenMP 'safelen' clause.
1334 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001335 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001336 /// Subclasses may override this routine to provide different behavior.
1337 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1341 }
1342
Alexander Musman8bd31e62014-05-27 15:12:19 +00001343 /// \brief Build a new OpenMP 'collapse' clause.
1344 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001345 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1351 EndLoc);
1352 }
1353
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001354 /// \brief Build a new OpenMP 'default' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1359 SourceLocation KindKwLoc,
1360 SourceLocation StartLoc,
1361 SourceLocation LParenLoc,
1362 SourceLocation EndLoc) {
1363 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1364 StartLoc, LParenLoc, EndLoc);
1365 }
1366
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001367 /// \brief Build a new OpenMP 'proc_bind' clause.
1368 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001369 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001370 /// Subclasses may override this routine to provide different behavior.
1371 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1372 SourceLocation KindKwLoc,
1373 SourceLocation StartLoc,
1374 SourceLocation LParenLoc,
1375 SourceLocation EndLoc) {
1376 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1377 StartLoc, LParenLoc, EndLoc);
1378 }
1379
Alexey Bataev56dafe82014-06-20 07:16:17 +00001380 /// \brief Build a new OpenMP 'schedule' clause.
1381 ///
1382 /// By default, performs semantic analysis to build the new OpenMP clause.
1383 /// Subclasses may override this routine to provide different behavior.
1384 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1385 Expr *ChunkSize,
1386 SourceLocation StartLoc,
1387 SourceLocation LParenLoc,
1388 SourceLocation KindLoc,
1389 SourceLocation CommaLoc,
1390 SourceLocation EndLoc) {
1391 return getSema().ActOnOpenMPScheduleClause(
1392 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1393 }
1394
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001395 /// \brief Build a new OpenMP 'private' clause.
1396 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001397 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001398 /// Subclasses may override this routine to provide different behavior.
1399 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1400 SourceLocation StartLoc,
1401 SourceLocation LParenLoc,
1402 SourceLocation EndLoc) {
1403 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1404 EndLoc);
1405 }
1406
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001407 /// \brief Build a new OpenMP 'firstprivate' clause.
1408 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001409 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001410 /// Subclasses may override this routine to provide different behavior.
1411 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1412 SourceLocation StartLoc,
1413 SourceLocation LParenLoc,
1414 SourceLocation EndLoc) {
1415 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1416 EndLoc);
1417 }
1418
Alexander Musman1bb328c2014-06-04 13:06:39 +00001419 /// \brief Build a new OpenMP 'lastprivate' clause.
1420 ///
1421 /// By default, performs semantic analysis to build the new OpenMP clause.
1422 /// Subclasses may override this routine to provide different behavior.
1423 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1424 SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1428 EndLoc);
1429 }
1430
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001431 /// \brief Build a new OpenMP 'shared' clause.
1432 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001433 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001434 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001435 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1436 SourceLocation StartLoc,
1437 SourceLocation LParenLoc,
1438 SourceLocation EndLoc) {
1439 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1440 EndLoc);
1441 }
1442
Alexey Bataevc5e02582014-06-16 07:08:35 +00001443 /// \brief Build a new OpenMP 'reduction' clause.
1444 ///
1445 /// By default, performs semantic analysis to build the new statement.
1446 /// Subclasses may override this routine to provide different behavior.
1447 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1448 SourceLocation StartLoc,
1449 SourceLocation LParenLoc,
1450 SourceLocation ColonLoc,
1451 SourceLocation EndLoc,
1452 CXXScopeSpec &ReductionIdScopeSpec,
1453 const DeclarationNameInfo &ReductionId) {
1454 return getSema().ActOnOpenMPReductionClause(
1455 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1456 ReductionId);
1457 }
1458
Alexander Musman8dba6642014-04-22 13:09:42 +00001459 /// \brief Build a new OpenMP 'linear' clause.
1460 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001461 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001462 /// Subclasses may override this routine to provide different behavior.
1463 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1464 SourceLocation StartLoc,
1465 SourceLocation LParenLoc,
1466 SourceLocation ColonLoc,
1467 SourceLocation EndLoc) {
1468 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1469 ColonLoc, EndLoc);
1470 }
1471
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001472 /// \brief Build a new OpenMP 'aligned' clause.
1473 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001474 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001475 /// Subclasses may override this routine to provide different behavior.
1476 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1477 SourceLocation StartLoc,
1478 SourceLocation LParenLoc,
1479 SourceLocation ColonLoc,
1480 SourceLocation EndLoc) {
1481 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1482 LParenLoc, ColonLoc, EndLoc);
1483 }
1484
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001485 /// \brief Build a new OpenMP 'copyin' clause.
1486 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001487 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1490 SourceLocation StartLoc,
1491 SourceLocation LParenLoc,
1492 SourceLocation EndLoc) {
1493 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1494 EndLoc);
1495 }
1496
Alexey Bataevbae9a792014-06-27 10:37:06 +00001497 /// \brief Build a new OpenMP 'copyprivate' clause.
1498 ///
1499 /// By default, performs semantic analysis to build the new OpenMP clause.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1502 SourceLocation StartLoc,
1503 SourceLocation LParenLoc,
1504 SourceLocation EndLoc) {
1505 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1506 EndLoc);
1507 }
1508
James Dennett2a4d13c2012-06-15 07:13:21 +00001509 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001510 ///
1511 /// By default, performs semantic analysis to build the new statement.
1512 /// Subclasses may override this routine to provide different behavior.
1513 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1514 Expr *object) {
1515 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1516 }
1517
James Dennett2a4d13c2012-06-15 07:13:21 +00001518 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001519 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001520 /// By default, performs semantic analysis to build the new statement.
1521 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001522 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001523 Expr *Object, Stmt *Body) {
1524 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001525 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001526
James Dennett2a4d13c2012-06-15 07:13:21 +00001527 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001528 ///
1529 /// By default, performs semantic analysis to build the new statement.
1530 /// Subclasses may override this routine to provide different behavior.
1531 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1532 Stmt *Body) {
1533 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1534 }
John McCall53848232011-07-27 01:07:15 +00001535
Douglas Gregorf68a5082010-04-22 23:10:45 +00001536 /// \brief Build a new Objective-C fast enumeration statement.
1537 ///
1538 /// By default, performs semantic analysis to build the new statement.
1539 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001540 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001541 Stmt *Element,
1542 Expr *Collection,
1543 SourceLocation RParenLoc,
1544 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001545 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001546 Element,
John McCallb268a282010-08-23 23:25:46 +00001547 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001548 RParenLoc);
1549 if (ForEachStmt.isInvalid())
1550 return StmtError();
1551
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001552 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001554
Douglas Gregorebe10102009-08-20 07:17:43 +00001555 /// \brief Build a new C++ exception declaration.
1556 ///
1557 /// By default, performs semantic analysis to build the new decaration.
1558 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001559 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001560 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001561 SourceLocation StartLoc,
1562 SourceLocation IdLoc,
1563 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001564 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001565 StartLoc, IdLoc, Id);
1566 if (Var)
1567 getSema().CurContext->addDecl(Var);
1568 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001569 }
1570
1571 /// \brief Build a new C++ catch statement.
1572 ///
1573 /// By default, performs semantic analysis to build the new statement.
1574 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001575 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001576 VarDecl *ExceptionDecl,
1577 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001578 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1579 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001580 }
Mike Stump11289f42009-09-09 15:08:12 +00001581
Douglas Gregorebe10102009-08-20 07:17:43 +00001582 /// \brief Build a new C++ try statement.
1583 ///
1584 /// By default, performs semantic analysis to build the new statement.
1585 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001586 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1587 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001588 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001589 }
Mike Stump11289f42009-09-09 15:08:12 +00001590
Richard Smith02e85f32011-04-14 22:09:26 +00001591 /// \brief Build a new C++0x range-based for statement.
1592 ///
1593 /// By default, performs semantic analysis to build the new statement.
1594 /// Subclasses may override this routine to provide different behavior.
1595 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1596 SourceLocation ColonLoc,
1597 Stmt *Range, Stmt *BeginEnd,
1598 Expr *Cond, Expr *Inc,
1599 Stmt *LoopVar,
1600 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001601 // If we've just learned that the range is actually an Objective-C
1602 // collection, treat this as an Objective-C fast enumeration loop.
1603 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1604 if (RangeStmt->isSingleDecl()) {
1605 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001606 if (RangeVar->isInvalidDecl())
1607 return StmtError();
1608
Douglas Gregorf7106af2013-04-08 18:40:13 +00001609 Expr *RangeExpr = RangeVar->getInit();
1610 if (!RangeExpr->isTypeDependent() &&
1611 RangeExpr->getType()->isObjCObjectPointerType())
1612 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1613 RParenLoc);
1614 }
1615 }
1616 }
1617
Richard Smith02e85f32011-04-14 22:09:26 +00001618 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001619 Cond, Inc, LoopVar, RParenLoc,
1620 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001621 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001622
1623 /// \brief Build a new C++0x range-based for statement.
1624 ///
1625 /// By default, performs semantic analysis to build the new statement.
1626 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001627 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001628 bool IsIfExists,
1629 NestedNameSpecifierLoc QualifierLoc,
1630 DeclarationNameInfo NameInfo,
1631 Stmt *Nested) {
1632 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1633 QualifierLoc, NameInfo, Nested);
1634 }
1635
Richard Smith02e85f32011-04-14 22:09:26 +00001636 /// \brief Attach body to a C++0x range-based for statement.
1637 ///
1638 /// By default, performs semantic analysis to finish the new statement.
1639 /// Subclasses may override this routine to provide different behavior.
1640 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1641 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001643
David Majnemerfad8f482013-10-15 09:33:02 +00001644 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1645 Stmt *TryBlock, Stmt *Handler) {
1646 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001647 }
1648
David Majnemerfad8f482013-10-15 09:33:02 +00001649 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001650 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001651 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001652 }
1653
David Majnemerfad8f482013-10-15 09:33:02 +00001654 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1655 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001656 }
1657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// \brief Build a new expression that references a declaration.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001663 LookupResult &R,
1664 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001665 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1666 }
1667
1668
1669 /// \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.
Douglas Gregorea972d32011-02-28 21:54:11 +00001673 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001674 ValueDecl *VD,
1675 const DeclarationNameInfo &NameInfo,
1676 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001677 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001678 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001679
1680 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001681
1682 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 }
Mike Stump11289f42009-09-09 15:08:12 +00001684
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001686 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001689 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001691 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 }
1693
Douglas Gregorad8a3362009-09-04 17:36:40 +00001694 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001695 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001698 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001699 SourceLocation OperatorLoc,
1700 bool isArrow,
1701 CXXScopeSpec &SS,
1702 TypeSourceInfo *ScopeType,
1703 SourceLocation CCLoc,
1704 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001705 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001708 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001712 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001713 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001714 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 }
Mike Stump11289f42009-09-09 15:08:12 +00001716
Douglas Gregor882211c2010-04-28 22:16:22 +00001717 /// \brief Build a new builtin offsetof expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001721 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001722 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001723 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001724 unsigned NumComponents,
1725 SourceLocation RParenLoc) {
1726 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1727 NumComponents, RParenLoc);
1728 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001729
1730 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001731 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001732 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001735 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1736 SourceLocation OpLoc,
1737 UnaryExprOrTypeTrait ExprKind,
1738 SourceRange R) {
1739 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 }
1741
Peter Collingbournee190dee2011-03-11 19:24:49 +00001742 /// \brief Build a new sizeof, alignof or vec step expression with an
1743 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001744 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001747 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1748 UnaryExprOrTypeTrait ExprKind,
1749 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001750 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001751 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001754
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001755 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 }
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001759 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001762 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001764 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001766 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001767 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 RBracketLoc);
1769 }
1770
1771 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001772 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001777 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001778 Expr *ExecConfig = nullptr) {
1779 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001780 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 }
1782
1783 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001784 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001787 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001788 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001789 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001790 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001791 const DeclarationNameInfo &MemberNameInfo,
1792 ValueDecl *Member,
1793 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001794 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001795 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001796 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1797 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001798 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001799 // We have a reference to an unnamed field. This is always the
1800 // base of an anonymous struct/union member access, i.e. the
1801 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001802 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001803 assert(Member->getType()->isRecordType() &&
1804 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001805
Richard Smithcab9a7d2011-10-26 19:06:56 +00001806 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001807 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001808 QualifierLoc.getNestedNameSpecifier(),
1809 FoundDecl, Member);
1810 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001811 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001812 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001813 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001814 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001815 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001816 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001817 cast<FieldDecl>(Member)->getType(),
1818 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001819 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001820 }
Mike Stump11289f42009-09-09 15:08:12 +00001821
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001822 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001823 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001824
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001825 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001826 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001827
John McCall16df1e52010-03-30 21:47:33 +00001828 // FIXME: this involves duplicating earlier analysis in a lot of
1829 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001830 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001831 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001832 R.resolveKind();
1833
John McCallb268a282010-08-23 23:25:46 +00001834 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001835 SS, TemplateKWLoc,
1836 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001837 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 }
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001841 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001844 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001845 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001846 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001847 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 }
1849
1850 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001851 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001854 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001855 SourceLocation QuestionLoc,
1856 Expr *LHS,
1857 SourceLocation ColonLoc,
1858 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001859 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1860 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 }
1862
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001864 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001868 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001870 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001871 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001872 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 }
Mike Stump11289f42009-09-09 15:08:12 +00001874
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001876 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001879 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001880 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001882 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001883 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001884 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 }
Mike Stump11289f42009-09-09 15:08:12 +00001886
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001888 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001891 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 SourceLocation OpLoc,
1893 SourceLocation AccessorLoc,
1894 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001895
John McCall10eae182009-11-30 22:42:35 +00001896 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001897 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001898 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001899 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001900 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001901 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001902 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001903 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001907 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001911 MultiExprArg Inits,
1912 SourceLocation RBraceLoc,
1913 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001914 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001915 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001916 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001917 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001918
Douglas Gregord3d93062009-11-09 17:16:50 +00001919 // Patch in the result type we were given, which may have been computed
1920 // when the initial InitListExpr was built.
1921 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1922 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001923 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 }
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001927 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 MultiExprArg ArrayExprs,
1932 SourceLocation EqualOrColonLoc,
1933 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001934 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001935 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001937 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001940
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001941 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 }
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001945 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// By default, builds the implicit value initialization without performing
1947 /// any semantic analysis. Subclasses may override this routine to provide
1948 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001949 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001950 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001954 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001958 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001959 SourceLocation RParenLoc) {
1960 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001961 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001962 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 }
1964
1965 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001966 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001969 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001970 MultiExprArg SubExprs,
1971 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001972 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 }
Mike Stump11289f42009-09-09 15:08:12 +00001974
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001976 ///
1977 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// rather than attempting to map the label statement itself.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001981 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001982 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 }
Mike Stump11289f42009-09-09 15:08:12 +00001984
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001986 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 /// By default, performs semantic analysis to build the new expression.
1988 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001989 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001990 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001992 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// \brief Build a new __builtin_choose_expr expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002000 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 SourceLocation RParenLoc) {
2002 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002003 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 RParenLoc);
2005 }
Mike Stump11289f42009-09-09 15:08:12 +00002006
Peter Collingbourne91147592011-04-15 00:35:48 +00002007 /// \brief Build a new generic selection expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
2011 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2012 SourceLocation DefaultLoc,
2013 SourceLocation RParenLoc,
2014 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002015 ArrayRef<TypeSourceInfo *> Types,
2016 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002017 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002018 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002019 }
2020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// \brief Build a new overloaded operator call expression.
2022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// The semantic analysis provides the behavior of template instantiation,
2025 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002026 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 /// argument-dependent lookup, etc. Subclasses may override this routine to
2028 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002029 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002031 Expr *Callee,
2032 Expr *First,
2033 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002034
2035 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// reinterpret_cast.
2037 ///
2038 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002039 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 Stmt::StmtClass Class,
2043 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002044 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 SourceLocation RAngleLoc,
2046 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002047 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 SourceLocation RParenLoc) {
2049 switch (Class) {
2050 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002051 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002052 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002053 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002054
2055 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002056 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002057 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002058 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002059
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002061 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002062 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002063 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002065
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002067 return getDerived().RebuildCXXConstCastExpr(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 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002072 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 }
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 /// \brief Build a new C++ static_cast expression.
2077 ///
2078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002080 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002082 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 SourceLocation RAngleLoc,
2084 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002085 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002087 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002088 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002089 SourceRange(LAngleLoc, RAngleLoc),
2090 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 }
2092
2093 /// \brief Build a new C++ dynamic_cast expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002097 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002099 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 SourceLocation RAngleLoc,
2101 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002102 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002104 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002105 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002106 SourceRange(LAngleLoc, RAngleLoc),
2107 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 }
2109
2110 /// \brief Build a new C++ reinterpret_cast expression.
2111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002114 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002116 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 SourceLocation RAngleLoc,
2118 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002119 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002121 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002122 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002123 SourceRange(LAngleLoc, RAngleLoc),
2124 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
2126
2127 /// \brief Build a new C++ const_cast expression.
2128 ///
2129 /// By default, performs semantic analysis to build the new expression.
2130 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002131 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002133 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 SourceLocation RAngleLoc,
2135 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002136 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002138 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002139 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002140 SourceRange(LAngleLoc, RAngleLoc),
2141 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 }
Mike Stump11289f42009-09-09 15:08:12 +00002143
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 /// \brief Build a new C++ functional-style cast expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002148 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2149 SourceLocation LParenLoc,
2150 Expr *Sub,
2151 SourceLocation RParenLoc) {
2152 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002153 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 RParenLoc);
2155 }
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 /// \brief Build a new C++ typeid(type) expression.
2158 ///
2159 /// By default, performs semantic analysis to build the new expression.
2160 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002161 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002162 SourceLocation TypeidLoc,
2163 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002165 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002166 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Francois Pichet9f4f2072010-09-08 12:20:18 +00002169
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// \brief Build a new C++ typeid(expr) expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002174 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002175 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002176 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002178 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002179 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002180 }
2181
Francois Pichet9f4f2072010-09-08 12:20:18 +00002182 /// \brief Build a new C++ __uuidof(type) expression.
2183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
2186 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2187 SourceLocation TypeidLoc,
2188 TypeSourceInfo *Operand,
2189 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002190 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002191 RParenLoc);
2192 }
2193
2194 /// \brief Build a new C++ __uuidof(expr) expression.
2195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
2198 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2199 SourceLocation TypeidLoc,
2200 Expr *Operand,
2201 SourceLocation RParenLoc) {
2202 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2203 RParenLoc);
2204 }
2205
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 /// \brief Build a new C++ "this" expression.
2207 ///
2208 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002209 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002211 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002212 QualType ThisType,
2213 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002214 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002215 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 }
2217
2218 /// \brief Build a new C++ throw expression.
2219 ///
2220 /// By default, performs semantic analysis to build the new expression.
2221 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002222 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2223 bool IsThrownVariableInScope) {
2224 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 }
2226
2227 /// \brief Build a new C++ default-argument expression.
2228 ///
2229 /// By default, builds a new default-argument expression, which does not
2230 /// require any semantic analysis. Subclasses may override this routine to
2231 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002232 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002233 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002234 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 }
2236
Richard Smith852c9db2013-04-20 22:23:05 +00002237 /// \brief Build a new C++11 default-initialization expression.
2238 ///
2239 /// By default, builds a new default field initialization expression, which
2240 /// does not require any semantic analysis. Subclasses may override this
2241 /// routine to provide different behavior.
2242 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2243 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002244 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002245 }
2246
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 /// \brief Build a new C++ zero-initialization expression.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002251 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2252 SourceLocation LParenLoc,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002255 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 }
Mike Stump11289f42009-09-09 15:08:12 +00002257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ "new" expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002262 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002263 bool UseGlobal,
2264 SourceLocation PlacementLParen,
2265 MultiExprArg PlacementArgs,
2266 SourceLocation PlacementRParen,
2267 SourceRange TypeIdParens,
2268 QualType AllocatedType,
2269 TypeSourceInfo *AllocatedTypeInfo,
2270 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002271 SourceRange DirectInitRange,
2272 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002273 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002275 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002277 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002278 AllocatedType,
2279 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002280 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002281 DirectInitRange,
2282 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 }
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 /// \brief Build a new C++ "delete" expression.
2286 ///
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002289 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 bool IsGlobalDelete,
2291 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002292 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002294 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 }
Mike Stump11289f42009-09-09 15:08:12 +00002296
Douglas Gregor29c42f22012-02-24 07:38:34 +00002297 /// \brief Build a new type trait expression.
2298 ///
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
2301 ExprResult RebuildTypeTrait(TypeTrait Trait,
2302 SourceLocation StartLoc,
2303 ArrayRef<TypeSourceInfo *> Args,
2304 SourceLocation RParenLoc) {
2305 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002307
John Wiegley6242b6a2011-04-28 00:16:57 +00002308 /// \brief Build a new array 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2313 SourceLocation StartLoc,
2314 TypeSourceInfo *TSInfo,
2315 Expr *DimExpr,
2316 SourceLocation RParenLoc) {
2317 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2318 }
2319
John Wiegleyf9f65842011-04-25 06:54:41 +00002320 /// \brief Build a new expression trait expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
2324 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2325 SourceLocation StartLoc,
2326 Expr *Queried,
2327 SourceLocation RParenLoc) {
2328 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2329 }
2330
Mike Stump11289f42009-09-09 15:08:12 +00002331 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 /// expression.
2333 ///
2334 /// By default, performs semantic analysis to build the new expression.
2335 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002336 ExprResult RebuildDependentScopeDeclRefExpr(
2337 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002338 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002339 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002340 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002341 bool IsAddressOfOperand,
2342 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002344 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002345
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002346 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002347 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2348 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002349
Reid Kleckner32506ed2014-06-12 23:03:48 +00002350 return getSema().BuildQualifiedDeclarationNameExpr(
2351 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 }
2353
2354 /// \brief Build a new template-id expression.
2355 ///
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002358 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002359 SourceLocation TemplateKWLoc,
2360 LookupResult &R,
2361 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002362 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002363 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2364 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 }
2366
2367 /// \brief Build a new object-construction expression.
2368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002371 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002372 SourceLocation Loc,
2373 CXXConstructorDecl *Constructor,
2374 bool IsElidable,
2375 MultiExprArg Args,
2376 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002377 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002378 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002379 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002380 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002381 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002382 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002383 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002384 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002385 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002386
Douglas Gregordb121ba2009-12-14 16:27:04 +00002387 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002388 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002389 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002390 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002391 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002392 RequiresZeroInit, ConstructKind,
2393 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 }
2395
2396 /// \brief Build a new object-construction expression.
2397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002400 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2401 SourceLocation LParenLoc,
2402 MultiExprArg Args,
2403 SourceLocation RParenLoc) {
2404 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002406 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 RParenLoc);
2408 }
2409
2410 /// \brief Build a new object-construction expression.
2411 ///
2412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002414 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2415 SourceLocation LParenLoc,
2416 MultiExprArg Args,
2417 SourceLocation RParenLoc) {
2418 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002420 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 RParenLoc);
2422 }
Mike Stump11289f42009-09-09 15:08:12 +00002423
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 /// \brief Build a new member reference expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002429 QualType BaseType,
2430 bool IsArrow,
2431 SourceLocation OperatorLoc,
2432 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002433 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002434 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002435 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002436 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002438 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002439
John McCallb268a282010-08-23 23:25:46 +00002440 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002441 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002442 SS, TemplateKWLoc,
2443 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002444 MemberNameInfo,
2445 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 }
2447
John McCall10eae182009-11-30 22:42:35 +00002448 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002452 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2453 SourceLocation OperatorLoc,
2454 bool IsArrow,
2455 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002456 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002457 NamedDecl *FirstQualifierInScope,
2458 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002459 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002460 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002461 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002462
John McCallb268a282010-08-23 23:25:46 +00002463 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002464 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002465 SS, TemplateKWLoc,
2466 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002467 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002468 }
Mike Stump11289f42009-09-09 15:08:12 +00002469
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002470 /// \brief Build a new noexcept expression.
2471 ///
2472 /// By default, performs semantic analysis to build the new expression.
2473 /// Subclasses may override this routine to provide different behavior.
2474 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2475 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2476 }
2477
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002478 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002479 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2480 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002481 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002482 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002483 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002484 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2485 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002486 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002487
2488 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2489 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002490 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002491 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002492
Patrick Beard0caa3942012-04-19 00:25:12 +00002493 /// \brief Build a new Objective-C boxed expression.
2494 ///
2495 /// By default, performs semantic analysis to build the new expression.
2496 /// Subclasses may override this routine to provide different behavior.
2497 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2498 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002500
Ted Kremeneke65b0862012-03-06 20:05:56 +00002501 /// \brief Build a new Objective-C array literal.
2502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
2505 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2506 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002507 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002508 MultiExprArg(Elements, NumElements));
2509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002510
2511 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002512 Expr *Base, Expr *Key,
2513 ObjCMethodDecl *getterMethod,
2514 ObjCMethodDecl *setterMethod) {
2515 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2516 getterMethod, setterMethod);
2517 }
2518
2519 /// \brief Build a new Objective-C dictionary literal.
2520 ///
2521 /// By default, performs semantic analysis to build the new expression.
2522 /// Subclasses may override this routine to provide different behavior.
2523 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2524 ObjCDictionaryElement *Elements,
2525 unsigned NumElements) {
2526 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002528
James Dennett2a4d13c2012-06-15 07:13:21 +00002529 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 ///
2531 /// By default, performs semantic analysis to build the new expression.
2532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002533 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002534 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002536 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002537 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002538
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002539 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002540 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002541 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002542 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002543 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002544 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002545 MultiExprArg Args,
2546 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002547 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2548 ReceiverTypeInfo->getType(),
2549 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002550 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002551 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002552 }
2553
2554 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002555 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002556 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002557 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002558 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002559 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002560 MultiExprArg Args,
2561 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002562 return SemaRef.BuildInstanceMessage(Receiver,
2563 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002564 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002565 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002566 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002567 }
2568
Douglas Gregord51d90d2010-04-26 20:11:03 +00002569 /// \brief Build a new Objective-C ivar reference expression.
2570 ///
2571 /// By default, performs semantic analysis to build the new expression.
2572 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002573 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002574 SourceLocation IvarLoc,
2575 bool IsArrow, bool IsFreeIvar) {
2576 // FIXME: We lose track of the IsFreeIvar bit.
2577 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002578 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2579 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002580 /*FIXME:*/IvarLoc, IsArrow,
2581 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002582 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002583 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002584 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002585 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002586
2587 /// \brief Build a new Objective-C property reference expression.
2588 ///
2589 /// By default, performs semantic analysis to build the new expression.
2590 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002591 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002592 ObjCPropertyDecl *Property,
2593 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002594 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002595 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2596 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2597 /*FIXME:*/PropertyLoc,
2598 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002599 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002600 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002601 NameInfo,
2602 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002604
John McCallb7bd14f2010-12-02 01:19:52 +00002605 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002606 ///
2607 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002608 /// Subclasses may override this routine to provide different behavior.
2609 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2610 ObjCMethodDecl *Getter,
2611 ObjCMethodDecl *Setter,
2612 SourceLocation PropertyLoc) {
2613 // Since these expressions can only be value-dependent, we do not
2614 // need to perform semantic analysis again.
2615 return Owned(
2616 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2617 VK_LValue, OK_ObjCProperty,
2618 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002619 }
2620
Douglas Gregord51d90d2010-04-26 20:11:03 +00002621 /// \brief Build a new Objective-C "isa" expression.
2622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002625 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002626 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002627 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002628 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2629 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002630 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002631 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002632 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002633 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002634 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002636
Douglas Gregora16548e2009-08-11 05:31:07 +00002637 /// \brief Build a new shuffle vector expression.
2638 ///
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002641 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002642 MultiExprArg SubExprs,
2643 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002644 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002645 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002646 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2647 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2648 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002649 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002650
Douglas Gregora16548e2009-08-11 05:31:07 +00002651 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002652 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002653 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2654 SemaRef.Context.BuiltinFnTy,
2655 VK_RValue, BuiltinLoc);
2656 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2657 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002658 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002659
2660 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002661 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002662 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002663 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002664
Douglas Gregora16548e2009-08-11 05:31:07 +00002665 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002666 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002667 }
John McCall31f82722010-11-12 08:19:04 +00002668
Hal Finkelc4d7c822013-09-18 03:29:45 +00002669 /// \brief Build a new convert vector expression.
2670 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2671 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2672 SourceLocation RParenLoc) {
2673 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2674 BuiltinLoc, RParenLoc);
2675 }
2676
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002677 /// \brief Build a new template argument pack expansion.
2678 ///
2679 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002680 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002681 /// different behavior.
2682 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002683 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002684 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002685 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002686 case TemplateArgument::Expression: {
2687 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002688 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2689 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002690 if (Result.isInvalid())
2691 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002692
Douglas Gregor98318c22011-01-03 21:37:45 +00002693 return TemplateArgumentLoc(Result.get(), Result.get());
2694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002695
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002696 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002697 return TemplateArgumentLoc(TemplateArgument(
2698 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002699 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002700 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002701 Pattern.getTemplateNameLoc(),
2702 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002703
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002704 case TemplateArgument::Null:
2705 case TemplateArgument::Integral:
2706 case TemplateArgument::Declaration:
2707 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002708 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002709 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002710 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002711
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002712 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002713 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002714 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002715 EllipsisLoc,
2716 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002717 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2718 Expansion);
2719 break;
2720 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002721
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002722 return TemplateArgumentLoc();
2723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002724
Douglas Gregor968f23a2011-01-03 19:31:53 +00002725 /// \brief Build a new expression pack expansion.
2726 ///
2727 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002728 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002729 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002730 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002731 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002732 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002733 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002734
2735 /// \brief Build a new atomic operation expression.
2736 ///
2737 /// By default, performs semantic analysis to build the new expression.
2738 /// Subclasses may override this routine to provide different behavior.
2739 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2740 MultiExprArg SubExprs,
2741 QualType RetTy,
2742 AtomicExpr::AtomicOp Op,
2743 SourceLocation RParenLoc) {
2744 // Just create the expression; there is not any interesting semantic
2745 // analysis here because we can't actually build an AtomicExpr until
2746 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002747 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002748 RParenLoc);
2749 }
2750
John McCall31f82722010-11-12 08:19:04 +00002751private:
Douglas Gregor14454802011-02-25 02:25:35 +00002752 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2753 QualType ObjectType,
2754 NamedDecl *FirstQualifierInScope,
2755 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002756
2757 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2758 QualType ObjectType,
2759 NamedDecl *FirstQualifierInScope,
2760 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002761
2762 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2763 NamedDecl *FirstQualifierInScope,
2764 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002765};
Douglas Gregora16548e2009-08-11 05:31:07 +00002766
Douglas Gregorebe10102009-08-20 07:17:43 +00002767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002768StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002769 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002770 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002771
Douglas Gregorebe10102009-08-20 07:17:43 +00002772 switch (S->getStmtClass()) {
2773 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002774
Douglas Gregorebe10102009-08-20 07:17:43 +00002775 // Transform individual statement nodes
2776#define STMT(Node, Parent) \
2777 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002778#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002779#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002780#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002781
Douglas Gregorebe10102009-08-20 07:17:43 +00002782 // Transform expressions by calling TransformExpr.
2783#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002784#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002785#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002786#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002787 {
John McCalldadc5752010-08-24 06:29:42 +00002788 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002789 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002790 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002791
Richard Smith945f8d32013-01-14 22:39:08 +00002792 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002793 }
Mike Stump11289f42009-09-09 15:08:12 +00002794 }
2795
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002796 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002797}
Mike Stump11289f42009-09-09 15:08:12 +00002798
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002799template<typename Derived>
2800OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2801 if (!S)
2802 return S;
2803
2804 switch (S->getClauseKind()) {
2805 default: break;
2806 // Transform individual clause nodes
2807#define OPENMP_CLAUSE(Name, Class) \
2808 case OMPC_ ## Name : \
2809 return getDerived().Transform ## Class(cast<Class>(S));
2810#include "clang/Basic/OpenMPKinds.def"
2811 }
2812
2813 return S;
2814}
2815
Mike Stump11289f42009-09-09 15:08:12 +00002816
Douglas Gregore922c772009-08-04 22:27:00 +00002817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002818ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002819 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002820 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002821
2822 switch (E->getStmtClass()) {
2823 case Stmt::NoStmtClass: break;
2824#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002825#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002826#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002827 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002828#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002829 }
2830
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002831 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002832}
2833
2834template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002835ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2836 bool CXXDirectInit) {
2837 // Initializers are instantiated like expressions, except that various outer
2838 // layers are stripped.
2839 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002840 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002841
2842 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2843 Init = ExprTemp->getSubExpr();
2844
Richard Smithe6ca4752013-05-30 22:40:16 +00002845 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2846 Init = MTE->GetTemporaryExpr();
2847
Richard Smithd59b8322012-12-19 01:39:02 +00002848 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2849 Init = Binder->getSubExpr();
2850
2851 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2852 Init = ICE->getSubExprAsWritten();
2853
Richard Smithcc1b96d2013-06-12 22:31:48 +00002854 if (CXXStdInitializerListExpr *ILE =
2855 dyn_cast<CXXStdInitializerListExpr>(Init))
2856 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2857
Richard Smith38a549b2012-12-21 08:13:35 +00002858 // If this is not a direct-initializer, we only need to reconstruct
2859 // InitListExprs. Other forms of copy-initialization will be a no-op if
2860 // the initializer is already the right type.
2861 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2862 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2863 return getDerived().TransformExpr(Init);
2864
2865 // Revert value-initialization back to empty parens.
2866 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2867 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002868 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002869 Parens.getEnd());
2870 }
2871
2872 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2873 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002874 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002875 SourceLocation());
2876
2877 // Revert initialization by constructor back to a parenthesized or braced list
2878 // of expressions. Any other form of initializer can just be reused directly.
2879 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002880 return getDerived().TransformExpr(Init);
2881
Richard Smithf8adcdc2014-07-17 05:12:35 +00002882 // If the initialization implicitly converted an initializer list to a
2883 // std::initializer_list object, unwrap the std::initializer_list too.
2884 if (Construct && Construct->isStdInitListInitialization())
2885 return TransformInitializer(Construct->getArg(0), CXXDirectInit);
2886
Richard Smithd59b8322012-12-19 01:39:02 +00002887 SmallVector<Expr*, 8> NewArgs;
2888 bool ArgChanged = false;
2889 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2890 /*IsCall*/true, NewArgs, &ArgChanged))
2891 return ExprError();
2892
2893 // If this was list initialization, revert to list form.
2894 if (Construct->isListInitialization())
2895 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2896 Construct->getLocEnd(),
2897 Construct->getType());
2898
Richard Smithd59b8322012-12-19 01:39:02 +00002899 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002900 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002901 if (Parens.isInvalid()) {
2902 // This was a variable declaration's initialization for which no initializer
2903 // was specified.
2904 assert(NewArgs.empty() &&
2905 "no parens or braces but have direct init with arguments?");
2906 return ExprEmpty();
2907 }
Richard Smithd59b8322012-12-19 01:39:02 +00002908 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2909 Parens.getEnd());
2910}
2911
2912template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002913bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2914 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002915 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002916 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002917 bool *ArgChanged) {
2918 for (unsigned I = 0; I != NumInputs; ++I) {
2919 // If requested, drop call arguments that need to be dropped.
2920 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2921 if (ArgChanged)
2922 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002923
Douglas Gregora3efea12011-01-03 19:04:46 +00002924 break;
2925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
Douglas Gregor968f23a2011-01-03 19:31:53 +00002927 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2928 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002929
Chris Lattner01cf8db2011-07-20 06:58:45 +00002930 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002931 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2932 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002933
Douglas Gregor968f23a2011-01-03 19:31:53 +00002934 // Determine whether the set of unexpanded parameter packs can and should
2935 // be expanded.
2936 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002937 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002938 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2939 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002940 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2941 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002942 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002943 Expand, RetainExpansion,
2944 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002945 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor968f23a2011-01-03 19:31:53 +00002947 if (!Expand) {
2948 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002949 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002950 // expansion.
2951 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2952 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2953 if (OutPattern.isInvalid())
2954 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002955
2956 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002957 Expansion->getEllipsisLoc(),
2958 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002959 if (Out.isInvalid())
2960 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002961
Douglas Gregor968f23a2011-01-03 19:31:53 +00002962 if (ArgChanged)
2963 *ArgChanged = true;
2964 Outputs.push_back(Out.get());
2965 continue;
2966 }
John McCall542e7c62011-07-06 07:30:07 +00002967
2968 // Record right away that the argument was changed. This needs
2969 // to happen even if the array expands to nothing.
2970 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor968f23a2011-01-03 19:31:53 +00002972 // The transform has determined that we should perform an elementwise
2973 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002974 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002975 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2976 ExprResult Out = getDerived().TransformExpr(Pattern);
2977 if (Out.isInvalid())
2978 return true;
2979
Richard Smith9467be42014-06-06 17:33:35 +00002980 // FIXME: Can this happen? We should not try to expand the pack
2981 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002982 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002983 Out = getDerived().RebuildPackExpansion(
2984 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002985 if (Out.isInvalid())
2986 return true;
2987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002988
Douglas Gregor968f23a2011-01-03 19:31:53 +00002989 Outputs.push_back(Out.get());
2990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002991
Richard Smith9467be42014-06-06 17:33:35 +00002992 // If we're supposed to retain a pack expansion, do so by temporarily
2993 // forgetting the partially-substituted parameter pack.
2994 if (RetainExpansion) {
2995 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2996
2997 ExprResult Out = getDerived().TransformExpr(Pattern);
2998 if (Out.isInvalid())
2999 return true;
3000
3001 Out = getDerived().RebuildPackExpansion(
3002 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3003 if (Out.isInvalid())
3004 return true;
3005
3006 Outputs.push_back(Out.get());
3007 }
3008
Douglas Gregor968f23a2011-01-03 19:31:53 +00003009 continue;
3010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003011
Richard Smithd59b8322012-12-19 01:39:02 +00003012 ExprResult Result =
3013 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3014 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003015 if (Result.isInvalid())
3016 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003017
Douglas Gregora3efea12011-01-03 19:04:46 +00003018 if (Result.get() != Inputs[I] && ArgChanged)
3019 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003020
3021 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003022 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregora3efea12011-01-03 19:04:46 +00003024 return false;
3025}
3026
3027template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003028NestedNameSpecifierLoc
3029TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3030 NestedNameSpecifierLoc NNS,
3031 QualType ObjectType,
3032 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003033 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003034 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003035 Qualifier = Qualifier.getPrefix())
3036 Qualifiers.push_back(Qualifier);
3037
3038 CXXScopeSpec SS;
3039 while (!Qualifiers.empty()) {
3040 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3041 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
Douglas Gregor14454802011-02-25 02:25:35 +00003043 switch (QNNS->getKind()) {
3044 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003045 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003046 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003047 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003048 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003049 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003050 FirstQualifierInScope, false))
3051 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003052
Douglas Gregor14454802011-02-25 02:25:35 +00003053 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003054
Douglas Gregor14454802011-02-25 02:25:35 +00003055 case NestedNameSpecifier::Namespace: {
3056 NamespaceDecl *NS
3057 = cast_or_null<NamespaceDecl>(
3058 getDerived().TransformDecl(
3059 Q.getLocalBeginLoc(),
3060 QNNS->getAsNamespace()));
3061 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3062 break;
3063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
Douglas Gregor14454802011-02-25 02:25:35 +00003065 case NestedNameSpecifier::NamespaceAlias: {
3066 NamespaceAliasDecl *Alias
3067 = cast_or_null<NamespaceAliasDecl>(
3068 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3069 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003070 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003071 Q.getLocalEndLoc());
3072 break;
3073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003074
Douglas Gregor14454802011-02-25 02:25:35 +00003075 case NestedNameSpecifier::Global:
3076 // There is no meaningful transformation that one could perform on the
3077 // global scope.
3078 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3079 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003080
Douglas Gregor14454802011-02-25 02:25:35 +00003081 case NestedNameSpecifier::TypeSpecWithTemplate:
3082 case NestedNameSpecifier::TypeSpec: {
3083 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3084 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregor14454802011-02-25 02:25:35 +00003086 if (!TL)
3087 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003088
Douglas Gregor14454802011-02-25 02:25:35 +00003089 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003090 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003091 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003092 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003093 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003094 if (TL.getType()->isEnumeralType())
3095 SemaRef.Diag(TL.getBeginLoc(),
3096 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003097 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3098 Q.getLocalEndLoc());
3099 break;
3100 }
Richard Trieude756fb2011-05-07 01:36:37 +00003101 // If the nested-name-specifier is an invalid type def, don't emit an
3102 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003103 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3104 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003105 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003106 << TL.getType() << SS.getRange();
3107 }
Douglas Gregor14454802011-02-25 02:25:35 +00003108 return NestedNameSpecifierLoc();
3109 }
Douglas Gregore16af532011-02-28 18:50:33 +00003110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregore16af532011-02-28 18:50:33 +00003112 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003113 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003114 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Douglas Gregor14454802011-02-25 02:25:35 +00003117 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003118 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003119 !getDerived().AlwaysRebuild())
3120 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003121
3122 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003123 // nested-name-specifier, do so.
3124 if (SS.location_size() == NNS.getDataLength() &&
3125 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3126 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3127
3128 // Allocate new nested-name-specifier location information.
3129 return SS.getWithLocInContext(SemaRef.Context);
3130}
3131
3132template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003133DeclarationNameInfo
3134TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003135::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003136 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003137 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003138 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003139
3140 switch (Name.getNameKind()) {
3141 case DeclarationName::Identifier:
3142 case DeclarationName::ObjCZeroArgSelector:
3143 case DeclarationName::ObjCOneArgSelector:
3144 case DeclarationName::ObjCMultiArgSelector:
3145 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003146 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003147 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003148 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregorf816bd72009-09-03 22:13:48 +00003150 case DeclarationName::CXXConstructorName:
3151 case DeclarationName::CXXDestructorName:
3152 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003153 TypeSourceInfo *NewTInfo;
3154 CanQualType NewCanTy;
3155 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003156 NewTInfo = getDerived().TransformType(OldTInfo);
3157 if (!NewTInfo)
3158 return DeclarationNameInfo();
3159 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003160 }
3161 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003162 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003163 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003164 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003165 if (NewT.isNull())
3166 return DeclarationNameInfo();
3167 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3168 }
Mike Stump11289f42009-09-09 15:08:12 +00003169
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003170 DeclarationName NewName
3171 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3172 NewCanTy);
3173 DeclarationNameInfo NewNameInfo(NameInfo);
3174 NewNameInfo.setName(NewName);
3175 NewNameInfo.setNamedTypeInfo(NewTInfo);
3176 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003177 }
Mike Stump11289f42009-09-09 15:08:12 +00003178 }
3179
David Blaikie83d382b2011-09-23 05:06:16 +00003180 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003181}
3182
3183template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003184TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003185TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3186 TemplateName Name,
3187 SourceLocation NameLoc,
3188 QualType ObjectType,
3189 NamedDecl *FirstQualifierInScope) {
3190 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3191 TemplateDecl *Template = QTN->getTemplateDecl();
3192 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003193
Douglas Gregor9db53502011-03-02 18:07:45 +00003194 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003195 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003196 Template));
3197 if (!TransTemplate)
3198 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003199
Douglas Gregor9db53502011-03-02 18:07:45 +00003200 if (!getDerived().AlwaysRebuild() &&
3201 SS.getScopeRep() == QTN->getQualifier() &&
3202 TransTemplate == Template)
3203 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor9db53502011-03-02 18:07:45 +00003205 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3206 TransTemplate);
3207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003208
Douglas Gregor9db53502011-03-02 18:07:45 +00003209 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3210 if (SS.getScopeRep()) {
3211 // These apply to the scope specifier, not the template.
3212 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003213 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003214 }
3215
Douglas Gregor9db53502011-03-02 18:07:45 +00003216 if (!getDerived().AlwaysRebuild() &&
3217 SS.getScopeRep() == DTN->getQualifier() &&
3218 ObjectType.isNull())
3219 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003220
Douglas Gregor9db53502011-03-02 18:07:45 +00003221 if (DTN->isIdentifier()) {
3222 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003223 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003224 NameLoc,
3225 ObjectType,
3226 FirstQualifierInScope);
3227 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003228
Douglas Gregor9db53502011-03-02 18:07:45 +00003229 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3230 ObjectType);
3231 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Douglas Gregor9db53502011-03-02 18:07:45 +00003233 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3234 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003235 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003236 Template));
3237 if (!TransTemplate)
3238 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
Douglas Gregor9db53502011-03-02 18:07:45 +00003240 if (!getDerived().AlwaysRebuild() &&
3241 TransTemplate == Template)
3242 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003243
Douglas Gregor9db53502011-03-02 18:07:45 +00003244 return TemplateName(TransTemplate);
3245 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003246
Douglas Gregor9db53502011-03-02 18:07:45 +00003247 if (SubstTemplateTemplateParmPackStorage *SubstPack
3248 = Name.getAsSubstTemplateTemplateParmPack()) {
3249 TemplateTemplateParmDecl *TransParam
3250 = cast_or_null<TemplateTemplateParmDecl>(
3251 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3252 if (!TransParam)
3253 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003254
Douglas Gregor9db53502011-03-02 18:07:45 +00003255 if (!getDerived().AlwaysRebuild() &&
3256 TransParam == SubstPack->getParameterPack())
3257 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003258
3259 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003260 SubstPack->getArgumentPack());
3261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregor9db53502011-03-02 18:07:45 +00003263 // These should be getting filtered out before they reach the AST.
3264 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003265}
3266
3267template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003268void TreeTransform<Derived>::InventTemplateArgumentLoc(
3269 const TemplateArgument &Arg,
3270 TemplateArgumentLoc &Output) {
3271 SourceLocation Loc = getDerived().getBaseLocation();
3272 switch (Arg.getKind()) {
3273 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003274 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003275 break;
3276
3277 case TemplateArgument::Type:
3278 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003279 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
John McCall0ad16662009-10-29 08:12:44 +00003281 break;
3282
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003283 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003284 case TemplateArgument::TemplateExpansion: {
3285 NestedNameSpecifierLocBuilder Builder;
3286 TemplateName Template = Arg.getAsTemplate();
3287 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3288 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3289 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3290 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003291
Douglas Gregor9d802122011-03-02 17:09:35 +00003292 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003293 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003294 Builder.getWithLocInContext(SemaRef.Context),
3295 Loc);
3296 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003297 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003298 Builder.getWithLocInContext(SemaRef.Context),
3299 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003301 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003302 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003303
John McCall0ad16662009-10-29 08:12:44 +00003304 case TemplateArgument::Expression:
3305 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3306 break;
3307
3308 case TemplateArgument::Declaration:
3309 case TemplateArgument::Integral:
3310 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003311 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003312 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003313 break;
3314 }
3315}
3316
3317template<typename Derived>
3318bool TreeTransform<Derived>::TransformTemplateArgument(
3319 const TemplateArgumentLoc &Input,
3320 TemplateArgumentLoc &Output) {
3321 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003322 switch (Arg.getKind()) {
3323 case TemplateArgument::Null:
3324 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003325 case TemplateArgument::Pack:
3326 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003327 case TemplateArgument::NullPtr:
3328 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003329
Douglas Gregore922c772009-08-04 22:27:00 +00003330 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003331 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003332 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003333 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003334
3335 DI = getDerived().TransformType(DI);
3336 if (!DI) return true;
3337
3338 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3339 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003340 }
Mike Stump11289f42009-09-09 15:08:12 +00003341
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003342 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003343 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3344 if (QualifierLoc) {
3345 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3346 if (!QualifierLoc)
3347 return true;
3348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregordf846d12011-03-02 18:46:51 +00003350 CXXScopeSpec SS;
3351 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003352 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003353 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3354 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003355 if (Template.isNull())
3356 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor9d802122011-03-02 17:09:35 +00003358 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003359 Input.getTemplateNameLoc());
3360 return false;
3361 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003362
3363 case TemplateArgument::TemplateExpansion:
3364 llvm_unreachable("Caller should expand pack expansions");
3365
Douglas Gregore922c772009-08-04 22:27:00 +00003366 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003367 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003368 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003369 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003370
John McCall0ad16662009-10-29 08:12:44 +00003371 Expr *InputExpr = Input.getSourceExpression();
3372 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3373
Chris Lattnercdb591a2011-04-25 20:37:58 +00003374 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003375 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003376 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003377 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003378 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003379 }
Douglas Gregore922c772009-08-04 22:27:00 +00003380 }
Mike Stump11289f42009-09-09 15:08:12 +00003381
Douglas Gregore922c772009-08-04 22:27:00 +00003382 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003383 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003384}
3385
Douglas Gregorfe921a72010-12-20 23:36:19 +00003386/// \brief Iterator adaptor that invents template argument location information
3387/// for each of the template arguments in its underlying iterator.
3388template<typename Derived, typename InputIterator>
3389class TemplateArgumentLocInventIterator {
3390 TreeTransform<Derived> &Self;
3391 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregorfe921a72010-12-20 23:36:19 +00003393public:
3394 typedef TemplateArgumentLoc value_type;
3395 typedef TemplateArgumentLoc reference;
3396 typedef typename std::iterator_traits<InputIterator>::difference_type
3397 difference_type;
3398 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregorfe921a72010-12-20 23:36:19 +00003400 class pointer {
3401 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregorfe921a72010-12-20 23:36:19 +00003403 public:
3404 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregorfe921a72010-12-20 23:36:19 +00003406 const TemplateArgumentLoc *operator->() const { return &Arg; }
3407 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003408
Douglas Gregorfe921a72010-12-20 23:36:19 +00003409 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
Douglas Gregorfe921a72010-12-20 23:36:19 +00003411 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3412 InputIterator Iter)
3413 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregorfe921a72010-12-20 23:36:19 +00003415 TemplateArgumentLocInventIterator &operator++() {
3416 ++Iter;
3417 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003418 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregorfe921a72010-12-20 23:36:19 +00003420 TemplateArgumentLocInventIterator operator++(int) {
3421 TemplateArgumentLocInventIterator Old(*this);
3422 ++(*this);
3423 return Old;
3424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregorfe921a72010-12-20 23:36:19 +00003426 reference operator*() const {
3427 TemplateArgumentLoc Result;
3428 Self.InventTemplateArgumentLoc(*Iter, Result);
3429 return Result;
3430 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
Douglas Gregorfe921a72010-12-20 23:36:19 +00003432 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregorfe921a72010-12-20 23:36:19 +00003434 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3435 const TemplateArgumentLocInventIterator &Y) {
3436 return X.Iter == Y.Iter;
3437 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003438
Douglas Gregorfe921a72010-12-20 23:36:19 +00003439 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3440 const TemplateArgumentLocInventIterator &Y) {
3441 return X.Iter != Y.Iter;
3442 }
3443};
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregor42cafa82010-12-20 17:42:22 +00003445template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003446template<typename InputIterator>
3447bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3448 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003449 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003450 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003451 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003452 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003454 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3455 // Unpack argument packs, which we translate them into separate
3456 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003457 // FIXME: We could do much better if we could guarantee that the
3458 // TemplateArgumentLocInfo for the pack expansion would be usable for
3459 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003460 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003461 TemplateArgument::pack_iterator>
3462 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003463 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003464 In.getArgument().pack_begin()),
3465 PackLocIterator(*this,
3466 In.getArgument().pack_end()),
3467 Outputs))
3468 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003470 continue;
3471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003473 if (In.getArgument().isPackExpansion()) {
3474 // We have a pack expansion, for which we will be substituting into
3475 // the pattern.
3476 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003477 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003478 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003479 = getSema().getTemplateArgumentPackExpansionPattern(
3480 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003481
Chris Lattner01cf8db2011-07-20 06:58:45 +00003482 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003483 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3484 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003486 // Determine whether the set of unexpanded parameter packs can and should
3487 // be expanded.
3488 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003489 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003490 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003491 if (getDerived().TryExpandParameterPacks(Ellipsis,
3492 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003493 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003494 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003495 RetainExpansion,
3496 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003497 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003499 if (!Expand) {
3500 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003501 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003502 // expansion.
3503 TemplateArgumentLoc OutPattern;
3504 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3505 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3506 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003508 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3509 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003510 if (Out.getArgument().isNull())
3511 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003513 Outputs.addArgument(Out);
3514 continue;
3515 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003517 // The transform has determined that we should perform an elementwise
3518 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003519 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003520 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3521
3522 if (getDerived().TransformTemplateArgument(Pattern, Out))
3523 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003525 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003526 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3527 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003528 if (Out.getArgument().isNull())
3529 return true;
3530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003532 Outputs.addArgument(Out);
3533 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregor48d24112011-01-10 20:53:55 +00003535 // If we're supposed to retain a pack expansion, do so by temporarily
3536 // forgetting the partially-substituted parameter pack.
3537 if (RetainExpansion) {
3538 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregor48d24112011-01-10 20:53:55 +00003540 if (getDerived().TransformTemplateArgument(Pattern, Out))
3541 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003543 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3544 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003545 if (Out.getArgument().isNull())
3546 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003547
Douglas Gregor48d24112011-01-10 20:53:55 +00003548 Outputs.addArgument(Out);
3549 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003551 continue;
3552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
3554 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003555 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003556 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003557
Douglas Gregor42cafa82010-12-20 17:42:22 +00003558 Outputs.addArgument(Out);
3559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Douglas Gregor42cafa82010-12-20 17:42:22 +00003561 return false;
3562
3563}
3564
Douglas Gregord6ff3322009-08-04 16:50:30 +00003565//===----------------------------------------------------------------------===//
3566// Type transformation
3567//===----------------------------------------------------------------------===//
3568
3569template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003570QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003571 if (getDerived().AlreadyTransformed(T))
3572 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003573
John McCall550e0c22009-10-21 00:40:46 +00003574 // Temporary workaround. All of these transformations should
3575 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003576 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3577 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
John McCall31f82722010-11-12 08:19:04 +00003579 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003580
John McCall550e0c22009-10-21 00:40:46 +00003581 if (!NewDI)
3582 return QualType();
3583
3584 return NewDI->getType();
3585}
3586
3587template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003588TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003589 // Refine the base location to the type's location.
3590 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3591 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003592 if (getDerived().AlreadyTransformed(DI->getType()))
3593 return DI;
3594
3595 TypeLocBuilder TLB;
3596
3597 TypeLoc TL = DI->getTypeLoc();
3598 TLB.reserve(TL.getFullDataSize());
3599
John McCall31f82722010-11-12 08:19:04 +00003600 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003601 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003602 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003603
John McCallbcd03502009-12-07 02:54:59 +00003604 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003605}
3606
3607template<typename Derived>
3608QualType
John McCall31f82722010-11-12 08:19:04 +00003609TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003610 switch (T.getTypeLocClass()) {
3611#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003612#define TYPELOC(CLASS, PARENT) \
3613 case TypeLoc::CLASS: \
3614 return getDerived().Transform##CLASS##Type(TLB, \
3615 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003616#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003617 }
Mike Stump11289f42009-09-09 15:08:12 +00003618
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003619 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003620}
3621
3622/// FIXME: By default, this routine adds type qualifiers only to types
3623/// that can have qualifiers, and silently suppresses those qualifiers
3624/// that are not permitted (e.g., qualifiers on reference or function
3625/// types). This is the right thing for template instantiation, but
3626/// probably not for other clients.
3627template<typename Derived>
3628QualType
3629TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003630 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003631 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003632
John McCall31f82722010-11-12 08:19:04 +00003633 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003634 if (Result.isNull())
3635 return QualType();
3636
3637 // Silently suppress qualifiers if the result type can't be qualified.
3638 // FIXME: this is the right thing for template instantiation, but
3639 // probably not for other clients.
3640 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003641 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003642
John McCall31168b02011-06-15 23:02:42 +00003643 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003644 // resulting type.
3645 if (Quals.hasObjCLifetime()) {
3646 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3647 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003648 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003649 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003650 // A lifetime qualifier applied to a substituted template parameter
3651 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003652 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003654 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3655 QualType Replacement = SubstTypeParam->getReplacementType();
3656 Qualifiers Qs = Replacement.getQualifiers();
3657 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003658 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003659 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3660 Qs);
3661 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003662 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003663 Replacement);
3664 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003665 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3666 // 'auto' types behave the same way as template parameters.
3667 QualType Deduced = AutoTy->getDeducedType();
3668 Qualifiers Qs = Deduced.getQualifiers();
3669 Qs.removeObjCLifetime();
3670 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3671 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003672 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3673 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003674 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003675 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003676 // Otherwise, complain about the addition of a qualifier to an
3677 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003678 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003679 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003680 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003681
Douglas Gregore46db902011-06-17 22:11:49 +00003682 Quals.removeObjCLifetime();
3683 }
3684 }
3685 }
John McCallcb0f89a2010-06-05 06:41:15 +00003686 if (!Quals.empty()) {
3687 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003688 // BuildQualifiedType might not add qualifiers if they are invalid.
3689 if (Result.hasLocalQualifiers())
3690 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003691 // No location information to preserve.
3692 }
John McCall550e0c22009-10-21 00:40:46 +00003693
3694 return Result;
3695}
3696
Douglas Gregor14454802011-02-25 02:25:35 +00003697template<typename Derived>
3698TypeLoc
3699TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3700 QualType ObjectType,
3701 NamedDecl *UnqualLookup,
3702 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003703 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003704 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003706 TypeSourceInfo *TSI =
3707 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3708 if (TSI)
3709 return TSI->getTypeLoc();
3710 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003711}
3712
Douglas Gregor579c15f2011-03-02 18:32:08 +00003713template<typename Derived>
3714TypeSourceInfo *
3715TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3716 QualType ObjectType,
3717 NamedDecl *UnqualLookup,
3718 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003719 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003720 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003722 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3723 UnqualLookup, SS);
3724}
3725
3726template <typename Derived>
3727TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3728 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3729 CXXScopeSpec &SS) {
3730 QualType T = TL.getType();
3731 assert(!getDerived().AlreadyTransformed(T));
3732
Douglas Gregor579c15f2011-03-02 18:32:08 +00003733 TypeLocBuilder TLB;
3734 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003735
Douglas Gregor579c15f2011-03-02 18:32:08 +00003736 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003737 TemplateSpecializationTypeLoc SpecTL =
3738 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003739
Douglas Gregor579c15f2011-03-02 18:32:08 +00003740 TemplateName Template
3741 = getDerived().TransformTemplateName(SS,
3742 SpecTL.getTypePtr()->getTemplateName(),
3743 SpecTL.getTemplateNameLoc(),
3744 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003745 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003746 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003747
3748 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003749 Template);
3750 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003751 DependentTemplateSpecializationTypeLoc SpecTL =
3752 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003753
Douglas Gregor579c15f2011-03-02 18:32:08 +00003754 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003755 = getDerived().RebuildTemplateName(SS,
3756 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003757 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003758 ObjectType, UnqualLookup);
3759 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003760 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
3762 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003763 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003764 Template,
3765 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003766 } else {
3767 // Nothing special needs to be done for these.
3768 Result = getDerived().TransformType(TLB, TL);
3769 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003770
3771 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003772 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003773
Douglas Gregor579c15f2011-03-02 18:32:08 +00003774 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3775}
3776
John McCall550e0c22009-10-21 00:40:46 +00003777template <class TyLoc> static inline
3778QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3779 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3780 NewT.setNameLoc(T.getNameLoc());
3781 return T.getType();
3782}
3783
John McCall550e0c22009-10-21 00:40:46 +00003784template<typename Derived>
3785QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003786 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003787 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3788 NewT.setBuiltinLoc(T.getBuiltinLoc());
3789 if (T.needsExtraLocalData())
3790 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3791 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003792}
Mike Stump11289f42009-09-09 15:08:12 +00003793
Douglas Gregord6ff3322009-08-04 16:50:30 +00003794template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003795QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003796 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003797 // FIXME: recurse?
3798 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003799}
Mike Stump11289f42009-09-09 15:08:12 +00003800
Reid Kleckner0503a872013-12-05 01:23:43 +00003801template <typename Derived>
3802QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3803 AdjustedTypeLoc TL) {
3804 // Adjustments applied during transformation are handled elsewhere.
3805 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3806}
3807
Douglas Gregord6ff3322009-08-04 16:50:30 +00003808template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003809QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3810 DecayedTypeLoc TL) {
3811 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3812 if (OriginalType.isNull())
3813 return QualType();
3814
3815 QualType Result = TL.getType();
3816 if (getDerived().AlwaysRebuild() ||
3817 OriginalType != TL.getOriginalLoc().getType())
3818 Result = SemaRef.Context.getDecayedType(OriginalType);
3819 TLB.push<DecayedTypeLoc>(Result);
3820 // Nothing to set for DecayedTypeLoc.
3821 return Result;
3822}
3823
3824template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003825QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003826 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003827 QualType PointeeType
3828 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003829 if (PointeeType.isNull())
3830 return QualType();
3831
3832 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003833 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003834 // A dependent pointer type 'T *' has is being transformed such
3835 // that an Objective-C class type is being replaced for 'T'. The
3836 // resulting pointer type is an ObjCObjectPointerType, not a
3837 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003838 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
John McCall8b07ec22010-05-15 11:32:37 +00003840 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3841 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003842 return Result;
3843 }
John McCall31f82722010-11-12 08:19:04 +00003844
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003845 if (getDerived().AlwaysRebuild() ||
3846 PointeeType != TL.getPointeeLoc().getType()) {
3847 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3848 if (Result.isNull())
3849 return QualType();
3850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
John McCall31168b02011-06-15 23:02:42 +00003852 // Objective-C ARC can add lifetime qualifiers to the type that we're
3853 // pointing to.
3854 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003856 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3857 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003858 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003859}
Mike Stump11289f42009-09-09 15:08:12 +00003860
3861template<typename Derived>
3862QualType
John McCall550e0c22009-10-21 00:40:46 +00003863TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003864 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003865 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003866 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3867 if (PointeeType.isNull())
3868 return QualType();
3869
3870 QualType Result = TL.getType();
3871 if (getDerived().AlwaysRebuild() ||
3872 PointeeType != TL.getPointeeLoc().getType()) {
3873 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003874 TL.getSigilLoc());
3875 if (Result.isNull())
3876 return QualType();
3877 }
3878
Douglas Gregor049211a2010-04-22 16:50:51 +00003879 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003880 NewT.setSigilLoc(TL.getSigilLoc());
3881 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882}
3883
John McCall70dd5f62009-10-30 00:06:24 +00003884/// Transforms a reference type. Note that somewhat paradoxically we
3885/// don't care whether the type itself is an l-value type or an r-value
3886/// type; we only care if the type was *written* as an l-value type
3887/// or an r-value type.
3888template<typename Derived>
3889QualType
3890TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003891 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003892 const ReferenceType *T = TL.getTypePtr();
3893
3894 // Note that this works with the pointee-as-written.
3895 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3896 if (PointeeType.isNull())
3897 return QualType();
3898
3899 QualType Result = TL.getType();
3900 if (getDerived().AlwaysRebuild() ||
3901 PointeeType != T->getPointeeTypeAsWritten()) {
3902 Result = getDerived().RebuildReferenceType(PointeeType,
3903 T->isSpelledAsLValue(),
3904 TL.getSigilLoc());
3905 if (Result.isNull())
3906 return QualType();
3907 }
3908
John McCall31168b02011-06-15 23:02:42 +00003909 // Objective-C ARC can add lifetime qualifiers to the type that we're
3910 // referring to.
3911 TLB.TypeWasModifiedSafely(
3912 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3913
John McCall70dd5f62009-10-30 00:06:24 +00003914 // r-value references can be rebuilt as l-value references.
3915 ReferenceTypeLoc NewTL;
3916 if (isa<LValueReferenceType>(Result))
3917 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3918 else
3919 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3920 NewTL.setSigilLoc(TL.getSigilLoc());
3921
3922 return Result;
3923}
3924
Mike Stump11289f42009-09-09 15:08:12 +00003925template<typename Derived>
3926QualType
John McCall550e0c22009-10-21 00:40:46 +00003927TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003928 LValueReferenceTypeLoc TL) {
3929 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003930}
3931
Mike Stump11289f42009-09-09 15:08:12 +00003932template<typename Derived>
3933QualType
John McCall550e0c22009-10-21 00:40:46 +00003934TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003935 RValueReferenceTypeLoc TL) {
3936 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937}
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregord6ff3322009-08-04 16:50:30 +00003939template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003940QualType
John McCall550e0c22009-10-21 00:40:46 +00003941TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003942 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003943 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003944 if (PointeeType.isNull())
3945 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003946
Abramo Bagnara509357842011-03-05 14:42:21 +00003947 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003948 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003949 if (OldClsTInfo) {
3950 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3951 if (!NewClsTInfo)
3952 return QualType();
3953 }
3954
3955 const MemberPointerType *T = TL.getTypePtr();
3956 QualType OldClsType = QualType(T->getClass(), 0);
3957 QualType NewClsType;
3958 if (NewClsTInfo)
3959 NewClsType = NewClsTInfo->getType();
3960 else {
3961 NewClsType = getDerived().TransformType(OldClsType);
3962 if (NewClsType.isNull())
3963 return QualType();
3964 }
Mike Stump11289f42009-09-09 15:08:12 +00003965
John McCall550e0c22009-10-21 00:40:46 +00003966 QualType Result = TL.getType();
3967 if (getDerived().AlwaysRebuild() ||
3968 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003969 NewClsType != OldClsType) {
3970 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003971 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003972 if (Result.isNull())
3973 return QualType();
3974 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003975
Reid Kleckner0503a872013-12-05 01:23:43 +00003976 // If we had to adjust the pointee type when building a member pointer, make
3977 // sure to push TypeLoc info for it.
3978 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3979 if (MPT && PointeeType != MPT->getPointeeType()) {
3980 assert(isa<AdjustedType>(MPT->getPointeeType()));
3981 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3982 }
3983
John McCall550e0c22009-10-21 00:40:46 +00003984 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3985 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003986 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003987
3988 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989}
3990
Mike Stump11289f42009-09-09 15:08:12 +00003991template<typename Derived>
3992QualType
John McCall550e0c22009-10-21 00:40:46 +00003993TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003994 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003995 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003996 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003997 if (ElementType.isNull())
3998 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003999
John McCall550e0c22009-10-21 00:40:46 +00004000 QualType Result = TL.getType();
4001 if (getDerived().AlwaysRebuild() ||
4002 ElementType != T->getElementType()) {
4003 Result = getDerived().RebuildConstantArrayType(ElementType,
4004 T->getSizeModifier(),
4005 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004006 T->getIndexTypeCVRQualifiers(),
4007 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004008 if (Result.isNull())
4009 return QualType();
4010 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004011
4012 // We might have either a ConstantArrayType or a VariableArrayType now:
4013 // a ConstantArrayType is allowed to have an element type which is a
4014 // VariableArrayType if the type is dependent. Fortunately, all array
4015 // types have the same location layout.
4016 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004017 NewTL.setLBracketLoc(TL.getLBracketLoc());
4018 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004019
John McCall550e0c22009-10-21 00:40:46 +00004020 Expr *Size = TL.getSizeExpr();
4021 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004022 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4023 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004024 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4025 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004026 }
4027 NewTL.setSizeExpr(Size);
4028
4029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030}
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregord6ff3322009-08-04 16:50:30 +00004032template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004033QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004034 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004035 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004036 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004037 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004038 if (ElementType.isNull())
4039 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004040
John McCall550e0c22009-10-21 00:40:46 +00004041 QualType Result = TL.getType();
4042 if (getDerived().AlwaysRebuild() ||
4043 ElementType != T->getElementType()) {
4044 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004046 T->getIndexTypeCVRQualifiers(),
4047 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004048 if (Result.isNull())
4049 return QualType();
4050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004051
John McCall550e0c22009-10-21 00:40:46 +00004052 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4053 NewTL.setLBracketLoc(TL.getLBracketLoc());
4054 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004055 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004056
4057 return Result;
4058}
4059
4060template<typename Derived>
4061QualType
4062TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004063 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004064 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004065 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4066 if (ElementType.isNull())
4067 return QualType();
4068
John McCalldadc5752010-08-24 06:29:42 +00004069 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004070 = getDerived().TransformExpr(T->getSizeExpr());
4071 if (SizeResult.isInvalid())
4072 return QualType();
4073
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004074 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004075
4076 QualType Result = TL.getType();
4077 if (getDerived().AlwaysRebuild() ||
4078 ElementType != T->getElementType() ||
4079 Size != T->getSizeExpr()) {
4080 Result = getDerived().RebuildVariableArrayType(ElementType,
4081 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004082 Size,
John McCall550e0c22009-10-21 00:40:46 +00004083 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004084 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004085 if (Result.isNull())
4086 return QualType();
4087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
Serge Pavlov774c6d02014-02-06 03:49:11 +00004089 // We might have constant size array now, but fortunately it has the same
4090 // location layout.
4091 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004092 NewTL.setLBracketLoc(TL.getLBracketLoc());
4093 NewTL.setRBracketLoc(TL.getRBracketLoc());
4094 NewTL.setSizeExpr(Size);
4095
4096 return Result;
4097}
4098
4099template<typename Derived>
4100QualType
4101TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004102 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004103 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004104 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4105 if (ElementType.isNull())
4106 return QualType();
4107
Richard Smith764d2fe2011-12-20 02:08:33 +00004108 // Array bounds are constant expressions.
4109 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4110 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004111
John McCall33ddac02011-01-19 10:06:00 +00004112 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4113 Expr *origSize = TL.getSizeExpr();
4114 if (!origSize) origSize = T->getSizeExpr();
4115
4116 ExprResult sizeResult
4117 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004118 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004119 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004120 return QualType();
4121
John McCall33ddac02011-01-19 10:06:00 +00004122 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004123
4124 QualType Result = TL.getType();
4125 if (getDerived().AlwaysRebuild() ||
4126 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004127 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004128 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4129 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004130 size,
John McCall550e0c22009-10-21 00:40:46 +00004131 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004132 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004133 if (Result.isNull())
4134 return QualType();
4135 }
John McCall550e0c22009-10-21 00:40:46 +00004136
4137 // We might have any sort of array type now, but fortunately they
4138 // all have the same location layout.
4139 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4140 NewTL.setLBracketLoc(TL.getLBracketLoc());
4141 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004142 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004143
4144 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004145}
Mike Stump11289f42009-09-09 15:08:12 +00004146
4147template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004148QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004149 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004150 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004151 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004152
4153 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004154 QualType ElementType = getDerived().TransformType(T->getElementType());
4155 if (ElementType.isNull())
4156 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004157
Richard Smith764d2fe2011-12-20 02:08:33 +00004158 // Vector sizes are constant expressions.
4159 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4160 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004161
John McCalldadc5752010-08-24 06:29:42 +00004162 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004163 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004164 if (Size.isInvalid())
4165 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004166
John McCall550e0c22009-10-21 00:40:46 +00004167 QualType Result = TL.getType();
4168 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004169 ElementType != T->getElementType() ||
4170 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004171 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004172 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004173 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004174 if (Result.isNull())
4175 return QualType();
4176 }
John McCall550e0c22009-10-21 00:40:46 +00004177
4178 // Result might be dependent or not.
4179 if (isa<DependentSizedExtVectorType>(Result)) {
4180 DependentSizedExtVectorTypeLoc NewTL
4181 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4182 NewTL.setNameLoc(TL.getNameLoc());
4183 } else {
4184 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4185 NewTL.setNameLoc(TL.getNameLoc());
4186 }
4187
4188 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189}
Mike Stump11289f42009-09-09 15:08:12 +00004190
4191template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004192QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004193 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004194 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195 QualType ElementType = getDerived().TransformType(T->getElementType());
4196 if (ElementType.isNull())
4197 return QualType();
4198
John McCall550e0c22009-10-21 00:40:46 +00004199 QualType Result = TL.getType();
4200 if (getDerived().AlwaysRebuild() ||
4201 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004202 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004203 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004204 if (Result.isNull())
4205 return QualType();
4206 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004207
John McCall550e0c22009-10-21 00:40:46 +00004208 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4209 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004210
John McCall550e0c22009-10-21 00:40:46 +00004211 return Result;
4212}
4213
4214template<typename Derived>
4215QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004216 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004217 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004218 QualType ElementType = getDerived().TransformType(T->getElementType());
4219 if (ElementType.isNull())
4220 return QualType();
4221
4222 QualType Result = TL.getType();
4223 if (getDerived().AlwaysRebuild() ||
4224 ElementType != T->getElementType()) {
4225 Result = getDerived().RebuildExtVectorType(ElementType,
4226 T->getNumElements(),
4227 /*FIXME*/ SourceLocation());
4228 if (Result.isNull())
4229 return QualType();
4230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004231
John McCall550e0c22009-10-21 00:40:46 +00004232 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4233 NewTL.setNameLoc(TL.getNameLoc());
4234
4235 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236}
Mike Stump11289f42009-09-09 15:08:12 +00004237
David Blaikie05785d12013-02-20 22:23:23 +00004238template <typename Derived>
4239ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4240 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4241 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004242 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004243 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004244
Douglas Gregor715e4612011-01-14 22:40:04 +00004245 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004246 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004247 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004248 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004249 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004250
Douglas Gregor715e4612011-01-14 22:40:04 +00004251 TypeLocBuilder TLB;
4252 TypeLoc NewTL = OldDI->getTypeLoc();
4253 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004254
4255 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004256 OldExpansionTL.getPatternLoc());
4257 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004258 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004259
4260 Result = RebuildPackExpansionType(Result,
4261 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004262 OldExpansionTL.getEllipsisLoc(),
4263 NumExpansions);
4264 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004265 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
Douglas Gregor715e4612011-01-14 22:40:04 +00004267 PackExpansionTypeLoc NewExpansionTL
4268 = TLB.push<PackExpansionTypeLoc>(Result);
4269 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4270 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4271 } else
4272 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004273 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004274 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004275
John McCall8fb0d9d2011-05-01 22:35:37 +00004276 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004277 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004278
4279 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4280 OldParm->getDeclContext(),
4281 OldParm->getInnerLocStart(),
4282 OldParm->getLocation(),
4283 OldParm->getIdentifier(),
4284 NewDI->getType(),
4285 NewDI,
4286 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004287 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004288 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4289 OldParm->getFunctionScopeIndex() + indexAdjustment);
4290 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004291}
4292
4293template<typename Derived>
4294bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004295 TransformFunctionTypeParams(SourceLocation Loc,
4296 ParmVarDecl **Params, unsigned NumParams,
4297 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004298 SmallVectorImpl<QualType> &OutParamTypes,
4299 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004300 int indexAdjustment = 0;
4301
Douglas Gregordd472162011-01-07 00:20:55 +00004302 for (unsigned i = 0; i != NumParams; ++i) {
4303 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004304 assert(OldParm->getFunctionScopeIndex() == i);
4305
David Blaikie05785d12013-02-20 22:23:23 +00004306 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004307 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004308 if (OldParm->isParameterPack()) {
4309 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004310 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004311
Douglas Gregor5499af42011-01-05 23:12:31 +00004312 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004313 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004314 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004315 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4316 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004317 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4318
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 // Determine whether we should expand the parameter packs.
4320 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004321 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004322 Optional<unsigned> OrigNumExpansions =
4323 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004324 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004325 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4326 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004327 Unexpanded,
4328 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004329 RetainExpansion,
4330 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004331 return true;
4332 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004333
Douglas Gregor5499af42011-01-05 23:12:31 +00004334 if (ShouldExpand) {
4335 // Expand the function parameter pack into multiple, separate
4336 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004337 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004338 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004339 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004340 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004341 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004342 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004343 OrigNumExpansions,
4344 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004345 if (!NewParm)
4346 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
Douglas Gregordd472162011-01-07 00:20:55 +00004348 OutParamTypes.push_back(NewParm->getType());
4349 if (PVars)
4350 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004351 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004352
4353 // If we're supposed to retain a pack expansion, do so by temporarily
4354 // forgetting the partially-substituted parameter pack.
4355 if (RetainExpansion) {
4356 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004357 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004358 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004359 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004360 OrigNumExpansions,
4361 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004362 if (!NewParm)
4363 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004364
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004365 OutParamTypes.push_back(NewParm->getType());
4366 if (PVars)
4367 PVars->push_back(NewParm);
4368 }
4369
John McCall8fb0d9d2011-05-01 22:35:37 +00004370 // The next parameter should have the same adjustment as the
4371 // last thing we pushed, but we post-incremented indexAdjustment
4372 // on every push. Also, if we push nothing, the adjustment should
4373 // go down by one.
4374 indexAdjustment--;
4375
Douglas Gregor5499af42011-01-05 23:12:31 +00004376 // We're done with the pack expansion.
4377 continue;
4378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004379
4380 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004381 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4383 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004384 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004385 NumExpansions,
4386 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004387 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004388 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004389 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004390 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004391
John McCall58f10c32010-03-11 09:03:00 +00004392 if (!NewParm)
4393 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004394
Douglas Gregordd472162011-01-07 00:20:55 +00004395 OutParamTypes.push_back(NewParm->getType());
4396 if (PVars)
4397 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004398 continue;
4399 }
John McCall58f10c32010-03-11 09:03:00 +00004400
4401 // Deal with the possibility that we don't have a parameter
4402 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004403 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004404 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004405 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004406 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004407 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004408 = dyn_cast<PackExpansionType>(OldType)) {
4409 // We have a function parameter pack that may need to be expanded.
4410 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004411 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004412 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004413
Douglas Gregor5499af42011-01-05 23:12:31 +00004414 // Determine whether we should expand the parameter packs.
4415 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004416 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004417 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004418 Unexpanded,
4419 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004420 RetainExpansion,
4421 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004422 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Douglas Gregor5499af42011-01-05 23:12:31 +00004425 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004426 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004427 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004428 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004429 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4430 QualType NewType = getDerived().TransformType(Pattern);
4431 if (NewType.isNull())
4432 return true;
John McCall58f10c32010-03-11 09:03:00 +00004433
Douglas Gregordd472162011-01-07 00:20:55 +00004434 OutParamTypes.push_back(NewType);
4435 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004436 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004438
Douglas Gregor5499af42011-01-05 23:12:31 +00004439 // We're done with the pack expansion.
4440 continue;
4441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004442
Douglas Gregor48d24112011-01-10 20:53:55 +00004443 // If we're supposed to retain a pack expansion, do so by temporarily
4444 // forgetting the partially-substituted parameter pack.
4445 if (RetainExpansion) {
4446 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4447 QualType NewType = getDerived().TransformType(Pattern);
4448 if (NewType.isNull())
4449 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004450
Douglas Gregor48d24112011-01-10 20:53:55 +00004451 OutParamTypes.push_back(NewType);
4452 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004453 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004454 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004455
Chad Rosier1dcde962012-08-08 18:46:20 +00004456 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 // expansion.
4458 OldType = Expansion->getPattern();
4459 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004460 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4461 NewType = getDerived().TransformType(OldType);
4462 } else {
4463 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004465
Douglas Gregor5499af42011-01-05 23:12:31 +00004466 if (NewType.isNull())
4467 return true;
4468
4469 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004470 NewType = getSema().Context.getPackExpansionType(NewType,
4471 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004472
Douglas Gregordd472162011-01-07 00:20:55 +00004473 OutParamTypes.push_back(NewType);
4474 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004475 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004476 }
4477
John McCall8fb0d9d2011-05-01 22:35:37 +00004478#ifndef NDEBUG
4479 if (PVars) {
4480 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4481 if (ParmVarDecl *parm = (*PVars)[i])
4482 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004483 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004484#endif
4485
4486 return false;
4487}
John McCall58f10c32010-03-11 09:03:00 +00004488
4489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004490QualType
John McCall550e0c22009-10-21 00:40:46 +00004491TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004492 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004493 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004494}
4495
4496template<typename Derived>
4497QualType
4498TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4499 FunctionProtoTypeLoc TL,
4500 CXXRecordDecl *ThisContext,
4501 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004502 // Transform the parameters and return type.
4503 //
Richard Smithf623c962012-04-17 00:58:00 +00004504 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004505 // When the function has a trailing return type, we instantiate the
4506 // parameters before the return type, since the return type can then refer
4507 // to the parameters themselves (via decltype, sizeof, etc.).
4508 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004509 SmallVector<QualType, 4> ParamTypes;
4510 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004511 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004512
Douglas Gregor7fb25412010-10-01 18:44:50 +00004513 QualType ResultType;
4514
Richard Smith1226c602012-08-14 22:51:13 +00004515 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004516 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004517 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004518 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004519 return QualType();
4520
Douglas Gregor3024f072012-04-16 07:05:22 +00004521 {
4522 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004523 // If a declaration declares a member function or member function
4524 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004525 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004526 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004527 // declarator.
4528 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004529
Alp Toker42a16a62014-01-25 23:51:36 +00004530 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004531 if (ResultType.isNull())
4532 return QualType();
4533 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004534 }
4535 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004536 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004537 if (ResultType.isNull())
4538 return QualType();
4539
Alp Toker9cacbab2014-01-20 20:26:09 +00004540 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004541 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004542 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004543 return QualType();
4544 }
4545
Richard Smithf623c962012-04-17 00:58:00 +00004546 // FIXME: Need to transform the exception-specification too.
4547
John McCall550e0c22009-10-21 00:40:46 +00004548 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004549 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004550 T->getNumParams() != ParamTypes.size() ||
4551 !std::equal(T->param_type_begin(), T->param_type_end(),
4552 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004553 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004554 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004555 if (Result.isNull())
4556 return QualType();
4557 }
Mike Stump11289f42009-09-09 15:08:12 +00004558
John McCall550e0c22009-10-21 00:40:46 +00004559 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004560 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004561 NewTL.setLParenLoc(TL.getLParenLoc());
4562 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004563 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004564 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4565 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004566
4567 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004568}
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregord6ff3322009-08-04 16:50:30 +00004570template<typename Derived>
4571QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004572 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004573 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004574 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004575 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004576 if (ResultType.isNull())
4577 return QualType();
4578
4579 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004580 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004581 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4582
4583 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004584 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004585 NewTL.setLParenLoc(TL.getLParenLoc());
4586 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004587 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004588
4589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCallb96ec562009-12-04 22:46:56 +00004592template<typename Derived> QualType
4593TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004594 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004595 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004596 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004597 if (!D)
4598 return QualType();
4599
4600 QualType Result = TL.getType();
4601 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4602 Result = getDerived().RebuildUnresolvedUsingType(D);
4603 if (Result.isNull())
4604 return QualType();
4605 }
4606
4607 // We might get an arbitrary type spec type back. We should at
4608 // least always get a type spec type, though.
4609 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4610 NewTL.setNameLoc(TL.getNameLoc());
4611
4612 return Result;
4613}
4614
Douglas Gregord6ff3322009-08-04 16:50:30 +00004615template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004616QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004617 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004618 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004619 TypedefNameDecl *Typedef
4620 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4621 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004622 if (!Typedef)
4623 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004624
John McCall550e0c22009-10-21 00:40:46 +00004625 QualType Result = TL.getType();
4626 if (getDerived().AlwaysRebuild() ||
4627 Typedef != T->getDecl()) {
4628 Result = getDerived().RebuildTypedefType(Typedef);
4629 if (Result.isNull())
4630 return QualType();
4631 }
Mike Stump11289f42009-09-09 15:08:12 +00004632
John McCall550e0c22009-10-21 00:40:46 +00004633 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4634 NewTL.setNameLoc(TL.getNameLoc());
4635
4636 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004637}
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregord6ff3322009-08-04 16:50:30 +00004639template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004640QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004641 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004642 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004643 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4644 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004645
John McCalldadc5752010-08-24 06:29:42 +00004646 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004647 if (E.isInvalid())
4648 return QualType();
4649
Eli Friedmane4f22df2012-02-29 04:03:55 +00004650 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4651 if (E.isInvalid())
4652 return QualType();
4653
John McCall550e0c22009-10-21 00:40:46 +00004654 QualType Result = TL.getType();
4655 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004656 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004657 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004658 if (Result.isNull())
4659 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004660 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004661 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004662
John McCall550e0c22009-10-21 00:40:46 +00004663 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004664 NewTL.setTypeofLoc(TL.getTypeofLoc());
4665 NewTL.setLParenLoc(TL.getLParenLoc());
4666 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004667
4668 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
4671template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004672QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004673 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004674 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4675 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4676 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004677 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004678
John McCall550e0c22009-10-21 00:40:46 +00004679 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004680 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4681 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004682 if (Result.isNull())
4683 return QualType();
4684 }
Mike Stump11289f42009-09-09 15:08:12 +00004685
John McCall550e0c22009-10-21 00:40:46 +00004686 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004687 NewTL.setTypeofLoc(TL.getTypeofLoc());
4688 NewTL.setLParenLoc(TL.getLParenLoc());
4689 NewTL.setRParenLoc(TL.getRParenLoc());
4690 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004691
4692 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
4695template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004696QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004697 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004698 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004699
Douglas Gregore922c772009-08-04 22:27:00 +00004700 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004701 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4702 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004703
John McCalldadc5752010-08-24 06:29:42 +00004704 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004705 if (E.isInvalid())
4706 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004707
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004708 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004709 if (E.isInvalid())
4710 return QualType();
4711
John McCall550e0c22009-10-21 00:40:46 +00004712 QualType Result = TL.getType();
4713 if (getDerived().AlwaysRebuild() ||
4714 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004715 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004716 if (Result.isNull())
4717 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004718 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004719 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004720
John McCall550e0c22009-10-21 00:40:46 +00004721 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4722 NewTL.setNameLoc(TL.getNameLoc());
4723
4724 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004725}
4726
4727template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004728QualType TreeTransform<Derived>::TransformUnaryTransformType(
4729 TypeLocBuilder &TLB,
4730 UnaryTransformTypeLoc TL) {
4731 QualType Result = TL.getType();
4732 if (Result->isDependentType()) {
4733 const UnaryTransformType *T = TL.getTypePtr();
4734 QualType NewBase =
4735 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4736 Result = getDerived().RebuildUnaryTransformType(NewBase,
4737 T->getUTTKind(),
4738 TL.getKWLoc());
4739 if (Result.isNull())
4740 return QualType();
4741 }
4742
4743 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4744 NewTL.setKWLoc(TL.getKWLoc());
4745 NewTL.setParensRange(TL.getParensRange());
4746 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4747 return Result;
4748}
4749
4750template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004751QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4752 AutoTypeLoc TL) {
4753 const AutoType *T = TL.getTypePtr();
4754 QualType OldDeduced = T->getDeducedType();
4755 QualType NewDeduced;
4756 if (!OldDeduced.isNull()) {
4757 NewDeduced = getDerived().TransformType(OldDeduced);
4758 if (NewDeduced.isNull())
4759 return QualType();
4760 }
4761
4762 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004763 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4764 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004765 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004766 if (Result.isNull())
4767 return QualType();
4768 }
4769
4770 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4771 NewTL.setNameLoc(TL.getNameLoc());
4772
4773 return Result;
4774}
4775
4776template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004777QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004778 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004779 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004780 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004781 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4782 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004783 if (!Record)
4784 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004785
John McCall550e0c22009-10-21 00:40:46 +00004786 QualType Result = TL.getType();
4787 if (getDerived().AlwaysRebuild() ||
4788 Record != T->getDecl()) {
4789 Result = getDerived().RebuildRecordType(Record);
4790 if (Result.isNull())
4791 return QualType();
4792 }
Mike Stump11289f42009-09-09 15:08:12 +00004793
John McCall550e0c22009-10-21 00:40:46 +00004794 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4795 NewTL.setNameLoc(TL.getNameLoc());
4796
4797 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
4800template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004801QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004802 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004803 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004804 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004805 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4806 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004807 if (!Enum)
4808 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004809
John McCall550e0c22009-10-21 00:40:46 +00004810 QualType Result = TL.getType();
4811 if (getDerived().AlwaysRebuild() ||
4812 Enum != T->getDecl()) {
4813 Result = getDerived().RebuildEnumType(Enum);
4814 if (Result.isNull())
4815 return QualType();
4816 }
Mike Stump11289f42009-09-09 15:08:12 +00004817
John McCall550e0c22009-10-21 00:40:46 +00004818 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4819 NewTL.setNameLoc(TL.getNameLoc());
4820
4821 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004822}
John McCallfcc33b02009-09-05 00:15:47 +00004823
John McCalle78aac42010-03-10 03:28:59 +00004824template<typename Derived>
4825QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4826 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004827 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004828 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4829 TL.getTypePtr()->getDecl());
4830 if (!D) return QualType();
4831
4832 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4833 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4834 return T;
4835}
4836
Douglas Gregord6ff3322009-08-04 16:50:30 +00004837template<typename Derived>
4838QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004839 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004840 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004841 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004842}
4843
Mike Stump11289f42009-09-09 15:08:12 +00004844template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004845QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004846 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004847 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004848 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004850 // Substitute into the replacement type, which itself might involve something
4851 // that needs to be transformed. This only tends to occur with default
4852 // template arguments of template template parameters.
4853 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4854 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4855 if (Replacement.isNull())
4856 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004857
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004858 // Always canonicalize the replacement type.
4859 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4860 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004861 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004862 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004863
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004864 // Propagate type-source information.
4865 SubstTemplateTypeParmTypeLoc NewTL
4866 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4867 NewTL.setNameLoc(TL.getNameLoc());
4868 return Result;
4869
John McCallcebee162009-10-18 09:09:24 +00004870}
4871
4872template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004873QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4874 TypeLocBuilder &TLB,
4875 SubstTemplateTypeParmPackTypeLoc TL) {
4876 return TransformTypeSpecType(TLB, TL);
4877}
4878
4879template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004880QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004881 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004882 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004883 const TemplateSpecializationType *T = TL.getTypePtr();
4884
Douglas Gregordf846d12011-03-02 18:46:51 +00004885 // The nested-name-specifier never matters in a TemplateSpecializationType,
4886 // because we can't have a dependent nested-name-specifier anyway.
4887 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004888 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004889 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4890 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004891 if (Template.isNull())
4892 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004893
John McCall31f82722010-11-12 08:19:04 +00004894 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4895}
4896
Eli Friedman0dfb8892011-10-06 23:00:33 +00004897template<typename Derived>
4898QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4899 AtomicTypeLoc TL) {
4900 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4901 if (ValueType.isNull())
4902 return QualType();
4903
4904 QualType Result = TL.getType();
4905 if (getDerived().AlwaysRebuild() ||
4906 ValueType != TL.getValueLoc().getType()) {
4907 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4908 if (Result.isNull())
4909 return QualType();
4910 }
4911
4912 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4913 NewTL.setKWLoc(TL.getKWLoc());
4914 NewTL.setLParenLoc(TL.getLParenLoc());
4915 NewTL.setRParenLoc(TL.getRParenLoc());
4916
4917 return Result;
4918}
4919
Chad Rosier1dcde962012-08-08 18:46:20 +00004920 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004921 /// container that provides a \c getArgLoc() member function.
4922 ///
4923 /// This iterator is intended to be used with the iterator form of
4924 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4925 template<typename ArgLocContainer>
4926 class TemplateArgumentLocContainerIterator {
4927 ArgLocContainer *Container;
4928 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004929
Douglas Gregorfe921a72010-12-20 23:36:19 +00004930 public:
4931 typedef TemplateArgumentLoc value_type;
4932 typedef TemplateArgumentLoc reference;
4933 typedef int difference_type;
4934 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004935
Douglas Gregorfe921a72010-12-20 23:36:19 +00004936 class pointer {
4937 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004938
Douglas Gregorfe921a72010-12-20 23:36:19 +00004939 public:
4940 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004941
Douglas Gregorfe921a72010-12-20 23:36:19 +00004942 const TemplateArgumentLoc *operator->() const {
4943 return &Arg;
4944 }
4945 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
4947
Douglas Gregorfe921a72010-12-20 23:36:19 +00004948 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
Douglas Gregorfe921a72010-12-20 23:36:19 +00004950 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4951 unsigned Index)
4952 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004953
Douglas Gregorfe921a72010-12-20 23:36:19 +00004954 TemplateArgumentLocContainerIterator &operator++() {
4955 ++Index;
4956 return *this;
4957 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004958
Douglas Gregorfe921a72010-12-20 23:36:19 +00004959 TemplateArgumentLocContainerIterator operator++(int) {
4960 TemplateArgumentLocContainerIterator Old(*this);
4961 ++(*this);
4962 return Old;
4963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004964
Douglas Gregorfe921a72010-12-20 23:36:19 +00004965 TemplateArgumentLoc operator*() const {
4966 return Container->getArgLoc(Index);
4967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004968
Douglas Gregorfe921a72010-12-20 23:36:19 +00004969 pointer operator->() const {
4970 return pointer(Container->getArgLoc(Index));
4971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004972
Douglas Gregorfe921a72010-12-20 23:36:19 +00004973 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004974 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004975 return X.Container == Y.Container && X.Index == Y.Index;
4976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004977
Douglas Gregorfe921a72010-12-20 23:36:19 +00004978 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004979 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004980 return !(X == Y);
4981 }
4982 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004983
4984
John McCall31f82722010-11-12 08:19:04 +00004985template <typename Derived>
4986QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4987 TypeLocBuilder &TLB,
4988 TemplateSpecializationTypeLoc TL,
4989 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004990 TemplateArgumentListInfo NewTemplateArgs;
4991 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4992 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004993 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4994 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004995 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004996 ArgIterator(TL, TL.getNumArgs()),
4997 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004998 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004999
John McCall0ad16662009-10-29 08:12:44 +00005000 // FIXME: maybe don't rebuild if all the template arguments are the same.
5001
5002 QualType Result =
5003 getDerived().RebuildTemplateSpecializationType(Template,
5004 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005005 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005006
5007 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005008 // Specializations of template template parameters are represented as
5009 // TemplateSpecializationTypes, and substitution of type alias templates
5010 // within a dependent context can transform them into
5011 // DependentTemplateSpecializationTypes.
5012 if (isa<DependentTemplateSpecializationType>(Result)) {
5013 DependentTemplateSpecializationTypeLoc NewTL
5014 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005015 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005016 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005017 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005018 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005019 NewTL.setLAngleLoc(TL.getLAngleLoc());
5020 NewTL.setRAngleLoc(TL.getRAngleLoc());
5021 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5022 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5023 return Result;
5024 }
5025
John McCall0ad16662009-10-29 08:12:44 +00005026 TemplateSpecializationTypeLoc NewTL
5027 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005028 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005029 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5030 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());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005034 }
Mike Stump11289f42009-09-09 15:08:12 +00005035
John McCall0ad16662009-10-29 08:12:44 +00005036 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005037}
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregor5a064722011-02-28 17:23:35 +00005039template <typename Derived>
5040QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5041 TypeLocBuilder &TLB,
5042 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005043 TemplateName Template,
5044 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005045 TemplateArgumentListInfo NewTemplateArgs;
5046 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5047 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5048 typedef TemplateArgumentLocContainerIterator<
5049 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005050 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005051 ArgIterator(TL, TL.getNumArgs()),
5052 NewTemplateArgs))
5053 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005054
Douglas Gregor5a064722011-02-28 17:23:35 +00005055 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005056
Douglas Gregor5a064722011-02-28 17:23:35 +00005057 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5058 QualType Result
5059 = getSema().Context.getDependentTemplateSpecializationType(
5060 TL.getTypePtr()->getKeyword(),
5061 DTN->getQualifier(),
5062 DTN->getIdentifier(),
5063 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005064
Douglas Gregor5a064722011-02-28 17:23:35 +00005065 DependentTemplateSpecializationTypeLoc NewTL
5066 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005067 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005068 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005069 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005070 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005071 NewTL.setLAngleLoc(TL.getLAngleLoc());
5072 NewTL.setRAngleLoc(TL.getRAngleLoc());
5073 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5074 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5075 return Result;
5076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005077
5078 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005079 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005080 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005081 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005082
Douglas Gregor5a064722011-02-28 17:23:35 +00005083 if (!Result.isNull()) {
5084 /// FIXME: Wrap this in an elaborated-type-specifier?
5085 TemplateSpecializationTypeLoc NewTL
5086 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005087 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005088 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005089 NewTL.setLAngleLoc(TL.getLAngleLoc());
5090 NewTL.setRAngleLoc(TL.getRAngleLoc());
5091 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5092 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5093 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005094
Douglas Gregor5a064722011-02-28 17:23:35 +00005095 return Result;
5096}
5097
Mike Stump11289f42009-09-09 15:08:12 +00005098template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005099QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005100TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005101 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005102 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005103
Douglas Gregor844cb502011-03-01 18:12:44 +00005104 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005105 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005106 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005107 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005108 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5109 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005110 return QualType();
5111 }
Mike Stump11289f42009-09-09 15:08:12 +00005112
John McCall31f82722010-11-12 08:19:04 +00005113 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5114 if (NamedT.isNull())
5115 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005116
Richard Smith3f1b5d02011-05-05 21:57:07 +00005117 // C++0x [dcl.type.elab]p2:
5118 // If the identifier resolves to a typedef-name or the simple-template-id
5119 // resolves to an alias template specialization, the
5120 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005121 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5122 if (const TemplateSpecializationType *TST =
5123 NamedT->getAs<TemplateSpecializationType>()) {
5124 TemplateName Template = TST->getTemplateName();
5125 if (TypeAliasTemplateDecl *TAT =
5126 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5127 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5128 diag::err_tag_reference_non_tag) << 4;
5129 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5130 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005131 }
5132 }
5133
John McCall550e0c22009-10-21 00:40:46 +00005134 QualType Result = TL.getType();
5135 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005136 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005137 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005138 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005139 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005140 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005141 if (Result.isNull())
5142 return QualType();
5143 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005144
Abramo Bagnara6150c882010-05-11 21:36:43 +00005145 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005146 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005147 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005149}
Mike Stump11289f42009-09-09 15:08:12 +00005150
5151template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005152QualType TreeTransform<Derived>::TransformAttributedType(
5153 TypeLocBuilder &TLB,
5154 AttributedTypeLoc TL) {
5155 const AttributedType *oldType = TL.getTypePtr();
5156 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5157 if (modifiedType.isNull())
5158 return QualType();
5159
5160 QualType result = TL.getType();
5161
5162 // FIXME: dependent operand expressions?
5163 if (getDerived().AlwaysRebuild() ||
5164 modifiedType != oldType->getModifiedType()) {
5165 // TODO: this is really lame; we should really be rebuilding the
5166 // equivalent type from first principles.
5167 QualType equivalentType
5168 = getDerived().TransformType(oldType->getEquivalentType());
5169 if (equivalentType.isNull())
5170 return QualType();
5171 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5172 modifiedType,
5173 equivalentType);
5174 }
5175
5176 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5177 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5178 if (TL.hasAttrOperand())
5179 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5180 if (TL.hasAttrExprOperand())
5181 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5182 else if (TL.hasAttrEnumOperand())
5183 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5184
5185 return result;
5186}
5187
5188template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005189QualType
5190TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5191 ParenTypeLoc TL) {
5192 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5193 if (Inner.isNull())
5194 return QualType();
5195
5196 QualType Result = TL.getType();
5197 if (getDerived().AlwaysRebuild() ||
5198 Inner != TL.getInnerLoc().getType()) {
5199 Result = getDerived().RebuildParenType(Inner);
5200 if (Result.isNull())
5201 return QualType();
5202 }
5203
5204 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5205 NewTL.setLParenLoc(TL.getLParenLoc());
5206 NewTL.setRParenLoc(TL.getRParenLoc());
5207 return Result;
5208}
5209
5210template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005211QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005212 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005213 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005214
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005215 NestedNameSpecifierLoc QualifierLoc
5216 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5217 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005218 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005219
John McCallc392f372010-06-11 00:33:02 +00005220 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005221 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005222 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005223 QualifierLoc,
5224 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005225 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005226 if (Result.isNull())
5227 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005228
Abramo Bagnarad7548482010-05-19 21:37:53 +00005229 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5230 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005231 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5232
Abramo Bagnarad7548482010-05-19 21:37:53 +00005233 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005234 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005235 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005236 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005237 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005238 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005239 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005240 NewTL.setNameLoc(TL.getNameLoc());
5241 }
John McCall550e0c22009-10-21 00:40:46 +00005242 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005243}
Mike Stump11289f42009-09-09 15:08:12 +00005244
Douglas Gregord6ff3322009-08-04 16:50:30 +00005245template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005246QualType TreeTransform<Derived>::
5247 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005248 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005249 NestedNameSpecifierLoc QualifierLoc;
5250 if (TL.getQualifierLoc()) {
5251 QualifierLoc
5252 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5253 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005254 return QualType();
5255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
John McCall31f82722010-11-12 08:19:04 +00005257 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005258 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005259}
5260
5261template<typename Derived>
5262QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005263TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5264 DependentTemplateSpecializationTypeLoc TL,
5265 NestedNameSpecifierLoc QualifierLoc) {
5266 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005267
Douglas Gregora7a795b2011-03-01 20:11:18 +00005268 TemplateArgumentListInfo NewTemplateArgs;
5269 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5270 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005271
Douglas Gregora7a795b2011-03-01 20:11:18 +00005272 typedef TemplateArgumentLocContainerIterator<
5273 DependentTemplateSpecializationTypeLoc> ArgIterator;
5274 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5275 ArgIterator(TL, TL.getNumArgs()),
5276 NewTemplateArgs))
5277 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005278
Douglas Gregora7a795b2011-03-01 20:11:18 +00005279 QualType Result
5280 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5281 QualifierLoc,
5282 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005283 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005284 NewTemplateArgs);
5285 if (Result.isNull())
5286 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005287
Douglas Gregora7a795b2011-03-01 20:11:18 +00005288 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5289 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005290
Douglas Gregora7a795b2011-03-01 20:11:18 +00005291 // Copy information relevant to the template specialization.
5292 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005293 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005294 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005295 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005296 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5297 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005298 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005299 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
Douglas Gregora7a795b2011-03-01 20:11:18 +00005301 // Copy information relevant to the elaborated type.
5302 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005303 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005304 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005305 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5306 DependentTemplateSpecializationTypeLoc SpecTL
5307 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005308 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005309 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005310 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005311 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005312 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5313 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005314 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005315 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005316 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005317 TemplateSpecializationTypeLoc SpecTL
5318 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005319 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005320 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005321 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5322 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005323 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005324 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005325 }
5326 return Result;
5327}
5328
5329template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005330QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5331 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005332 QualType Pattern
5333 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005334 if (Pattern.isNull())
5335 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005336
5337 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005338 if (getDerived().AlwaysRebuild() ||
5339 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005340 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005341 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005342 TL.getEllipsisLoc(),
5343 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005344 if (Result.isNull())
5345 return QualType();
5346 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005347
Douglas Gregor822d0302011-01-12 17:07:58 +00005348 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5349 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5350 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005351}
5352
5353template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005354QualType
5355TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005356 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005357 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005358 TLB.pushFullCopy(TL);
5359 return TL.getType();
5360}
5361
5362template<typename Derived>
5363QualType
5364TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005365 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005366 // ObjCObjectType is never dependent.
5367 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005368 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005369}
Mike Stump11289f42009-09-09 15:08:12 +00005370
5371template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005372QualType
5373TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005374 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005375 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005376 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005377 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005378}
5379
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005381// Statement transformation
5382//===----------------------------------------------------------------------===//
5383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005384StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005385TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005386 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005387}
5388
5389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005390StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005391TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5392 return getDerived().TransformCompoundStmt(S, false);
5393}
5394
5395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005396StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005397TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005398 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005399 Sema::CompoundScopeRAII CompoundScope(getSema());
5400
John McCall1ababa62010-08-27 19:56:05 +00005401 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005402 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005403 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005404 for (auto *B : S->body()) {
5405 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005406 if (Result.isInvalid()) {
5407 // Immediately fail if this was a DeclStmt, since it's very
5408 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005409 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005410 return StmtError();
5411
5412 // Otherwise, just keep processing substatements and fail later.
5413 SubStmtInvalid = true;
5414 continue;
5415 }
Mike Stump11289f42009-09-09 15:08:12 +00005416
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005417 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005418 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005419 }
Mike Stump11289f42009-09-09 15:08:12 +00005420
John McCall1ababa62010-08-27 19:56:05 +00005421 if (SubStmtInvalid)
5422 return StmtError();
5423
Douglas Gregorebe10102009-08-20 07:17:43 +00005424 if (!getDerived().AlwaysRebuild() &&
5425 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005426 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005427
5428 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005429 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005430 S->getRBracLoc(),
5431 IsStmtExpr);
5432}
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregorebe10102009-08-20 07:17:43 +00005434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005435StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005436TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005437 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005438 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005439 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5440 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005441
Eli Friedman06577382009-11-19 03:14:00 +00005442 // Transform the left-hand case value.
5443 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005444 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005445 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005446 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005447
Eli Friedman06577382009-11-19 03:14:00 +00005448 // Transform the right-hand case value (for the GNU case-range extension).
5449 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005450 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005451 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005452 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005453 }
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregorebe10102009-08-20 07:17:43 +00005455 // Build the case statement.
5456 // Case statements are always rebuilt so that they will attached to their
5457 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005458 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005459 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005460 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005461 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005462 S->getColonLoc());
5463 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005467 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005468 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregorebe10102009-08-20 07:17:43 +00005471 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005472 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005473}
5474
5475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005476StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005477TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005478 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005479 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005480 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 // Default statements are always rebuilt
5484 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005485 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregorebe10102009-08-20 07:17:43 +00005488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005489StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005491 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005492 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005493 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005494
Chris Lattnercab02a62011-02-17 20:34:02 +00005495 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5496 S->getDecl());
5497 if (!LD)
5498 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005499
5500
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005502 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005503 cast<LabelDecl>(LD), SourceLocation(),
5504 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005505}
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregorebe10102009-08-20 07:17:43 +00005507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005508StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005509TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5510 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5511 if (SubStmt.isInvalid())
5512 return StmtError();
5513
5514 // TODO: transform attributes
5515 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5516 return S;
5517
5518 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5519 S->getAttrs(),
5520 SubStmt.get());
5521}
5522
5523template<typename Derived>
5524StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005525TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005527 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005528 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005529 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005530 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005531 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005532 getDerived().TransformDefinition(
5533 S->getConditionVariable()->getLocation(),
5534 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005535 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005537 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005538 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005539
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005540 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005543 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005544 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005545 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005546 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005547 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005548 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005549
John McCallb268a282010-08-23 23:25:46 +00005550 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005551 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005553
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005554 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005555 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005556 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005557
Douglas Gregorebe10102009-08-20 07:17:43 +00005558 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005559 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005560 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregorebe10102009-08-20 07:17:43 +00005563 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005564 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005565 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregorebe10102009-08-20 07:17:43 +00005568 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005569 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005570 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 Then.get() == S->getThen() &&
5572 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005573 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005575 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005576 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005577 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005578}
5579
5580template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005581StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005582TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005584 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005585 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005586 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005587 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005588 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005589 getDerived().TransformDefinition(
5590 S->getConditionVariable()->getLocation(),
5591 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005592 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005594 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005595 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005596
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005597 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005599 }
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005602 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005603 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005604 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
Douglas Gregorebe10102009-08-20 07:17:43 +00005608 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005609 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005610 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005611 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005612
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005614 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5615 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregorebe10102009-08-20 07:17:43 +00005618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005620TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005622 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005623 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005624 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005625 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005626 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005627 getDerived().TransformDefinition(
5628 S->getConditionVariable()->getLocation(),
5629 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005630 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005631 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005632 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005633 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005634
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005635 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005636 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005637
5638 if (S->getCond()) {
5639 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005640 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5641 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005642 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005643 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005645 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005646 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005647 }
Mike Stump11289f42009-09-09 15:08:12 +00005648
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005649 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005650 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005652
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005654 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005655 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005659 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005660 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005661 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005662 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005664 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005665 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005666}
Mike Stump11289f42009-09-09 15:08:12 +00005667
Douglas Gregorebe10102009-08-20 07:17:43 +00005668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005669StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005670TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005672 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005676 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005677 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005678 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005680
Douglas Gregorebe10102009-08-20 07:17:43 +00005681 if (!getDerived().AlwaysRebuild() &&
5682 Cond.get() == S->getCond() &&
5683 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005684 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005685
John McCallb268a282010-08-23 23:25:46 +00005686 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5687 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 S->getRParenLoc());
5689}
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005695 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005697 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005698
Douglas Gregorebe10102009-08-20 07:17:43 +00005699 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005700 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005701 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005702 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005703 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005704 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005705 getDerived().TransformDefinition(
5706 S->getConditionVariable()->getLocation(),
5707 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005708 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005709 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005710 } else {
5711 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005712
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005713 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005714 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005715
5716 if (S->getCond()) {
5717 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005718 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5719 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005720 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005721 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005722 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005723
John McCallb268a282010-08-23 23:25:46 +00005724 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005725 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005726 }
Mike Stump11289f42009-09-09 15:08:12 +00005727
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005728 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005729 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005730 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005731
Douglas Gregorebe10102009-08-20 07:17:43 +00005732 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005733 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005734 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005736
Richard Smith945f8d32013-01-14 22:39:08 +00005737 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005738 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005739 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005740
Douglas Gregorebe10102009-08-20 07:17:43 +00005741 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005742 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005743 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005744 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregorebe10102009-08-20 07:17:43 +00005746 if (!getDerived().AlwaysRebuild() &&
5747 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005748 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005749 Inc.get() == S->getInc() &&
5750 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005751 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005752
Douglas Gregorebe10102009-08-20 07:17:43 +00005753 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005754 Init.get(), FullCond, ConditionVar,
5755 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005756}
5757
5758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005759StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005760TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005761 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5762 S->getLabel());
5763 if (!LD)
5764 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005765
Douglas Gregorebe10102009-08-20 07:17:43 +00005766 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005767 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005768 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005769}
5770
5771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005772StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005773TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005774 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005775 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005776 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005777 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005778
Douglas Gregorebe10102009-08-20 07:17:43 +00005779 if (!getDerived().AlwaysRebuild() &&
5780 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005781 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005782
5783 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005784 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005785}
5786
5787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005788StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005789TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005790 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005791}
Mike Stump11289f42009-09-09 15:08:12 +00005792
Douglas Gregorebe10102009-08-20 07:17:43 +00005793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005794StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005795TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005796 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005797}
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregorebe10102009-08-20 07:17:43 +00005799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005800StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005801TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005802 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005803 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005804 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005805
Mike Stump11289f42009-09-09 15:08:12 +00005806 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005807 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005808 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005809}
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregorebe10102009-08-20 07:17:43 +00005811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005813TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005814 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005815 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005816 for (auto *D : S->decls()) {
5817 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005819 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005820
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005821 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005822 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregorebe10102009-08-20 07:17:43 +00005824 Decls.push_back(Transformed);
5825 }
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregorebe10102009-08-20 07:17:43 +00005827 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005828 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005829
Rafael Espindolaab417692013-07-09 12:05:01 +00005830 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregorebe10102009-08-20 07:17:43 +00005833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005835TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005836
Benjamin Kramerf0623432012-08-23 22:51:59 +00005837 SmallVector<Expr*, 8> Constraints;
5838 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005839 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005840
John McCalldadc5752010-08-24 06:29:42 +00005841 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005842 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005843
5844 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005845
Anders Carlssonaaeef072010-01-24 05:50:09 +00005846 // Go through the outputs.
5847 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005848 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005849
Anders Carlssonaaeef072010-01-24 05:50:09 +00005850 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005851 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
Anders Carlssonaaeef072010-01-24 05:50:09 +00005853 // Transform the output expr.
5854 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005855 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005856 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Anders Carlssonaaeef072010-01-24 05:50:09 +00005859 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005860
John McCallb268a282010-08-23 23:25:46 +00005861 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005862 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Anders Carlssonaaeef072010-01-24 05:50:09 +00005864 // Go through the inputs.
5865 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005866 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005867
Anders Carlssonaaeef072010-01-24 05:50:09 +00005868 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005869 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
Anders Carlssonaaeef072010-01-24 05:50:09 +00005871 // Transform the input expr.
5872 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005873 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005874 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005875 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Anders Carlssonaaeef072010-01-24 05:50:09 +00005877 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005878
John McCallb268a282010-08-23 23:25:46 +00005879 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
Anders Carlssonaaeef072010-01-24 05:50:09 +00005882 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005883 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005884
5885 // Go through the clobbers.
5886 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005887 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005888
5889 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005890 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005891 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5892 S->isVolatile(), S->getNumOutputs(),
5893 S->getNumInputs(), Names.data(),
5894 Constraints, Exprs, AsmString.get(),
5895 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005896}
5897
Chad Rosier32503022012-06-11 20:47:18 +00005898template<typename Derived>
5899StmtResult
5900TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005901 ArrayRef<Token> AsmToks =
5902 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005903
John McCallf413f5e2013-05-03 00:10:13 +00005904 bool HadError = false, HadChange = false;
5905
5906 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5907 SmallVector<Expr*, 8> TransformedExprs;
5908 TransformedExprs.reserve(SrcExprs.size());
5909 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5910 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5911 if (!Result.isUsable()) {
5912 HadError = true;
5913 } else {
5914 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005915 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005916 }
5917 }
5918
5919 if (HadError) return StmtError();
5920 if (!HadChange && !getDerived().AlwaysRebuild())
5921 return Owned(S);
5922
Chad Rosierb6f46c12012-08-15 16:53:30 +00005923 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005924 AsmToks, S->getAsmString(),
5925 S->getNumOutputs(), S->getNumInputs(),
5926 S->getAllConstraints(), S->getClobbers(),
5927 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005928}
Douglas Gregorebe10102009-08-20 07:17:43 +00005929
5930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005931StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005932TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005933 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005934 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005935 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005936 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
Douglas Gregor96c79492010-04-23 22:50:49 +00005938 // Transform the @catch statements (if present).
5939 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005940 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005941 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005942 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005943 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005944 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005945 if (Catch.get() != S->getCatchStmt(I))
5946 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005947 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005949
Douglas Gregor306de2f2010-04-22 23:59:56 +00005950 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005951 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005952 if (S->getFinallyStmt()) {
5953 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5954 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005955 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005956 }
5957
5958 // If nothing changed, just retain this statement.
5959 if (!getDerived().AlwaysRebuild() &&
5960 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005961 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005962 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005963 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005964
Douglas Gregor306de2f2010-04-22 23:59:56 +00005965 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005966 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005967 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005968}
Mike Stump11289f42009-09-09 15:08:12 +00005969
Douglas Gregorebe10102009-08-20 07:17:43 +00005970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005971StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005972TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005973 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005974 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005975 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005976 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005977 if (FromVar->getTypeSourceInfo()) {
5978 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5979 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005980 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005983 QualType T;
5984 if (TSInfo)
5985 T = TSInfo->getType();
5986 else {
5987 T = getDerived().TransformType(FromVar->getType());
5988 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005989 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005991
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005992 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5993 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005995 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005996
John McCalldadc5752010-08-24 06:29:42 +00005997 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005998 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005999 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006000
6001 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006002 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006003 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006004}
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregorebe10102009-08-20 07:17:43 +00006006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006008TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006009 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006010 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006011 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
Douglas Gregor306de2f2010-04-22 23:59:56 +00006014 // If nothing changed, just retain this statement.
6015 if (!getDerived().AlwaysRebuild() &&
6016 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006017 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006018
6019 // Build a new statement.
6020 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006021 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006022}
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregorebe10102009-08-20 07:17:43 +00006024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006025StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006026TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006027 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006028 if (S->getThrowExpr()) {
6029 Operand = getDerived().TransformExpr(S->getThrowExpr());
6030 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006033
Douglas Gregor2900c162010-04-22 21:44:01 +00006034 if (!getDerived().AlwaysRebuild() &&
6035 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006036 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006037
John McCallb268a282010-08-23 23:25:46 +00006038 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006043TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006044 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006045 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006046 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006047 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006048 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006049 Object =
6050 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6051 Object.get());
6052 if (Object.isInvalid())
6053 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006054
Douglas Gregor6148de72010-04-22 22:01:21 +00006055 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006056 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006057 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006058 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006059
Douglas Gregor6148de72010-04-22 22:01:21 +00006060 // If nothing change, just retain the current statement.
6061 if (!getDerived().AlwaysRebuild() &&
6062 Object.get() == S->getSynchExpr() &&
6063 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006064 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006065
6066 // Build a new statement.
6067 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006068 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006069}
6070
6071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006072StmtResult
John McCall31168b02011-06-15 23:02:42 +00006073TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6074 ObjCAutoreleasePoolStmt *S) {
6075 // Transform the body.
6076 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6077 if (Body.isInvalid())
6078 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006079
John McCall31168b02011-06-15 23:02:42 +00006080 // If nothing changed, just retain this statement.
6081 if (!getDerived().AlwaysRebuild() &&
6082 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006083 return S;
John McCall31168b02011-06-15 23:02:42 +00006084
6085 // Build a new statement.
6086 return getDerived().RebuildObjCAutoreleasePoolStmt(
6087 S->getAtLoc(), Body.get());
6088}
6089
6090template<typename Derived>
6091StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006092TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006093 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006094 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006095 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006096 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006098
Douglas Gregorf68a5082010-04-22 23:10:45 +00006099 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006100 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006101 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006102 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006103
Douglas Gregorf68a5082010-04-22 23:10:45 +00006104 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006105 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006106 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006107 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006108
Douglas Gregorf68a5082010-04-22 23:10:45 +00006109 // If nothing changed, just retain this statement.
6110 if (!getDerived().AlwaysRebuild() &&
6111 Element.get() == S->getElement() &&
6112 Collection.get() == S->getCollection() &&
6113 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006114 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006115
Douglas Gregorf68a5082010-04-22 23:10:45 +00006116 // Build a new statement.
6117 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006118 Element.get(),
6119 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006120 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006121 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006122}
6123
David Majnemer5f7efef2013-10-15 09:50:08 +00006124template <typename Derived>
6125StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006126 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006127 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006128 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6129 TypeSourceInfo *T =
6130 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006131 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006132 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006133
David Majnemer5f7efef2013-10-15 09:50:08 +00006134 Var = getDerived().RebuildExceptionDecl(
6135 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6136 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006137 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006138 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 }
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregorebe10102009-08-20 07:17:43 +00006141 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006142 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006143 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006144 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006145
David Majnemer5f7efef2013-10-15 09:50:08 +00006146 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006147 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006148 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006149
David Majnemer5f7efef2013-10-15 09:50:08 +00006150 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006151}
Mike Stump11289f42009-09-09 15:08:12 +00006152
David Majnemer5f7efef2013-10-15 09:50:08 +00006153template <typename Derived>
6154StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006155 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006156 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006158 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006159
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 // Transform the handlers.
6161 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006162 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006163 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006164 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006165 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006166 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006167
Douglas Gregorebe10102009-08-20 07:17:43 +00006168 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006169 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 }
Mike Stump11289f42009-09-09 15:08:12 +00006171
David Majnemer5f7efef2013-10-15 09:50:08 +00006172 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006174 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006175
John McCallb268a282010-08-23 23:25:46 +00006176 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006177 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006178}
Mike Stump11289f42009-09-09 15:08:12 +00006179
Richard Smith02e85f32011-04-14 22:09:26 +00006180template<typename Derived>
6181StmtResult
6182TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6183 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6184 if (Range.isInvalid())
6185 return StmtError();
6186
6187 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6188 if (BeginEnd.isInvalid())
6189 return StmtError();
6190
6191 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6192 if (Cond.isInvalid())
6193 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006194 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006195 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006196 if (Cond.isInvalid())
6197 return StmtError();
6198 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006199 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006200
6201 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6202 if (Inc.isInvalid())
6203 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006204 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006205 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006206
6207 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6208 if (LoopVar.isInvalid())
6209 return StmtError();
6210
6211 StmtResult NewStmt = S;
6212 if (getDerived().AlwaysRebuild() ||
6213 Range.get() != S->getRangeStmt() ||
6214 BeginEnd.get() != S->getBeginEndStmt() ||
6215 Cond.get() != S->getCond() ||
6216 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006217 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006218 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6219 S->getColonLoc(), Range.get(),
6220 BeginEnd.get(), Cond.get(),
6221 Inc.get(), LoopVar.get(),
6222 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006223 if (NewStmt.isInvalid())
6224 return StmtError();
6225 }
Richard Smith02e85f32011-04-14 22:09:26 +00006226
6227 StmtResult Body = getDerived().TransformStmt(S->getBody());
6228 if (Body.isInvalid())
6229 return StmtError();
6230
6231 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6232 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006233 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006234 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6235 S->getColonLoc(), Range.get(),
6236 BeginEnd.get(), Cond.get(),
6237 Inc.get(), LoopVar.get(),
6238 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006239 if (NewStmt.isInvalid())
6240 return StmtError();
6241 }
Richard Smith02e85f32011-04-14 22:09:26 +00006242
6243 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006244 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006245
6246 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6247}
6248
John Wiegley1c0675e2011-04-28 01:08:34 +00006249template<typename Derived>
6250StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006251TreeTransform<Derived>::TransformMSDependentExistsStmt(
6252 MSDependentExistsStmt *S) {
6253 // Transform the nested-name-specifier, if any.
6254 NestedNameSpecifierLoc QualifierLoc;
6255 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006256 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006257 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6258 if (!QualifierLoc)
6259 return StmtError();
6260 }
6261
6262 // Transform the declaration name.
6263 DeclarationNameInfo NameInfo = S->getNameInfo();
6264 if (NameInfo.getName()) {
6265 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6266 if (!NameInfo.getName())
6267 return StmtError();
6268 }
6269
6270 // Check whether anything changed.
6271 if (!getDerived().AlwaysRebuild() &&
6272 QualifierLoc == S->getQualifierLoc() &&
6273 NameInfo.getName() == S->getNameInfo().getName())
6274 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006275
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006276 // Determine whether this name exists, if we can.
6277 CXXScopeSpec SS;
6278 SS.Adopt(QualifierLoc);
6279 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006280 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006281 case Sema::IER_Exists:
6282 if (S->isIfExists())
6283 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006284
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006285 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6286
6287 case Sema::IER_DoesNotExist:
6288 if (S->isIfNotExists())
6289 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006290
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006291 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006292
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006293 case Sema::IER_Dependent:
6294 Dependent = true;
6295 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006296
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006297 case Sema::IER_Error:
6298 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006300
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006301 // We need to continue with the instantiation, so do so now.
6302 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6303 if (SubStmt.isInvalid())
6304 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006305
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006306 // If we have resolved the name, just transform to the substatement.
6307 if (!Dependent)
6308 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006309
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006310 // The name is still dependent, so build a dependent expression again.
6311 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6312 S->isIfExists(),
6313 QualifierLoc,
6314 NameInfo,
6315 SubStmt.get());
6316}
6317
6318template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006319ExprResult
6320TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6321 NestedNameSpecifierLoc QualifierLoc;
6322 if (E->getQualifierLoc()) {
6323 QualifierLoc
6324 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6325 if (!QualifierLoc)
6326 return ExprError();
6327 }
6328
6329 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6330 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6331 if (!PD)
6332 return ExprError();
6333
6334 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6335 if (Base.isInvalid())
6336 return ExprError();
6337
6338 return new (SemaRef.getASTContext())
6339 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6340 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6341 QualifierLoc, E->getMemberLoc());
6342}
6343
David Majnemerfad8f482013-10-15 09:33:02 +00006344template <typename Derived>
6345StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006346 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006347 if (TryBlock.isInvalid())
6348 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006349
6350 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006351 if (Handler.isInvalid())
6352 return StmtError();
6353
David Majnemerfad8f482013-10-15 09:33:02 +00006354 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6355 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006356 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006357
David Majnemerfad8f482013-10-15 09:33:02 +00006358 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006359 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006360}
6361
David Majnemerfad8f482013-10-15 09:33:02 +00006362template <typename Derived>
6363StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006364 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006365 if (Block.isInvalid())
6366 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006367
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006368 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006369}
6370
David Majnemerfad8f482013-10-15 09:33:02 +00006371template <typename Derived>
6372StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006373 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006374 if (FilterExpr.isInvalid())
6375 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006376
David Majnemer7e755502013-10-15 09:30:14 +00006377 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006378 if (Block.isInvalid())
6379 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006380
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006381 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6382 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006383}
6384
David Majnemerfad8f482013-10-15 09:33:02 +00006385template <typename Derived>
6386StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6387 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006388 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6389 else
6390 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6391}
6392
Nico Weber9b982072014-07-07 00:12:30 +00006393template<typename Derived>
6394StmtResult
6395TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6396 return S;
6397}
6398
Alexander Musman64d33f12014-06-04 07:53:32 +00006399//===----------------------------------------------------------------------===//
6400// OpenMP directive transformation
6401//===----------------------------------------------------------------------===//
6402template <typename Derived>
6403StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6404 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006405
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006406 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006407 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006408 ArrayRef<OMPClause *> Clauses = D->clauses();
6409 TClauses.reserve(Clauses.size());
6410 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6411 I != E; ++I) {
6412 if (*I) {
6413 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006414 if (Clause)
6415 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006416 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006417 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006418 }
6419 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006420 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006421 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006422 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006423 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006424 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataevc5e02582014-06-16 07:08:35 +00006425 if (AssociatedStmt.isInvalid() || TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006426 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006427 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006428
Alexander Musman64d33f12014-06-04 07:53:32 +00006429 return getDerived().RebuildOMPExecutableDirective(
6430 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6431 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006432}
6433
Alexander Musman64d33f12014-06-04 07:53:32 +00006434template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006435StmtResult
6436TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6437 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006438 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6439 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006440 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6441 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6442 return Res;
6443}
6444
Alexander Musman64d33f12014-06-04 07:53:32 +00006445template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006446StmtResult
6447TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6448 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006449 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6450 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006451 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6452 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006453 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006454}
6455
Alexey Bataevf29276e2014-06-18 04:14:57 +00006456template <typename Derived>
6457StmtResult
6458TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6459 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006460 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6461 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006462 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6463 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6464 return Res;
6465}
6466
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006467template <typename Derived>
6468StmtResult
6469TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6470 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006471 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6472 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006473 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6474 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6475 return Res;
6476}
6477
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006478template <typename Derived>
6479StmtResult
6480TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6481 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006482 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6483 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006484 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6485 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6486 return Res;
6487}
6488
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006489template <typename Derived>
6490StmtResult
6491TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6492 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006493 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6494 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006495 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6496 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6497 return Res;
6498}
6499
Alexey Bataev4acb8592014-07-07 13:01:15 +00006500template <typename Derived>
6501StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6502 OMPParallelForDirective *D) {
6503 DeclarationNameInfo DirName;
6504 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6505 nullptr, D->getLocStart());
6506 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6507 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6508 return Res;
6509}
6510
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006511template <typename Derived>
6512StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6513 OMPParallelSectionsDirective *D) {
6514 DeclarationNameInfo DirName;
6515 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6516 nullptr, D->getLocStart());
6517 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6518 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6519 return Res;
6520}
6521
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006522template <typename Derived>
6523StmtResult
6524TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6525 DeclarationNameInfo DirName;
6526 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6527 D->getLocStart());
6528 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6529 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6530 return Res;
6531}
6532
Alexander Musman64d33f12014-06-04 07:53:32 +00006533//===----------------------------------------------------------------------===//
6534// OpenMP clause transformation
6535//===----------------------------------------------------------------------===//
6536template <typename Derived>
6537OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006538 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6539 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006540 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006541 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006542 C->getLParenLoc(), C->getLocEnd());
6543}
6544
Alexander Musman64d33f12014-06-04 07:53:32 +00006545template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006546OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006547TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6548 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6549 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006550 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006551 return getDerived().RebuildOMPNumThreadsClause(
6552 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006553}
6554
Alexey Bataev62c87d22014-03-21 04:51:18 +00006555template <typename Derived>
6556OMPClause *
6557TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6558 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6559 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006560 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006561 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006562 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006563}
6564
Alexander Musman8bd31e62014-05-27 15:12:19 +00006565template <typename Derived>
6566OMPClause *
6567TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6568 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6569 if (E.isInvalid())
6570 return 0;
6571 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006572 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006573}
6574
Alexander Musman64d33f12014-06-04 07:53:32 +00006575template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006576OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006577TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006578 return getDerived().RebuildOMPDefaultClause(
6579 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6580 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006581}
6582
Alexander Musman64d33f12014-06-04 07:53:32 +00006583template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006584OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006585TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006586 return getDerived().RebuildOMPProcBindClause(
6587 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6588 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006589}
6590
Alexander Musman64d33f12014-06-04 07:53:32 +00006591template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006592OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006593TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6594 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6595 if (E.isInvalid())
6596 return nullptr;
6597 return getDerived().RebuildOMPScheduleClause(
6598 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6599 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6600}
6601
6602template <typename Derived>
6603OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006604TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6605 // No need to rebuild this clause, no template-dependent parameters.
6606 return C;
6607}
6608
6609template <typename Derived>
6610OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006611TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6612 // No need to rebuild this clause, no template-dependent parameters.
6613 return C;
6614}
6615
6616template <typename Derived>
6617OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006618TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006619 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006620 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006621 for (auto *VE : C->varlists()) {
6622 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006623 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006624 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006625 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006626 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006627 return getDerived().RebuildOMPPrivateClause(
6628 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006629}
6630
Alexander Musman64d33f12014-06-04 07:53:32 +00006631template <typename Derived>
6632OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6633 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006634 llvm::SmallVector<Expr *, 16> Vars;
6635 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006636 for (auto *VE : C->varlists()) {
6637 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006638 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006639 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006640 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006641 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006642 return getDerived().RebuildOMPFirstprivateClause(
6643 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006644}
6645
Alexander Musman64d33f12014-06-04 07:53:32 +00006646template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006647OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006648TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6649 llvm::SmallVector<Expr *, 16> Vars;
6650 Vars.reserve(C->varlist_size());
6651 for (auto *VE : C->varlists()) {
6652 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6653 if (EVar.isInvalid())
6654 return nullptr;
6655 Vars.push_back(EVar.get());
6656 }
6657 return getDerived().RebuildOMPLastprivateClause(
6658 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6659}
6660
6661template <typename Derived>
6662OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006663TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6664 llvm::SmallVector<Expr *, 16> Vars;
6665 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006666 for (auto *VE : C->varlists()) {
6667 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006668 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006669 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006670 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006671 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006672 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6673 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006674}
6675
Alexander Musman64d33f12014-06-04 07:53:32 +00006676template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006677OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006678TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6679 llvm::SmallVector<Expr *, 16> Vars;
6680 Vars.reserve(C->varlist_size());
6681 for (auto *VE : C->varlists()) {
6682 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6683 if (EVar.isInvalid())
6684 return nullptr;
6685 Vars.push_back(EVar.get());
6686 }
6687 CXXScopeSpec ReductionIdScopeSpec;
6688 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6689
6690 DeclarationNameInfo NameInfo = C->getNameInfo();
6691 if (NameInfo.getName()) {
6692 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6693 if (!NameInfo.getName())
6694 return nullptr;
6695 }
6696 return getDerived().RebuildOMPReductionClause(
6697 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6698 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6699}
6700
6701template <typename Derived>
6702OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006703TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6704 llvm::SmallVector<Expr *, 16> Vars;
6705 Vars.reserve(C->varlist_size());
6706 for (auto *VE : C->varlists()) {
6707 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6708 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006709 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006710 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006711 }
6712 ExprResult Step = getDerived().TransformExpr(C->getStep());
6713 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006714 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006715 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6716 C->getLParenLoc(),
6717 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006718}
6719
Alexander Musman64d33f12014-06-04 07:53:32 +00006720template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006721OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006722TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6723 llvm::SmallVector<Expr *, 16> Vars;
6724 Vars.reserve(C->varlist_size());
6725 for (auto *VE : C->varlists()) {
6726 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6727 if (EVar.isInvalid())
6728 return nullptr;
6729 Vars.push_back(EVar.get());
6730 }
6731 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6732 if (Alignment.isInvalid())
6733 return nullptr;
6734 return getDerived().RebuildOMPAlignedClause(
6735 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6736 C->getColonLoc(), C->getLocEnd());
6737}
6738
Alexander Musman64d33f12014-06-04 07:53:32 +00006739template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006740OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006741TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6742 llvm::SmallVector<Expr *, 16> Vars;
6743 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006744 for (auto *VE : C->varlists()) {
6745 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006746 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006747 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006748 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006749 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006750 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6751 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006752}
6753
Alexey Bataevbae9a792014-06-27 10:37:06 +00006754template <typename Derived>
6755OMPClause *
6756TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6757 llvm::SmallVector<Expr *, 16> Vars;
6758 Vars.reserve(C->varlist_size());
6759 for (auto *VE : C->varlists()) {
6760 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6761 if (EVar.isInvalid())
6762 return nullptr;
6763 Vars.push_back(EVar.get());
6764 }
6765 return getDerived().RebuildOMPCopyprivateClause(
6766 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6767}
6768
Douglas Gregorebe10102009-08-20 07:17:43 +00006769//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006770// Expression transformation
6771//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006775 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006776}
Mike Stump11289f42009-09-09 15:08:12 +00006777
6778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006781 NestedNameSpecifierLoc QualifierLoc;
6782 if (E->getQualifierLoc()) {
6783 QualifierLoc
6784 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6785 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006787 }
John McCallce546572009-12-08 09:08:17 +00006788
6789 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006790 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6791 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006792 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006794
John McCall815039a2010-08-17 21:27:17 +00006795 DeclarationNameInfo NameInfo = E->getNameInfo();
6796 if (NameInfo.getName()) {
6797 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6798 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006799 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006800 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006801
6802 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006803 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006804 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006805 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006806 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006807
6808 // Mark it referenced in the new context regardless.
6809 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006810 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006811
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006812 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006813 }
John McCallce546572009-12-08 09:08:17 +00006814
Craig Topperc3ec1492014-05-26 06:22:03 +00006815 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006816 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006817 TemplateArgs = &TransArgs;
6818 TransArgs.setLAngleLoc(E->getLAngleLoc());
6819 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006820 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6821 E->getNumTemplateArgs(),
6822 TransArgs))
6823 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006824 }
6825
Chad Rosier1dcde962012-08-08 18:46:20 +00006826 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006827 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006828}
Mike Stump11289f42009-09-09 15:08:12 +00006829
Douglas Gregora16548e2009-08-11 05:31:07 +00006830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006832TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006833 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006834}
Mike Stump11289f42009-09-09 15:08:12 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006838TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006839 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006840}
Mike Stump11289f42009-09-09 15:08:12 +00006841
Douglas Gregora16548e2009-08-11 05:31:07 +00006842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006844TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006845 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006846}
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregora16548e2009-08-11 05:31:07 +00006848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006850TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006851 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006852}
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregora16548e2009-08-11 05:31:07 +00006854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006856TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006857 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006858}
6859
6860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006861ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006862TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006863 if (FunctionDecl *FD = E->getDirectCallee())
6864 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006865 return SemaRef.MaybeBindToTemporary(E);
6866}
6867
6868template<typename Derived>
6869ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006870TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6871 ExprResult ControllingExpr =
6872 getDerived().TransformExpr(E->getControllingExpr());
6873 if (ControllingExpr.isInvalid())
6874 return ExprError();
6875
Chris Lattner01cf8db2011-07-20 06:58:45 +00006876 SmallVector<Expr *, 4> AssocExprs;
6877 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006878 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6879 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6880 if (TS) {
6881 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6882 if (!AssocType)
6883 return ExprError();
6884 AssocTypes.push_back(AssocType);
6885 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006886 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006887 }
6888
6889 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6890 if (AssocExpr.isInvalid())
6891 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006892 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006893 }
6894
6895 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6896 E->getDefaultLoc(),
6897 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006898 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006899 AssocTypes,
6900 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006901}
6902
6903template<typename Derived>
6904ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006905TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006906 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006908 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006909
Douglas Gregora16548e2009-08-11 05:31:07 +00006910 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006911 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006912
John McCallb268a282010-08-23 23:25:46 +00006913 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006914 E->getRParen());
6915}
6916
Richard Smithdb2630f2012-10-21 03:28:35 +00006917/// \brief The operand of a unary address-of operator has special rules: it's
6918/// allowed to refer to a non-static member of a class even if there's no 'this'
6919/// object available.
6920template<typename Derived>
6921ExprResult
6922TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6923 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00006924 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00006925 else
6926 return getDerived().TransformExpr(E);
6927}
6928
Mike Stump11289f42009-09-09 15:08:12 +00006929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006931TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006932 ExprResult SubExpr;
6933 if (E->getOpcode() == UO_AddrOf)
6934 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6935 else
6936 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006938 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006941 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregora16548e2009-08-11 05:31:07 +00006943 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6944 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006945 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006946}
Mike Stump11289f42009-09-09 15:08:12 +00006947
Douglas Gregora16548e2009-08-11 05:31:07 +00006948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006949ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006950TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6951 // Transform the type.
6952 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6953 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006955
Douglas Gregor882211c2010-04-28 22:16:22 +00006956 // Transform all of the components into components similar to what the
6957 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006958 // FIXME: It would be slightly more efficient in the non-dependent case to
6959 // just map FieldDecls, rather than requiring the rebuilder to look for
6960 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006961 // template code that we don't care.
6962 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006963 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006964 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006965 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006966 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6967 const Node &ON = E->getComponent(I);
6968 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006969 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006970 Comp.LocStart = ON.getSourceRange().getBegin();
6971 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006972 switch (ON.getKind()) {
6973 case Node::Array: {
6974 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006975 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006976 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006978
Douglas Gregor882211c2010-04-28 22:16:22 +00006979 ExprChanged = ExprChanged || Index.get() != FromIndex;
6980 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006981 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006982 break;
6983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006984
Douglas Gregor882211c2010-04-28 22:16:22 +00006985 case Node::Field:
6986 case Node::Identifier:
6987 Comp.isBrackets = false;
6988 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006989 if (!Comp.U.IdentInfo)
6990 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006991
Douglas Gregor882211c2010-04-28 22:16:22 +00006992 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006993
Douglas Gregord1702062010-04-29 00:18:15 +00006994 case Node::Base:
6995 // Will be recomputed during the rebuild.
6996 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006998
Douglas Gregor882211c2010-04-28 22:16:22 +00006999 Components.push_back(Comp);
7000 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007001
Douglas Gregor882211c2010-04-28 22:16:22 +00007002 // If nothing changed, retain the existing expression.
7003 if (!getDerived().AlwaysRebuild() &&
7004 Type == E->getTypeSourceInfo() &&
7005 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007006 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007007
Douglas Gregor882211c2010-04-28 22:16:22 +00007008 // Build a new offsetof expression.
7009 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7010 Components.data(), Components.size(),
7011 E->getRParenLoc());
7012}
7013
7014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007015ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007016TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7017 assert(getDerived().AlreadyTransformed(E->getType()) &&
7018 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007019 return E;
John McCall8d69a212010-11-15 23:31:06 +00007020}
7021
7022template<typename Derived>
7023ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007024TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007025 // Rebuild the syntactic form. The original syntactic form has
7026 // opaque-value expressions in it, so strip those away and rebuild
7027 // the result. This is a really awful way of doing this, but the
7028 // better solution (rebuilding the semantic expressions and
7029 // rebinding OVEs as necessary) doesn't work; we'd need
7030 // TreeTransform to not strip away implicit conversions.
7031 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7032 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007033 if (result.isInvalid()) return ExprError();
7034
7035 // If that gives us a pseudo-object result back, the pseudo-object
7036 // expression must have been an lvalue-to-rvalue conversion which we
7037 // should reapply.
7038 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007039 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007040
7041 return result;
7042}
7043
7044template<typename Derived>
7045ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007046TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7047 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007049 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007050
John McCallbcd03502009-12-07 02:54:59 +00007051 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007052 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007054
John McCall4c98fd82009-11-04 07:28:41 +00007055 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007056 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007057
Peter Collingbournee190dee2011-03-11 19:24:49 +00007058 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7059 E->getKind(),
7060 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007061 }
Mike Stump11289f42009-09-09 15:08:12 +00007062
Eli Friedmane4f22df2012-02-29 04:03:55 +00007063 // C++0x [expr.sizeof]p1:
7064 // The operand is either an expression, which is an unevaluated operand
7065 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007066 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7067 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007068
Reid Kleckner32506ed2014-06-12 23:03:48 +00007069 // Try to recover if we have something like sizeof(T::X) where X is a type.
7070 // Notably, there must be *exactly* one set of parens if X is a type.
7071 TypeSourceInfo *RecoveryTSI = nullptr;
7072 ExprResult SubExpr;
7073 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7074 if (auto *DRE =
7075 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7076 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7077 PE, DRE, false, &RecoveryTSI);
7078 else
7079 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7080
7081 if (RecoveryTSI) {
7082 return getDerived().RebuildUnaryExprOrTypeTrait(
7083 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7084 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007086
Eli Friedmane4f22df2012-02-29 04:03:55 +00007087 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007088 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007089
Peter Collingbournee190dee2011-03-11 19:24:49 +00007090 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7091 E->getOperatorLoc(),
7092 E->getKind(),
7093 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007094}
Mike Stump11289f42009-09-09 15:08:12 +00007095
Douglas Gregora16548e2009-08-11 05:31:07 +00007096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007098TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007099 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007100 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007102
John McCalldadc5752010-08-24 06:29:42 +00007103 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007106
7107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108 if (!getDerived().AlwaysRebuild() &&
7109 LHS.get() == E->getLHS() &&
7110 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007111 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007112
John McCallb268a282010-08-23 23:25:46 +00007113 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007115 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007116 E->getRBracketLoc());
7117}
Mike Stump11289f42009-09-09 15:08:12 +00007118
7119template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007120ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007121TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007123 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007124 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007125 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007126
7127 // Transform arguments.
7128 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007129 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007130 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007131 &ArgChanged))
7132 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007133
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 if (!getDerived().AlwaysRebuild() &&
7135 Callee.get() == E->getCallee() &&
7136 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007137 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007138
Douglas Gregora16548e2009-08-11 05:31:07 +00007139 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007140 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007141 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007142 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007143 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 E->getRParenLoc());
7145}
Mike Stump11289f42009-09-09 15:08:12 +00007146
7147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007149TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007150 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007153
Douglas Gregorea972d32011-02-28 21:54:11 +00007154 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007155 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007156 QualifierLoc
7157 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007158
Douglas Gregorea972d32011-02-28 21:54:11 +00007159 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007160 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007161 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007162 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007163
Eli Friedman2cfcef62009-12-04 06:40:45 +00007164 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007165 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7166 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007167 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007169
John McCall16df1e52010-03-30 21:47:33 +00007170 NamedDecl *FoundDecl = E->getFoundDecl();
7171 if (FoundDecl == E->getMemberDecl()) {
7172 FoundDecl = Member;
7173 } else {
7174 FoundDecl = cast_or_null<NamedDecl>(
7175 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7176 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007177 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007178 }
7179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 if (!getDerived().AlwaysRebuild() &&
7181 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007182 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007183 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007184 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007185 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007186
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007187 // Mark it referenced in the new context regardless.
7188 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007189 SemaRef.MarkMemberReferenced(E);
7190
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007191 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007192 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007193
John McCall6b51f282009-11-23 01:53:49 +00007194 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007195 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007196 TransArgs.setLAngleLoc(E->getLAngleLoc());
7197 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007198 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7199 E->getNumTemplateArgs(),
7200 TransArgs))
7201 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007202 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007203
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007205 SourceLocation FakeOperatorLoc =
7206 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007207
John McCall38836f02010-01-15 08:34:02 +00007208 // FIXME: to do this check properly, we will need to preserve the
7209 // first-qualifier-in-scope here, just in case we had a dependent
7210 // base (and therefore couldn't do the check) and a
7211 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007212 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007213
John McCallb268a282010-08-23 23:25:46 +00007214 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007215 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007216 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007217 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007218 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007219 Member,
John McCall16df1e52010-03-30 21:47:33 +00007220 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007221 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007222 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007223 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007224}
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregora16548e2009-08-11 05:31:07 +00007226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007228TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007229 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007232
John McCalldadc5752010-08-24 06:29:42 +00007233 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007234 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007236
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 if (!getDerived().AlwaysRebuild() &&
7238 LHS.get() == E->getLHS() &&
7239 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007240 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007241
Lang Hames5de91cc2012-10-02 04:45:10 +00007242 Sema::FPContractStateRAII FPContractState(getSema());
7243 getSema().FPFeatures.fp_contract = E->isFPContractable();
7244
Douglas Gregora16548e2009-08-11 05:31:07 +00007245 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007246 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007247}
7248
Mike Stump11289f42009-09-09 15:08:12 +00007249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007250ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007251TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007252 CompoundAssignOperator *E) {
7253 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007254}
Mike Stump11289f42009-09-09 15:08:12 +00007255
Douglas Gregora16548e2009-08-11 05:31:07 +00007256template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007257ExprResult TreeTransform<Derived>::
7258TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7259 // Just rebuild the common and RHS expressions and see whether we
7260 // get any changes.
7261
7262 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7263 if (commonExpr.isInvalid())
7264 return ExprError();
7265
7266 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7267 if (rhs.isInvalid())
7268 return ExprError();
7269
7270 if (!getDerived().AlwaysRebuild() &&
7271 commonExpr.get() == e->getCommon() &&
7272 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007273 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007274
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007275 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007276 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007277 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007278 e->getColonLoc(),
7279 rhs.get());
7280}
7281
7282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007284TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007285 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007288
John McCalldadc5752010-08-24 06:29:42 +00007289 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007292
John McCalldadc5752010-08-24 06:29:42 +00007293 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007296
Douglas Gregora16548e2009-08-11 05:31:07 +00007297 if (!getDerived().AlwaysRebuild() &&
7298 Cond.get() == E->getCond() &&
7299 LHS.get() == E->getLHS() &&
7300 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007301 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007302
John McCallb268a282010-08-23 23:25:46 +00007303 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007304 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007305 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007306 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007307 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
7310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007313 // Implicit casts are eliminated during transformation, since they
7314 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007315 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007316}
Mike Stump11289f42009-09-09 15:08:12 +00007317
Douglas Gregora16548e2009-08-11 05:31:07 +00007318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007320TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007321 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7322 if (!Type)
7323 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007324
John McCalldadc5752010-08-24 06:29:42 +00007325 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007326 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007327 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007331 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007332 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007333 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007334
John McCall97513962010-01-15 18:39:57 +00007335 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007336 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007337 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007338 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007339}
Mike Stump11289f42009-09-09 15:08:12 +00007340
Douglas Gregora16548e2009-08-11 05:31:07 +00007341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007343TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007344 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7345 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7346 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007348
John McCalldadc5752010-08-24 06:29:42 +00007349 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007350 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007352
Douglas Gregora16548e2009-08-11 05:31:07 +00007353 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007354 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007356 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007357
John McCall5d7aa7f2010-01-19 22:33:45 +00007358 // Note: the expression type doesn't necessarily match the
7359 // type-as-written, but that's okay, because it should always be
7360 // derivable from the initializer.
7361
John McCalle15bbff2010-01-18 19:35:47 +00007362 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007364 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007365}
Mike Stump11289f42009-09-09 15:08:12 +00007366
Douglas Gregora16548e2009-08-11 05:31:07 +00007367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007369TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007370 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregora16548e2009-08-11 05:31:07 +00007374 if (!getDerived().AlwaysRebuild() &&
7375 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007376 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007377
Douglas Gregora16548e2009-08-11 05:31:07 +00007378 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007379 SourceLocation FakeOperatorLoc =
7380 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007381 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 E->getAccessorLoc(),
7383 E->getAccessor());
7384}
Mike Stump11289f42009-09-09 15:08:12 +00007385
Douglas Gregora16548e2009-08-11 05:31:07 +00007386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007388TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007389 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007390
Benjamin Kramerf0623432012-08-23 22:51:59 +00007391 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007392 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007393 Inits, &InitChanged))
7394 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007397 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007398
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007399 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007400 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007401}
Mike Stump11289f42009-09-09 15:08:12 +00007402
Douglas Gregora16548e2009-08-11 05:31:07 +00007403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007405TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007406 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregorebe10102009-08-20 07:17:43 +00007408 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007409 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007410 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007412
Douglas Gregorebe10102009-08-20 07:17:43 +00007413 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007414 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007415 bool ExprChanged = false;
7416 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7417 DEnd = E->designators_end();
7418 D != DEnd; ++D) {
7419 if (D->isFieldDesignator()) {
7420 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7421 D->getDotLoc(),
7422 D->getFieldLoc()));
7423 continue;
7424 }
Mike Stump11289f42009-09-09 15:08:12 +00007425
Douglas Gregora16548e2009-08-11 05:31:07 +00007426 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007427 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007430
7431 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007433
Douglas Gregora16548e2009-08-11 05:31:07 +00007434 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007435 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 continue;
7437 }
Mike Stump11289f42009-09-09 15:08:12 +00007438
Douglas Gregora16548e2009-08-11 05:31:07 +00007439 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007440 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007441 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7442 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007444
John McCalldadc5752010-08-24 06:29:42 +00007445 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007446 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007448
7449 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007450 End.get(),
7451 D->getLBracketLoc(),
7452 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007453
Douglas Gregora16548e2009-08-11 05:31:07 +00007454 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7455 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007456
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007457 ArrayExprs.push_back(Start.get());
7458 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 }
Mike Stump11289f42009-09-09 15:08:12 +00007460
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 if (!getDerived().AlwaysRebuild() &&
7462 Init.get() == E->getInit() &&
7463 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007464 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007465
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007466 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007467 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007468 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007469}
Mike Stump11289f42009-09-09 15:08:12 +00007470
Douglas Gregora16548e2009-08-11 05:31:07 +00007471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007472ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007473TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007474 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007475 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007476
Douglas Gregor3da3c062009-10-28 00:29:27 +00007477 // FIXME: Will we ever have proper type location here? Will we actually
7478 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007479 QualType T = getDerived().TransformType(E->getType());
7480 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregora16548e2009-08-11 05:31:07 +00007483 if (!getDerived().AlwaysRebuild() &&
7484 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007485 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007486
Douglas Gregora16548e2009-08-11 05:31:07 +00007487 return getDerived().RebuildImplicitValueInitExpr(T);
7488}
Mike Stump11289f42009-09-09 15:08:12 +00007489
Douglas Gregora16548e2009-08-11 05:31:07 +00007490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007491ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007492TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007493 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7494 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007495 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007496
John McCalldadc5752010-08-24 06:29:42 +00007497 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007498 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007500
Douglas Gregora16548e2009-08-11 05:31:07 +00007501 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007502 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007503 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007504 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007505
John McCallb268a282010-08-23 23:25:46 +00007506 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007507 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007508}
7509
7510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007512TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007513 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007514 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007515 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7516 &ArgumentChanged))
7517 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007518
Douglas Gregora16548e2009-08-11 05:31:07 +00007519 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007520 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007521 E->getRParenLoc());
7522}
Mike Stump11289f42009-09-09 15:08:12 +00007523
Douglas Gregora16548e2009-08-11 05:31:07 +00007524/// \brief Transform an address-of-label expression.
7525///
7526/// By default, the transformation of an address-of-label expression always
7527/// rebuilds the expression, so that the label identifier can be resolved to
7528/// the corresponding label statement by semantic analysis.
7529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007531TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007532 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7533 E->getLabel());
7534 if (!LD)
7535 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007536
Douglas Gregora16548e2009-08-11 05:31:07 +00007537 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007538 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007539}
Mike Stump11289f42009-09-09 15:08:12 +00007540
7541template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007543TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007544 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007545 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007547 if (SubStmt.isInvalid()) {
7548 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007550 }
Mike Stump11289f42009-09-09 15:08:12 +00007551
Douglas Gregora16548e2009-08-11 05:31:07 +00007552 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007553 SubStmt.get() == E->getSubStmt()) {
7554 // Calling this an 'error' is unintuitive, but it does the right thing.
7555 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007556 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007557 }
Mike Stump11289f42009-09-09 15:08:12 +00007558
7559 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007560 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007561 E->getRParenLoc());
7562}
Mike Stump11289f42009-09-09 15:08:12 +00007563
Douglas Gregora16548e2009-08-11 05:31:07 +00007564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007566TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007567 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007568 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007570
John McCalldadc5752010-08-24 06:29:42 +00007571 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007574
John McCalldadc5752010-08-24 06:29:42 +00007575 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007576 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007578
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 if (!getDerived().AlwaysRebuild() &&
7580 Cond.get() == E->getCond() &&
7581 LHS.get() == E->getLHS() &&
7582 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007583 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007584
Douglas Gregora16548e2009-08-11 05:31:07 +00007585 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007586 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 E->getRParenLoc());
7588}
Mike Stump11289f42009-09-09 15:08:12 +00007589
Douglas Gregora16548e2009-08-11 05:31:07 +00007590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007592TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007593 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007594}
7595
7596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007598TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007599 switch (E->getOperator()) {
7600 case OO_New:
7601 case OO_Delete:
7602 case OO_Array_New:
7603 case OO_Array_Delete:
7604 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007605
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007606 case OO_Call: {
7607 // This is a call to an object's operator().
7608 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7609
7610 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007611 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007612 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007613 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007614
7615 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007616 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7617 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007618
7619 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007620 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007621 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007622 Args))
7623 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007624
John McCallb268a282010-08-23 23:25:46 +00007625 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007626 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007627 E->getLocEnd());
7628 }
7629
7630#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7631 case OO_##Name:
7632#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7633#include "clang/Basic/OperatorKinds.def"
7634 case OO_Subscript:
7635 // Handled below.
7636 break;
7637
7638 case OO_Conditional:
7639 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007640
7641 case OO_None:
7642 case NUM_OVERLOADED_OPERATORS:
7643 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007644 }
7645
John McCalldadc5752010-08-24 06:29:42 +00007646 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007647 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007649
Richard Smithdb2630f2012-10-21 03:28:35 +00007650 ExprResult First;
7651 if (E->getOperator() == OO_Amp)
7652 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7653 else
7654 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007655 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007656 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007657
John McCalldadc5752010-08-24 06:29:42 +00007658 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 if (E->getNumArgs() == 2) {
7660 Second = getDerived().TransformExpr(E->getArg(1));
7661 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007662 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007663 }
Mike Stump11289f42009-09-09 15:08:12 +00007664
Douglas Gregora16548e2009-08-11 05:31:07 +00007665 if (!getDerived().AlwaysRebuild() &&
7666 Callee.get() == E->getCallee() &&
7667 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007668 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007669 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007670
Lang Hames5de91cc2012-10-02 04:45:10 +00007671 Sema::FPContractStateRAII FPContractState(getSema());
7672 getSema().FPFeatures.fp_contract = E->isFPContractable();
7673
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7675 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007676 Callee.get(),
7677 First.get(),
7678 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007679}
Mike Stump11289f42009-09-09 15:08:12 +00007680
Douglas Gregora16548e2009-08-11 05:31:07 +00007681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007682ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007683TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7684 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007685}
Mike Stump11289f42009-09-09 15:08:12 +00007686
Douglas Gregora16548e2009-08-11 05:31:07 +00007687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007688ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007689TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7690 // Transform the callee.
7691 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7692 if (Callee.isInvalid())
7693 return ExprError();
7694
7695 // Transform exec config.
7696 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7697 if (EC.isInvalid())
7698 return ExprError();
7699
7700 // Transform arguments.
7701 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007702 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007703 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007704 &ArgChanged))
7705 return ExprError();
7706
7707 if (!getDerived().AlwaysRebuild() &&
7708 Callee.get() == E->getCallee() &&
7709 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007710 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007711
7712 // FIXME: Wrong source location information for the '('.
7713 SourceLocation FakeLParenLoc
7714 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7715 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007716 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007717 E->getRParenLoc(), EC.get());
7718}
7719
7720template<typename Derived>
7721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007722TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007723 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7724 if (!Type)
7725 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007726
John McCalldadc5752010-08-24 06:29:42 +00007727 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007728 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007729 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007731
Douglas Gregora16548e2009-08-11 05:31:07 +00007732 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007733 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007734 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007735 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007736 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007737 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007738 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007739 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007740 E->getAngleBrackets().getEnd(),
7741 // FIXME. this should be '(' location
7742 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007743 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007744 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007745}
Mike Stump11289f42009-09-09 15:08:12 +00007746
Douglas Gregora16548e2009-08-11 05:31:07 +00007747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007748ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007749TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7750 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007751}
Mike Stump11289f42009-09-09 15:08:12 +00007752
7753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007754ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007755TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7756 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007757}
7758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007760ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007761TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007762 CXXReinterpretCastExpr *E) {
7763 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007764}
Mike Stump11289f42009-09-09 15:08:12 +00007765
Douglas Gregora16548e2009-08-11 05:31:07 +00007766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007767ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007768TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7769 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007770}
Mike Stump11289f42009-09-09 15:08:12 +00007771
Douglas Gregora16548e2009-08-11 05:31:07 +00007772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007773ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007774TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007775 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007776 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7777 if (!Type)
7778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007779
John McCalldadc5752010-08-24 06:29:42 +00007780 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007781 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007782 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007783 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007784
Douglas Gregora16548e2009-08-11 05:31:07 +00007785 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007786 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007787 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007788 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007789
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007790 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007791 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007792 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007793 E->getRParenLoc());
7794}
Mike Stump11289f42009-09-09 15:08:12 +00007795
Douglas Gregora16548e2009-08-11 05:31:07 +00007796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007798TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007799 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007800 TypeSourceInfo *TInfo
7801 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7802 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007804
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007806 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007807 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007808
Douglas Gregor9da64192010-04-26 22:37:10 +00007809 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7810 E->getLocStart(),
7811 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007812 E->getLocEnd());
7813 }
Mike Stump11289f42009-09-09 15:08:12 +00007814
Eli Friedman456f0182012-01-20 01:26:23 +00007815 // We don't know whether the subexpression is potentially evaluated until
7816 // after we perform semantic analysis. We speculatively assume it is
7817 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007819 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7820 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007821
John McCalldadc5752010-08-24 06:29:42 +00007822 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007823 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregora16548e2009-08-11 05:31:07 +00007826 if (!getDerived().AlwaysRebuild() &&
7827 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007828 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007829
Douglas Gregor9da64192010-04-26 22:37:10 +00007830 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7831 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007832 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007833 E->getLocEnd());
7834}
7835
7836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007837ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007838TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7839 if (E->isTypeOperand()) {
7840 TypeSourceInfo *TInfo
7841 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7842 if (!TInfo)
7843 return ExprError();
7844
7845 if (!getDerived().AlwaysRebuild() &&
7846 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007847 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007848
Douglas Gregor69735112011-03-06 17:40:41 +00007849 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007850 E->getLocStart(),
7851 TInfo,
7852 E->getLocEnd());
7853 }
7854
Francois Pichet9f4f2072010-09-08 12:20:18 +00007855 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7856
7857 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7858 if (SubExpr.isInvalid())
7859 return ExprError();
7860
7861 if (!getDerived().AlwaysRebuild() &&
7862 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007863 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007864
7865 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7866 E->getLocStart(),
7867 SubExpr.get(),
7868 E->getLocEnd());
7869}
7870
7871template<typename Derived>
7872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007873TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007874 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007875}
Mike Stump11289f42009-09-09 15:08:12 +00007876
Douglas Gregora16548e2009-08-11 05:31:07 +00007877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007878ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007879TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007880 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007881 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007882}
Mike Stump11289f42009-09-09 15:08:12 +00007883
Douglas Gregora16548e2009-08-11 05:31:07 +00007884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007886TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007887 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007888
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007889 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7890 // Make sure that we capture 'this'.
7891 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007892 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007893 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007894
Douglas Gregorb15af892010-01-07 23:12:05 +00007895 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007896}
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007900TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007901 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007902 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007903 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007904
Douglas Gregora16548e2009-08-11 05:31:07 +00007905 if (!getDerived().AlwaysRebuild() &&
7906 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007907 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007908
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007909 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7910 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007911}
Mike Stump11289f42009-09-09 15:08:12 +00007912
Douglas Gregora16548e2009-08-11 05:31:07 +00007913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007915TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007916 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007917 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7918 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007919 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007920 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007921
Chandler Carruth794da4c2010-02-08 06:42:49 +00007922 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007924 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007925
Douglas Gregor033f6752009-12-23 23:03:06 +00007926 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007927}
Mike Stump11289f42009-09-09 15:08:12 +00007928
Douglas Gregora16548e2009-08-11 05:31:07 +00007929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007930ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007931TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7932 FieldDecl *Field
7933 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7934 E->getField()));
7935 if (!Field)
7936 return ExprError();
7937
7938 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007939 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007940
7941 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7942}
7943
7944template<typename Derived>
7945ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007946TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7947 CXXScalarValueInitExpr *E) {
7948 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7949 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007950 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007951
Douglas Gregora16548e2009-08-11 05:31:07 +00007952 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007953 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007954 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007955
Chad Rosier1dcde962012-08-08 18:46:20 +00007956 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007957 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007958 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007959}
Mike Stump11289f42009-09-09 15:08:12 +00007960
Douglas Gregora16548e2009-08-11 05:31:07 +00007961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007962ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007963TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007964 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007965 TypeSourceInfo *AllocTypeInfo
7966 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7967 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregora16548e2009-08-11 05:31:07 +00007970 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007971 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007972 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007974
Douglas Gregora16548e2009-08-11 05:31:07 +00007975 // Transform the placement arguments (if any).
7976 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007977 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007978 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007979 E->getNumPlacementArgs(), true,
7980 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007982
Sebastian Redl6047f072012-02-16 12:22:20 +00007983 // Transform the initializer (if any).
7984 Expr *OldInit = E->getInitializer();
7985 ExprResult NewInit;
7986 if (OldInit)
7987 NewInit = getDerived().TransformExpr(OldInit);
7988 if (NewInit.isInvalid())
7989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007990
Sebastian Redl6047f072012-02-16 12:22:20 +00007991 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007992 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007993 if (E->getOperatorNew()) {
7994 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007995 getDerived().TransformDecl(E->getLocStart(),
7996 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007997 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007998 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007999 }
8000
Craig Topperc3ec1492014-05-26 06:22:03 +00008001 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008002 if (E->getOperatorDelete()) {
8003 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008004 getDerived().TransformDecl(E->getLocStart(),
8005 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008006 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008007 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008009
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008011 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008012 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008013 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008014 OperatorNew == E->getOperatorNew() &&
8015 OperatorDelete == E->getOperatorDelete() &&
8016 !ArgumentChanged) {
8017 // Mark any declarations we need as referenced.
8018 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008019 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008020 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008021 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008022 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008023
Sebastian Redl6047f072012-02-16 12:22:20 +00008024 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008025 QualType ElementType
8026 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8027 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8028 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8029 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008030 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008031 }
8032 }
8033 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008034
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008035 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008036 }
Mike Stump11289f42009-09-09 15:08:12 +00008037
Douglas Gregor0744ef62010-09-07 21:49:58 +00008038 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008039 if (!ArraySize.get()) {
8040 // If no array size was specified, but the new expression was
8041 // instantiated with an array type (e.g., "new T" where T is
8042 // instantiated with "int[4]"), extract the outer bound from the
8043 // array type as our array size. We do this with constant and
8044 // dependently-sized array types.
8045 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8046 if (!ArrayT) {
8047 // Do nothing
8048 } else if (const ConstantArrayType *ConsArrayT
8049 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008050 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8051 SemaRef.Context.getSizeType(),
8052 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008053 AllocType = ConsArrayT->getElementType();
8054 } else if (const DependentSizedArrayType *DepArrayT
8055 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8056 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008057 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008058 AllocType = DepArrayT->getElementType();
8059 }
8060 }
8061 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008062
Douglas Gregora16548e2009-08-11 05:31:07 +00008063 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8064 E->isGlobalNew(),
8065 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008066 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008067 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008068 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008069 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008070 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008071 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008072 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008073 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008074}
Mike Stump11289f42009-09-09 15:08:12 +00008075
Douglas Gregora16548e2009-08-11 05:31:07 +00008076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008078TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008079 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008082
Douglas Gregord2d9da02010-02-26 00:38:10 +00008083 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008084 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008085 if (E->getOperatorDelete()) {
8086 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008087 getDerived().TransformDecl(E->getLocStart(),
8088 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008089 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008090 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008091 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008092
Douglas Gregora16548e2009-08-11 05:31:07 +00008093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008094 Operand.get() == E->getArgument() &&
8095 OperatorDelete == E->getOperatorDelete()) {
8096 // Mark any declarations we need as referenced.
8097 // FIXME: instantiation-specific.
8098 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008099 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008100
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008101 if (!E->getArgument()->isTypeDependent()) {
8102 QualType Destroyed = SemaRef.Context.getBaseElementType(
8103 E->getDestroyedType());
8104 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8105 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008106 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008107 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008108 }
8109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008110
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008111 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008112 }
Mike Stump11289f42009-09-09 15:08:12 +00008113
Douglas Gregora16548e2009-08-11 05:31:07 +00008114 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8115 E->isGlobalDelete(),
8116 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008117 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008118}
Mike Stump11289f42009-09-09 15:08:12 +00008119
Douglas Gregora16548e2009-08-11 05:31:07 +00008120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008121ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008122TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008123 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008124 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008125 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008126 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008127
John McCallba7bf592010-08-24 05:47:05 +00008128 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008129 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008130 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008131 E->getOperatorLoc(),
8132 E->isArrow()? tok::arrow : tok::period,
8133 ObjectTypePtr,
8134 MayBePseudoDestructor);
8135 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008136 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008137
John McCallba7bf592010-08-24 05:47:05 +00008138 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008139 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8140 if (QualifierLoc) {
8141 QualifierLoc
8142 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8143 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008144 return ExprError();
8145 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008146 CXXScopeSpec SS;
8147 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008148
Douglas Gregor678f90d2010-02-25 01:56:36 +00008149 PseudoDestructorTypeStorage Destroyed;
8150 if (E->getDestroyedTypeInfo()) {
8151 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008152 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008153 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008154 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008155 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008156 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008157 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008158 // We aren't likely to be able to resolve the identifier down to a type
8159 // now anyway, so just retain the identifier.
8160 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8161 E->getDestroyedTypeLoc());
8162 } else {
8163 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008164 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008165 *E->getDestroyedTypeIdentifier(),
8166 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008167 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008168 SS, ObjectTypePtr,
8169 false);
8170 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008171 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008172
Douglas Gregor678f90d2010-02-25 01:56:36 +00008173 Destroyed
8174 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8175 E->getDestroyedTypeLoc());
8176 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008177
Craig Topperc3ec1492014-05-26 06:22:03 +00008178 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008179 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008180 CXXScopeSpec EmptySS;
8181 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008182 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008183 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008184 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008186
John McCallb268a282010-08-23 23:25:46 +00008187 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008188 E->getOperatorLoc(),
8189 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008190 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008191 ScopeTypeInfo,
8192 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008193 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008194 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008195}
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregorad8a3362009-09-04 17:36:40 +00008197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008198ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008199TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008200 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008201 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8202 Sema::LookupOrdinaryName);
8203
8204 // Transform all the decls.
8205 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8206 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008207 NamedDecl *InstD = static_cast<NamedDecl*>(
8208 getDerived().TransformDecl(Old->getNameLoc(),
8209 *I));
John McCall84d87672009-12-10 09:41:52 +00008210 if (!InstD) {
8211 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8212 // This can happen because of dependent hiding.
8213 if (isa<UsingShadowDecl>(*I))
8214 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008215 else {
8216 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008218 }
John McCall84d87672009-12-10 09:41:52 +00008219 }
John McCalle66edc12009-11-24 19:00:30 +00008220
8221 // Expand using declarations.
8222 if (isa<UsingDecl>(InstD)) {
8223 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008224 for (auto *I : UD->shadows())
8225 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008226 continue;
8227 }
8228
8229 R.addDecl(InstD);
8230 }
8231
8232 // Resolve a kind, but don't do any further analysis. If it's
8233 // ambiguous, the callee needs to deal with it.
8234 R.resolveKind();
8235
8236 // Rebuild the nested-name qualifier, if present.
8237 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008238 if (Old->getQualifierLoc()) {
8239 NestedNameSpecifierLoc QualifierLoc
8240 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8241 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008242 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008243
Douglas Gregor0da1d432011-02-28 20:01:57 +00008244 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008245 }
8246
Douglas Gregor9262f472010-04-27 18:19:34 +00008247 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008248 CXXRecordDecl *NamingClass
8249 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8250 Old->getNameLoc(),
8251 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008252 if (!NamingClass) {
8253 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008254 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008256
Douglas Gregorda7be082010-04-27 16:10:10 +00008257 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008258 }
8259
Abramo Bagnara7945c982012-01-27 09:46:47 +00008260 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8261
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008262 // If we have neither explicit template arguments, nor the template keyword,
8263 // it's a normal declaration name.
8264 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008265 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8266
8267 // If we have template arguments, rebuild them, then rebuild the
8268 // templateid expression.
8269 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008270 if (Old->hasExplicitTemplateArgs() &&
8271 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008272 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008273 TransArgs)) {
8274 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008275 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008276 }
John McCalle66edc12009-11-24 19:00:30 +00008277
Abramo Bagnara7945c982012-01-27 09:46:47 +00008278 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008279 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008280}
Mike Stump11289f42009-09-09 15:08:12 +00008281
Douglas Gregora16548e2009-08-11 05:31:07 +00008282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008283ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008284TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8285 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008286 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008287 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8288 TypeSourceInfo *From = E->getArg(I);
8289 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008290 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008291 TypeLocBuilder TLB;
8292 TLB.reserve(FromTL.getFullDataSize());
8293 QualType To = getDerived().TransformType(TLB, FromTL);
8294 if (To.isNull())
8295 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008296
Douglas Gregor29c42f22012-02-24 07:38:34 +00008297 if (To == From->getType())
8298 Args.push_back(From);
8299 else {
8300 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8301 ArgChanged = true;
8302 }
8303 continue;
8304 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008305
Douglas Gregor29c42f22012-02-24 07:38:34 +00008306 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008307
Douglas Gregor29c42f22012-02-24 07:38:34 +00008308 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008309 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008310 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8311 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8312 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008313
Douglas Gregor29c42f22012-02-24 07:38:34 +00008314 // Determine whether the set of unexpanded parameter packs can and should
8315 // be expanded.
8316 bool Expand = true;
8317 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008318 Optional<unsigned> OrigNumExpansions =
8319 ExpansionTL.getTypePtr()->getNumExpansions();
8320 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008321 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8322 PatternTL.getSourceRange(),
8323 Unexpanded,
8324 Expand, RetainExpansion,
8325 NumExpansions))
8326 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008327
Douglas Gregor29c42f22012-02-24 07:38:34 +00008328 if (!Expand) {
8329 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008330 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008331 // expansion.
8332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008333
Douglas Gregor29c42f22012-02-24 07:38:34 +00008334 TypeLocBuilder TLB;
8335 TLB.reserve(From->getTypeLoc().getFullDataSize());
8336
8337 QualType To = getDerived().TransformType(TLB, PatternTL);
8338 if (To.isNull())
8339 return ExprError();
8340
Chad Rosier1dcde962012-08-08 18:46:20 +00008341 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008342 PatternTL.getSourceRange(),
8343 ExpansionTL.getEllipsisLoc(),
8344 NumExpansions);
8345 if (To.isNull())
8346 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008347
Douglas Gregor29c42f22012-02-24 07:38:34 +00008348 PackExpansionTypeLoc ToExpansionTL
8349 = TLB.push<PackExpansionTypeLoc>(To);
8350 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8351 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8352 continue;
8353 }
8354
8355 // Expand the pack expansion by substituting for each argument in the
8356 // pack(s).
8357 for (unsigned I = 0; I != *NumExpansions; ++I) {
8358 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8359 TypeLocBuilder TLB;
8360 TLB.reserve(PatternTL.getFullDataSize());
8361 QualType To = getDerived().TransformType(TLB, PatternTL);
8362 if (To.isNull())
8363 return ExprError();
8364
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008365 if (To->containsUnexpandedParameterPack()) {
8366 To = getDerived().RebuildPackExpansionType(To,
8367 PatternTL.getSourceRange(),
8368 ExpansionTL.getEllipsisLoc(),
8369 NumExpansions);
8370 if (To.isNull())
8371 return ExprError();
8372
8373 PackExpansionTypeLoc ToExpansionTL
8374 = TLB.push<PackExpansionTypeLoc>(To);
8375 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8376 }
8377
Douglas Gregor29c42f22012-02-24 07:38:34 +00008378 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8379 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008380
Douglas Gregor29c42f22012-02-24 07:38:34 +00008381 if (!RetainExpansion)
8382 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008383
Douglas Gregor29c42f22012-02-24 07:38:34 +00008384 // If we're supposed to retain a pack expansion, do so by temporarily
8385 // forgetting the partially-substituted parameter pack.
8386 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8387
8388 TypeLocBuilder TLB;
8389 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008390
Douglas Gregor29c42f22012-02-24 07:38:34 +00008391 QualType To = getDerived().TransformType(TLB, PatternTL);
8392 if (To.isNull())
8393 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008394
8395 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008396 PatternTL.getSourceRange(),
8397 ExpansionTL.getEllipsisLoc(),
8398 NumExpansions);
8399 if (To.isNull())
8400 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008401
Douglas Gregor29c42f22012-02-24 07:38:34 +00008402 PackExpansionTypeLoc ToExpansionTL
8403 = TLB.push<PackExpansionTypeLoc>(To);
8404 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8405 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008407
Douglas Gregor29c42f22012-02-24 07:38:34 +00008408 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008409 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008410
8411 return getDerived().RebuildTypeTrait(E->getTrait(),
8412 E->getLocStart(),
8413 Args,
8414 E->getLocEnd());
8415}
8416
8417template<typename Derived>
8418ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008419TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8420 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8421 if (!T)
8422 return ExprError();
8423
8424 if (!getDerived().AlwaysRebuild() &&
8425 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008426 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008427
8428 ExprResult SubExpr;
8429 {
8430 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8431 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8432 if (SubExpr.isInvalid())
8433 return ExprError();
8434
8435 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008436 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008437 }
8438
8439 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8440 E->getLocStart(),
8441 T,
8442 SubExpr.get(),
8443 E->getLocEnd());
8444}
8445
8446template<typename Derived>
8447ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008448TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8449 ExprResult SubExpr;
8450 {
8451 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8452 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8453 if (SubExpr.isInvalid())
8454 return ExprError();
8455
8456 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008457 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008458 }
8459
8460 return getDerived().RebuildExpressionTrait(
8461 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8462}
8463
Reid Kleckner32506ed2014-06-12 23:03:48 +00008464template <typename Derived>
8465ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8466 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8467 TypeSourceInfo **RecoveryTSI) {
8468 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8469 DRE, AddrTaken, RecoveryTSI);
8470
8471 // Propagate both errors and recovered types, which return ExprEmpty.
8472 if (!NewDRE.isUsable())
8473 return NewDRE;
8474
8475 // We got an expr, wrap it up in parens.
8476 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8477 return PE;
8478 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8479 PE->getRParen());
8480}
8481
8482template <typename Derived>
8483ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8484 DependentScopeDeclRefExpr *E) {
8485 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8486 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008487}
8488
8489template<typename Derived>
8490ExprResult
8491TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8492 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008493 bool IsAddressOfOperand,
8494 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008495 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008496 NestedNameSpecifierLoc QualifierLoc
8497 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8498 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008499 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008500 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008501
John McCall31f82722010-11-12 08:19:04 +00008502 // TODO: If this is a conversion-function-id, verify that the
8503 // destination type name (if present) resolves the same way after
8504 // instantiation as it did in the local scope.
8505
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008506 DeclarationNameInfo NameInfo
8507 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8508 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008510
John McCalle66edc12009-11-24 19:00:30 +00008511 if (!E->hasExplicitTemplateArgs()) {
8512 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008513 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008514 // Note: it is sufficient to compare the Name component of NameInfo:
8515 // if name has not changed, DNLoc has not changed either.
8516 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008517 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008518
Reid Kleckner32506ed2014-06-12 23:03:48 +00008519 return getDerived().RebuildDependentScopeDeclRefExpr(
8520 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8521 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008522 }
John McCall6b51f282009-11-23 01:53:49 +00008523
8524 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008525 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8526 E->getNumTemplateArgs(),
8527 TransArgs))
8528 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008529
Reid Kleckner32506ed2014-06-12 23:03:48 +00008530 return getDerived().RebuildDependentScopeDeclRefExpr(
8531 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8532 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008533}
8534
8535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008537TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008538 // CXXConstructExprs other than for list-initialization and
8539 // CXXTemporaryObjectExpr are always implicit, so when we have
8540 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008541 if ((E->getNumArgs() == 1 ||
8542 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008543 (!getDerived().DropCallArgument(E->getArg(0))) &&
8544 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008545 return getDerived().TransformExpr(E->getArg(0));
8546
Douglas Gregora16548e2009-08-11 05:31:07 +00008547 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8548
8549 QualType T = getDerived().TransformType(E->getType());
8550 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008551 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008552
8553 CXXConstructorDecl *Constructor
8554 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008555 getDerived().TransformDecl(E->getLocStart(),
8556 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008557 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008559
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008561 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008562 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008563 &ArgumentChanged))
8564 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008565
Douglas Gregora16548e2009-08-11 05:31:07 +00008566 if (!getDerived().AlwaysRebuild() &&
8567 T == E->getType() &&
8568 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008569 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008570 // Mark the constructor as referenced.
8571 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008572 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008573 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008574 }
Mike Stump11289f42009-09-09 15:08:12 +00008575
Douglas Gregordb121ba2009-12-14 16:27:04 +00008576 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8577 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008578 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008579 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008580 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008581 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008582 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008583 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008584 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008585}
Mike Stump11289f42009-09-09 15:08:12 +00008586
Douglas Gregora16548e2009-08-11 05:31:07 +00008587/// \brief Transform a C++ temporary-binding expression.
8588///
Douglas Gregor363b1512009-12-24 18:51:59 +00008589/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8590/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008593TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008594 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008595}
Mike Stump11289f42009-09-09 15:08:12 +00008596
John McCall5d413782010-12-06 08:20:24 +00008597/// \brief Transform a C++ expression that contains cleanups that should
8598/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008599///
John McCall5d413782010-12-06 08:20:24 +00008600/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008601/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008603ExprResult
John McCall5d413782010-12-06 08:20:24 +00008604TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008605 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008606}
Mike Stump11289f42009-09-09 15:08:12 +00008607
Douglas Gregora16548e2009-08-11 05:31:07 +00008608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008609ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008610TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008611 CXXTemporaryObjectExpr *E) {
8612 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8613 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008615
Douglas Gregora16548e2009-08-11 05:31:07 +00008616 CXXConstructorDecl *Constructor
8617 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008618 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008619 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008620 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008622
Douglas Gregora16548e2009-08-11 05:31:07 +00008623 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008624 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008625 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008626 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008627 &ArgumentChanged))
8628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008629
Douglas Gregora16548e2009-08-11 05:31:07 +00008630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008631 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008633 !ArgumentChanged) {
8634 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008635 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008636 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008638
Richard Smithd59b8322012-12-19 01:39:02 +00008639 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008640 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8641 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008642 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008643 E->getLocEnd());
8644}
Mike Stump11289f42009-09-09 15:08:12 +00008645
Douglas Gregora16548e2009-08-11 05:31:07 +00008646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008647ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008648TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008649
8650 // Transform any init-capture expressions before entering the scope of the
8651 // lambda body, because they are not semantically within that scope.
8652 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8653 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8654 E->explicit_capture_begin());
8655
8656 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8657 CEnd = E->capture_end();
8658 C != CEnd; ++C) {
8659 if (!C->isInitCapture())
8660 continue;
8661 EnterExpressionEvaluationContext EEEC(getSema(),
8662 Sema::PotentiallyEvaluated);
8663 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8664 C->getCapturedVar()->getInit(),
8665 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8666
8667 if (NewExprInitResult.isInvalid())
8668 return ExprError();
8669 Expr *NewExprInit = NewExprInitResult.get();
8670
8671 VarDecl *OldVD = C->getCapturedVar();
8672 QualType NewInitCaptureType =
8673 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8674 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8675 NewExprInit);
8676 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008677 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8678 std::make_pair(NewExprInitResult, NewInitCaptureType);
8679
8680 }
8681
Faisal Vali524ca282013-11-12 01:40:44 +00008682 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008683 // Transform the template parameters, and add them to the current
8684 // instantiation scope. The null case is handled correctly.
8685 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8686 E->getTemplateParameterList());
8687
8688 // Check to see if the TypeSourceInfo of the call operator needs to
8689 // be transformed, and if so do the transformation in the
8690 // CurrentInstantiationScope.
8691
8692 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8693 FunctionProtoTypeLoc OldCallOpFPTL =
8694 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008695 TypeSourceInfo *NewCallOpTSI = nullptr;
8696
Faisal Vali2cba1332013-10-23 06:44:28 +00008697 const bool CallOpWasAlreadyTransformed =
8698 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8699
8700 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8701 if (CallOpWasAlreadyTransformed)
8702 NewCallOpTSI = OldCallOpTSI;
8703 else {
8704 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8705 // The transformation MUST be done in the CurrentInstantiationScope since
8706 // it introduces a mapping of the original to the newly created
8707 // transformed parameters.
8708
8709 TypeLocBuilder NewCallOpTLBuilder;
8710 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8711 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008712 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008713 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8714 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008715 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008716 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8717 // the vector below - this will be used to synthesize the
8718 // NewCallOperator. Additionally, add the parameters of the untransformed
8719 // lambda call operator to the CurrentInstantiationScope.
8720 SmallVector<ParmVarDecl *, 4> Params;
8721 {
8722 FunctionProtoTypeLoc NewCallOpFPTL =
8723 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8724 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008725 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008726
8727 for (unsigned I = 0; I < NewNumArgs; ++I) {
8728 // If this call operator's type does not require transformation,
8729 // the parameters do not get added to the current instantiation scope,
8730 // - so ADD them! This allows the following to compile when the enclosing
8731 // template is specialized and the entire lambda expression has to be
8732 // transformed.
8733 // template<class T> void foo(T t) {
8734 // auto L = [](auto a) {
8735 // auto M = [](char b) { <-- note: non-generic lambda
8736 // auto N = [](auto c) {
8737 // int x = sizeof(a);
8738 // x = sizeof(b); <-- specifically this line
8739 // x = sizeof(c);
8740 // };
8741 // };
8742 // };
8743 // }
8744 // foo('a')
8745 if (CallOpWasAlreadyTransformed)
8746 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8747 NewParamDeclArray[I]);
8748 // Add to Params array, so these parameters can be used to create
8749 // the newly transformed call operator.
8750 Params.push_back(NewParamDeclArray[I]);
8751 }
8752 }
8753
8754 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008755 return ExprError();
8756
Eli Friedmand564afb2012-09-19 01:18:11 +00008757 // Create the local class that will describe the lambda.
8758 CXXRecordDecl *Class
8759 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008760 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008761 /*KnownDependent=*/false,
8762 E->getCaptureDefault());
8763
Eli Friedmand564afb2012-09-19 01:18:11 +00008764 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8765
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008766 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008767 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008768 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008769 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008770 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008771 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008772 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008773
Faisal Vali2cba1332013-10-23 06:44:28 +00008774 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8775
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008776 return getDerived().TransformLambdaScope(E, NewCallOperator,
8777 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008778}
8779
8780template<typename Derived>
8781ExprResult
8782TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008783 CXXMethodDecl *CallOperator,
8784 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008785 bool Invalid = false;
8786
Douglas Gregorb4328232012-02-14 00:00:48 +00008787 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008788 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8789 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008790
Faisal Vali2b391ab2013-09-26 19:54:12 +00008791 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008792 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008793 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008794 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008795 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008796 E->hasExplicitParameters(),
8797 E->hasExplicitResultType(),
8798 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008799
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008800 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008801 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008802 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008803 CEnd = E->capture_end();
8804 C != CEnd; ++C) {
8805 // When we hit the first implicit capture, tell Sema that we've finished
8806 // the list of explicit captures.
8807 if (!FinishedExplicitCaptures && C->isImplicit()) {
8808 getSema().finishLambdaExplicitCaptures(LSI);
8809 FinishedExplicitCaptures = true;
8810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008811
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008812 // Capturing 'this' is trivial.
8813 if (C->capturesThis()) {
8814 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8815 continue;
8816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008817
Richard Smithba71c082013-05-16 06:20:58 +00008818 // Rebuild init-captures, including the implied field declaration.
8819 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008820
8821 InitCaptureInfoTy InitExprTypePair =
8822 InitCaptureExprsAndTypes[C - E->capture_begin()];
8823 ExprResult Init = InitExprTypePair.first;
8824 QualType InitQualType = InitExprTypePair.second;
8825 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008826 Invalid = true;
8827 continue;
8828 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008829 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008830 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8831 OldVD->getLocation(), InitExprTypePair.second,
8832 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008833 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008834 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008835 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008836 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008837 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008838 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008839 continue;
8840 }
8841
8842 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8843
Douglas Gregor3e308b12012-02-14 19:27:52 +00008844 // Determine the capture kind for Sema.
8845 Sema::TryCaptureKind Kind
8846 = C->isImplicit()? Sema::TryCapture_Implicit
8847 : C->getCaptureKind() == LCK_ByCopy
8848 ? Sema::TryCapture_ExplicitByVal
8849 : Sema::TryCapture_ExplicitByRef;
8850 SourceLocation EllipsisLoc;
8851 if (C->isPackExpansion()) {
8852 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8853 bool ShouldExpand = false;
8854 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008855 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008856 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8857 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008858 Unexpanded,
8859 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008860 NumExpansions)) {
8861 Invalid = true;
8862 continue;
8863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008864
Douglas Gregor3e308b12012-02-14 19:27:52 +00008865 if (ShouldExpand) {
8866 // The transform has determined that we should perform an expansion;
8867 // transform and capture each of the arguments.
8868 // expansion of the pattern. Do so.
8869 VarDecl *Pack = C->getCapturedVar();
8870 for (unsigned I = 0; I != *NumExpansions; ++I) {
8871 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8872 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008873 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008874 Pack));
8875 if (!CapturedVar) {
8876 Invalid = true;
8877 continue;
8878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008879
Douglas Gregor3e308b12012-02-14 19:27:52 +00008880 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008881 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8882 }
Richard Smith9467be42014-06-06 17:33:35 +00008883
8884 // FIXME: Retain a pack expansion if RetainExpansion is true.
8885
Douglas Gregor3e308b12012-02-14 19:27:52 +00008886 continue;
8887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008888
Douglas Gregor3e308b12012-02-14 19:27:52 +00008889 EllipsisLoc = C->getEllipsisLoc();
8890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008891
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008892 // Transform the captured variable.
8893 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008894 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008895 C->getCapturedVar()));
8896 if (!CapturedVar) {
8897 Invalid = true;
8898 continue;
8899 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008900
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008901 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008902 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008903 }
8904 if (!FinishedExplicitCaptures)
8905 getSema().finishLambdaExplicitCaptures(LSI);
8906
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008907
8908 // Enter a new evaluation context to insulate the lambda from any
8909 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008910 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008911
8912 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008913 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008914 /*IsInstantiation=*/true);
8915 return ExprError();
8916 }
8917
8918 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008919 StmtResult Body = getDerived().TransformStmt(E->getBody());
8920 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008921 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008922 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008923 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008924 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008925
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008926 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008927 /*CurScope=*/nullptr,
8928 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008929}
8930
8931template<typename Derived>
8932ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008933TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008934 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008935 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8936 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008938
Douglas Gregora16548e2009-08-11 05:31:07 +00008939 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008940 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008941 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008942 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008943 &ArgumentChanged))
8944 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008945
Douglas Gregora16548e2009-08-11 05:31:07 +00008946 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008947 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008948 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008949 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008950
Douglas Gregora16548e2009-08-11 05:31:07 +00008951 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008952 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008953 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008954 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008955 E->getRParenLoc());
8956}
Mike Stump11289f42009-09-09 15:08:12 +00008957
Douglas Gregora16548e2009-08-11 05:31:07 +00008958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008959ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008960TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008961 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008962 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008963 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008964 Expr *OldBase;
8965 QualType BaseType;
8966 QualType ObjectType;
8967 if (!E->isImplicitAccess()) {
8968 OldBase = E->getBase();
8969 Base = getDerived().TransformExpr(OldBase);
8970 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008972
John McCall2d74de92009-12-01 22:10:20 +00008973 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008974 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008975 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008976 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008977 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008978 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008979 ObjectTy,
8980 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008981 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008982 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008983
John McCallba7bf592010-08-24 05:47:05 +00008984 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008985 BaseType = ((Expr*) Base.get())->getType();
8986 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008987 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008988 BaseType = getDerived().TransformType(E->getBaseType());
8989 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8990 }
Mike Stump11289f42009-09-09 15:08:12 +00008991
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008992 // Transform the first part of the nested-name-specifier that qualifies
8993 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008994 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008995 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008996 E->getFirstQualifierFoundInScope(),
8997 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008998
Douglas Gregore16af532011-02-28 18:50:33 +00008999 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009000 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009001 QualifierLoc
9002 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9003 ObjectType,
9004 FirstQualifierInScope);
9005 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009006 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009007 }
Mike Stump11289f42009-09-09 15:08:12 +00009008
Abramo Bagnara7945c982012-01-27 09:46:47 +00009009 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9010
John McCall31f82722010-11-12 08:19:04 +00009011 // TODO: If this is a conversion-function-id, verify that the
9012 // destination type name (if present) resolves the same way after
9013 // instantiation as it did in the local scope.
9014
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009015 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009016 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009017 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009019
John McCall2d74de92009-12-01 22:10:20 +00009020 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009021 // This is a reference to a member without an explicitly-specified
9022 // template argument list. Optimize for this common case.
9023 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009024 Base.get() == OldBase &&
9025 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009026 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009027 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009028 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009029 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009030
John McCallb268a282010-08-23 23:25:46 +00009031 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009032 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009033 E->isArrow(),
9034 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009035 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009036 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009037 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009038 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009039 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009040 }
9041
John McCall6b51f282009-11-23 01:53:49 +00009042 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009043 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9044 E->getNumTemplateArgs(),
9045 TransArgs))
9046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009047
John McCallb268a282010-08-23 23:25:46 +00009048 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009049 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009050 E->isArrow(),
9051 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009052 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009053 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009054 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009055 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009056 &TransArgs);
9057}
9058
9059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009060ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009061TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009062 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009063 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009064 QualType BaseType;
9065 if (!Old->isImplicitAccess()) {
9066 Base = getDerived().TransformExpr(Old->getBase());
9067 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009068 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009069 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009070 Old->isArrow());
9071 if (Base.isInvalid())
9072 return ExprError();
9073 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009074 } else {
9075 BaseType = getDerived().TransformType(Old->getBaseType());
9076 }
John McCall10eae182009-11-30 22:42:35 +00009077
Douglas Gregor0da1d432011-02-28 20:01:57 +00009078 NestedNameSpecifierLoc QualifierLoc;
9079 if (Old->getQualifierLoc()) {
9080 QualifierLoc
9081 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9082 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009083 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009084 }
9085
Abramo Bagnara7945c982012-01-27 09:46:47 +00009086 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9087
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009088 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009089 Sema::LookupOrdinaryName);
9090
9091 // Transform all the decls.
9092 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9093 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009094 NamedDecl *InstD = static_cast<NamedDecl*>(
9095 getDerived().TransformDecl(Old->getMemberLoc(),
9096 *I));
John McCall84d87672009-12-10 09:41:52 +00009097 if (!InstD) {
9098 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9099 // This can happen because of dependent hiding.
9100 if (isa<UsingShadowDecl>(*I))
9101 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009102 else {
9103 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009104 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009105 }
John McCall84d87672009-12-10 09:41:52 +00009106 }
John McCall10eae182009-11-30 22:42:35 +00009107
9108 // Expand using declarations.
9109 if (isa<UsingDecl>(InstD)) {
9110 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009111 for (auto *I : UD->shadows())
9112 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009113 continue;
9114 }
9115
9116 R.addDecl(InstD);
9117 }
9118
9119 R.resolveKind();
9120
Douglas Gregor9262f472010-04-27 18:19:34 +00009121 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009122 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009123 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009124 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009125 Old->getMemberLoc(),
9126 Old->getNamingClass()));
9127 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009128 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009129
Douglas Gregorda7be082010-04-27 16:10:10 +00009130 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009131 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009132
John McCall10eae182009-11-30 22:42:35 +00009133 TemplateArgumentListInfo TransArgs;
9134 if (Old->hasExplicitTemplateArgs()) {
9135 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9136 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009137 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9138 Old->getNumTemplateArgs(),
9139 TransArgs))
9140 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009141 }
John McCall38836f02010-01-15 08:34:02 +00009142
9143 // FIXME: to do this check properly, we will need to preserve the
9144 // first-qualifier-in-scope here, just in case we had a dependent
9145 // base (and therefore couldn't do the check) and a
9146 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009147 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009148
John McCallb268a282010-08-23 23:25:46 +00009149 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009150 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009151 Old->getOperatorLoc(),
9152 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009153 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009154 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009155 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009156 R,
9157 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009158 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009159}
9160
9161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009162ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009163TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009164 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009165 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9166 if (SubExpr.isInvalid())
9167 return ExprError();
9168
9169 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009170 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009171
9172 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9173}
9174
9175template<typename Derived>
9176ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009177TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009178 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9179 if (Pattern.isInvalid())
9180 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009181
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009182 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009183 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009184
Douglas Gregorb8840002011-01-14 21:20:45 +00009185 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9186 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009187}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009188
9189template<typename Derived>
9190ExprResult
9191TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9192 // If E is not value-dependent, then nothing will change when we transform it.
9193 // Note: This is an instantiation-centric view.
9194 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009195 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009196
9197 // Note: None of the implementations of TryExpandParameterPacks can ever
9198 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009199 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009200 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9201 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009202 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009203 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009204 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009205 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009206 ShouldExpand, RetainExpansion,
9207 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009208 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009209
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009210 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009211 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009212
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009213 NamedDecl *Pack = E->getPack();
9214 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009215 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009216 Pack));
9217 if (!Pack)
9218 return ExprError();
9219 }
9220
Chad Rosier1dcde962012-08-08 18:46:20 +00009221
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009222 // We now know the length of the parameter pack, so build a new expression
9223 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009224 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9225 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009226 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009227}
9228
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009229template<typename Derived>
9230ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009231TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9232 SubstNonTypeTemplateParmPackExpr *E) {
9233 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009234 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009235}
9236
9237template<typename Derived>
9238ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009239TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9240 SubstNonTypeTemplateParmExpr *E) {
9241 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009242 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009243}
9244
9245template<typename Derived>
9246ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009247TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9248 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009249 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009250}
9251
9252template<typename Derived>
9253ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009254TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9255 MaterializeTemporaryExpr *E) {
9256 return getDerived().TransformExpr(E->GetTemporaryExpr());
9257}
Chad Rosier1dcde962012-08-08 18:46:20 +00009258
Douglas Gregorfe314812011-06-21 17:03:29 +00009259template<typename Derived>
9260ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009261TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9262 CXXStdInitializerListExpr *E) {
9263 return getDerived().TransformExpr(E->getSubExpr());
9264}
9265
9266template<typename Derived>
9267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009268TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009269 return SemaRef.MaybeBindToTemporary(E);
9270}
9271
9272template<typename Derived>
9273ExprResult
9274TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009275 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009276}
9277
9278template<typename Derived>
9279ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009280TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9281 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9282 if (SubExpr.isInvalid())
9283 return ExprError();
9284
9285 if (!getDerived().AlwaysRebuild() &&
9286 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009287 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009288
9289 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009290}
9291
9292template<typename Derived>
9293ExprResult
9294TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9295 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009296 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009297 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009298 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009299 /*IsCall=*/false, Elements, &ArgChanged))
9300 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009301
Ted Kremeneke65b0862012-03-06 20:05:56 +00009302 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9303 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009304
Ted Kremeneke65b0862012-03-06 20:05:56 +00009305 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9306 Elements.data(),
9307 Elements.size());
9308}
9309
9310template<typename Derived>
9311ExprResult
9312TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009313 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009314 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009315 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009316 bool ArgChanged = false;
9317 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9318 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009319
Ted Kremeneke65b0862012-03-06 20:05:56 +00009320 if (OrigElement.isPackExpansion()) {
9321 // This key/value element is a pack expansion.
9322 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9323 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9324 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9325 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9326
9327 // Determine whether the set of unexpanded parameter packs can
9328 // and should be expanded.
9329 bool Expand = true;
9330 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009331 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9332 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009333 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9334 OrigElement.Value->getLocEnd());
9335 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9336 PatternRange,
9337 Unexpanded,
9338 Expand, RetainExpansion,
9339 NumExpansions))
9340 return ExprError();
9341
9342 if (!Expand) {
9343 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009344 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009345 // expansion.
9346 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9347 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9348 if (Key.isInvalid())
9349 return ExprError();
9350
9351 if (Key.get() != OrigElement.Key)
9352 ArgChanged = true;
9353
9354 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9355 if (Value.isInvalid())
9356 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009357
Ted Kremeneke65b0862012-03-06 20:05:56 +00009358 if (Value.get() != OrigElement.Value)
9359 ArgChanged = true;
9360
Chad Rosier1dcde962012-08-08 18:46:20 +00009361 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009362 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9363 };
9364 Elements.push_back(Expansion);
9365 continue;
9366 }
9367
9368 // Record right away that the argument was changed. This needs
9369 // to happen even if the array expands to nothing.
9370 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009371
Ted Kremeneke65b0862012-03-06 20:05:56 +00009372 // The transform has determined that we should perform an elementwise
9373 // expansion of the pattern. Do so.
9374 for (unsigned I = 0; I != *NumExpansions; ++I) {
9375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9376 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9377 if (Key.isInvalid())
9378 return ExprError();
9379
9380 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9381 if (Value.isInvalid())
9382 return ExprError();
9383
Chad Rosier1dcde962012-08-08 18:46:20 +00009384 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009385 Key.get(), Value.get(), SourceLocation(), NumExpansions
9386 };
9387
9388 // If any unexpanded parameter packs remain, we still have a
9389 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009390 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009391 if (Key.get()->containsUnexpandedParameterPack() ||
9392 Value.get()->containsUnexpandedParameterPack())
9393 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009394
Ted Kremeneke65b0862012-03-06 20:05:56 +00009395 Elements.push_back(Element);
9396 }
9397
Richard Smith9467be42014-06-06 17:33:35 +00009398 // FIXME: Retain a pack expansion if RetainExpansion is true.
9399
Ted Kremeneke65b0862012-03-06 20:05:56 +00009400 // We've finished with this pack expansion.
9401 continue;
9402 }
9403
9404 // Transform and check key.
9405 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9406 if (Key.isInvalid())
9407 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009408
Ted Kremeneke65b0862012-03-06 20:05:56 +00009409 if (Key.get() != OrigElement.Key)
9410 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009411
Ted Kremeneke65b0862012-03-06 20:05:56 +00009412 // Transform and check value.
9413 ExprResult Value
9414 = getDerived().TransformExpr(OrigElement.Value);
9415 if (Value.isInvalid())
9416 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009417
Ted Kremeneke65b0862012-03-06 20:05:56 +00009418 if (Value.get() != OrigElement.Value)
9419 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009420
9421 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009422 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009423 };
9424 Elements.push_back(Element);
9425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009426
Ted Kremeneke65b0862012-03-06 20:05:56 +00009427 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9428 return SemaRef.MaybeBindToTemporary(E);
9429
9430 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9431 Elements.data(),
9432 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009433}
9434
Mike Stump11289f42009-09-09 15:08:12 +00009435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009437TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009438 TypeSourceInfo *EncodedTypeInfo
9439 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9440 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009441 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009442
Douglas Gregora16548e2009-08-11 05:31:07 +00009443 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009444 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009445 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009446
9447 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009448 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009449 E->getRParenLoc());
9450}
Mike Stump11289f42009-09-09 15:08:12 +00009451
Douglas Gregora16548e2009-08-11 05:31:07 +00009452template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009453ExprResult TreeTransform<Derived>::
9454TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009455 // This is a kind of implicit conversion, and it needs to get dropped
9456 // and recomputed for the same general reasons that ImplicitCastExprs
9457 // do, as well a more specific one: this expression is only valid when
9458 // it appears *immediately* as an argument expression.
9459 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009460}
9461
9462template<typename Derived>
9463ExprResult TreeTransform<Derived>::
9464TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009465 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009466 = getDerived().TransformType(E->getTypeInfoAsWritten());
9467 if (!TSInfo)
9468 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009469
John McCall31168b02011-06-15 23:02:42 +00009470 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009471 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009472 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009473
John McCall31168b02011-06-15 23:02:42 +00009474 if (!getDerived().AlwaysRebuild() &&
9475 TSInfo == E->getTypeInfoAsWritten() &&
9476 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009477 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009478
John McCall31168b02011-06-15 23:02:42 +00009479 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009480 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009481 Result.get());
9482}
9483
9484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009486TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009487 // Transform arguments.
9488 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009489 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009490 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009491 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009492 &ArgChanged))
9493 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009494
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009495 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9496 // Class message: transform the receiver type.
9497 TypeSourceInfo *ReceiverTypeInfo
9498 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9499 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009500 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009501
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009502 // If nothing changed, just retain the existing message send.
9503 if (!getDerived().AlwaysRebuild() &&
9504 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009505 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009506
9507 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009508 SmallVector<SourceLocation, 16> SelLocs;
9509 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009510 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9511 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009512 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009513 E->getMethodDecl(),
9514 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009515 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009516 E->getRightLoc());
9517 }
9518
9519 // Instance message: transform the receiver
9520 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9521 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009522 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009523 = getDerived().TransformExpr(E->getInstanceReceiver());
9524 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009525 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009526
9527 // If nothing changed, just retain the existing message send.
9528 if (!getDerived().AlwaysRebuild() &&
9529 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009530 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009531
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009532 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009533 SmallVector<SourceLocation, 16> SelLocs;
9534 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009535 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009536 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009537 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009538 E->getMethodDecl(),
9539 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009540 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009541 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009542}
9543
Mike Stump11289f42009-09-09 15:08:12 +00009544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009546TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009547 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009548}
9549
Mike Stump11289f42009-09-09 15:08:12 +00009550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009551ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009552TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009553 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009554}
9555
Mike Stump11289f42009-09-09 15:08:12 +00009556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009558TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009559 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009560 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009561 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009562 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009563
9564 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009565
Douglas Gregord51d90d2010-04-26 20:11:03 +00009566 // If nothing changed, just retain the existing expression.
9567 if (!getDerived().AlwaysRebuild() &&
9568 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009569 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009570
John McCallb268a282010-08-23 23:25:46 +00009571 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009572 E->getLocation(),
9573 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009574}
9575
Mike Stump11289f42009-09-09 15:08:12 +00009576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009578TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009579 // 'super' and types never change. Property never changes. Just
9580 // retain the existing expression.
9581 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009582 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009583
Douglas Gregor9faee212010-04-26 20:47:02 +00009584 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009585 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009586 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009587 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009588
Douglas Gregor9faee212010-04-26 20:47:02 +00009589 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009590
Douglas Gregor9faee212010-04-26 20:47:02 +00009591 // If nothing changed, just retain the existing expression.
9592 if (!getDerived().AlwaysRebuild() &&
9593 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009594 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009595
John McCallb7bd14f2010-12-02 01:19:52 +00009596 if (E->isExplicitProperty())
9597 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9598 E->getExplicitProperty(),
9599 E->getLocation());
9600
9601 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009602 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009603 E->getImplicitPropertyGetter(),
9604 E->getImplicitPropertySetter(),
9605 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009606}
9607
Mike Stump11289f42009-09-09 15:08:12 +00009608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009609ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009610TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9611 // Transform the base expression.
9612 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9613 if (Base.isInvalid())
9614 return ExprError();
9615
9616 // Transform the key expression.
9617 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9618 if (Key.isInvalid())
9619 return ExprError();
9620
9621 // If nothing changed, just retain the existing expression.
9622 if (!getDerived().AlwaysRebuild() &&
9623 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009624 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009625
Chad Rosier1dcde962012-08-08 18:46:20 +00009626 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009627 Base.get(), Key.get(),
9628 E->getAtIndexMethodDecl(),
9629 E->setAtIndexMethodDecl());
9630}
9631
9632template<typename Derived>
9633ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009634TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009635 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009636 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009637 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009638 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009639
Douglas Gregord51d90d2010-04-26 20:11:03 +00009640 // If nothing changed, just retain the existing expression.
9641 if (!getDerived().AlwaysRebuild() &&
9642 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009643 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009644
John McCallb268a282010-08-23 23:25:46 +00009645 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009646 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009647 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009648}
9649
Mike Stump11289f42009-09-09 15:08:12 +00009650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009652TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009653 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009654 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009655 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009656 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009657 SubExprs, &ArgumentChanged))
9658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009659
Douglas Gregora16548e2009-08-11 05:31:07 +00009660 if (!getDerived().AlwaysRebuild() &&
9661 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009662 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009663
Douglas Gregora16548e2009-08-11 05:31:07 +00009664 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009665 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009666 E->getRParenLoc());
9667}
9668
Mike Stump11289f42009-09-09 15:08:12 +00009669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009670ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009671TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9672 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9673 if (SrcExpr.isInvalid())
9674 return ExprError();
9675
9676 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9677 if (!Type)
9678 return ExprError();
9679
9680 if (!getDerived().AlwaysRebuild() &&
9681 Type == E->getTypeSourceInfo() &&
9682 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009683 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009684
9685 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9686 SrcExpr.get(), Type,
9687 E->getRParenLoc());
9688}
9689
9690template<typename Derived>
9691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009692TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009693 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009694
Craig Topperc3ec1492014-05-26 06:22:03 +00009695 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009696 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9697
9698 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009699 blockScope->TheDecl->setBlockMissingReturnType(
9700 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009701
Chris Lattner01cf8db2011-07-20 06:58:45 +00009702 SmallVector<ParmVarDecl*, 4> params;
9703 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009704
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009705 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009706 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9707 oldBlock->param_begin(),
9708 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009709 nullptr, paramTypes, &params)) {
9710 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009711 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009712 }
John McCall490112f2011-02-04 18:33:18 +00009713
Jordan Rosea0a86be2013-03-08 22:25:36 +00009714 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009715 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009716 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009717
Jordan Rose5c382722013-03-08 21:51:21 +00009718 QualType functionType =
9719 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009720 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009721 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009722
9723 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009724 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009725 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009726
9727 if (!oldBlock->blockMissingReturnType()) {
9728 blockScope->HasImplicitReturnType = false;
9729 blockScope->ReturnType = exprResultType;
9730 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009731
John McCall3882ace2011-01-05 12:14:39 +00009732 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009733 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009734 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009735 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009736 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009737 }
John McCall3882ace2011-01-05 12:14:39 +00009738
John McCall490112f2011-02-04 18:33:18 +00009739#ifndef NDEBUG
9740 // In builds with assertions, make sure that we captured everything we
9741 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009742 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009743 for (const auto &I : oldBlock->captures()) {
9744 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009745
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009746 // Ignore parameter packs.
9747 if (isa<ParmVarDecl>(oldCapture) &&
9748 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9749 continue;
John McCall490112f2011-02-04 18:33:18 +00009750
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009751 VarDecl *newCapture =
9752 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9753 oldCapture));
9754 assert(blockScope->CaptureMap.count(newCapture));
9755 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009756 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009757 }
9758#endif
9759
9760 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009761 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009762}
9763
Mike Stump11289f42009-09-09 15:08:12 +00009764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009765ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009766TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009767 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009768}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009769
9770template<typename Derived>
9771ExprResult
9772TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009773 QualType RetTy = getDerived().TransformType(E->getType());
9774 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009775 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009776 SubExprs.reserve(E->getNumSubExprs());
9777 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9778 SubExprs, &ArgumentChanged))
9779 return ExprError();
9780
9781 if (!getDerived().AlwaysRebuild() &&
9782 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009783 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009784
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009785 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009786 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009787}
Chad Rosier1dcde962012-08-08 18:46:20 +00009788
Douglas Gregora16548e2009-08-11 05:31:07 +00009789//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009790// Type reconstruction
9791//===----------------------------------------------------------------------===//
9792
Mike Stump11289f42009-09-09 15:08:12 +00009793template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009794QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9795 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009796 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009797 getDerived().getBaseEntity());
9798}
9799
Mike Stump11289f42009-09-09 15:08:12 +00009800template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009801QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9802 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009803 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009804 getDerived().getBaseEntity());
9805}
9806
Mike Stump11289f42009-09-09 15:08:12 +00009807template<typename Derived>
9808QualType
John McCall70dd5f62009-10-30 00:06:24 +00009809TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9810 bool WrittenAsLValue,
9811 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009812 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009813 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009814}
9815
9816template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009817QualType
John McCall70dd5f62009-10-30 00:06:24 +00009818TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9819 QualType ClassType,
9820 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009821 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9822 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009823}
9824
9825template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009826QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009827TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9828 ArrayType::ArraySizeModifier SizeMod,
9829 const llvm::APInt *Size,
9830 Expr *SizeExpr,
9831 unsigned IndexTypeQuals,
9832 SourceRange BracketsRange) {
9833 if (SizeExpr || !Size)
9834 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9835 IndexTypeQuals, BracketsRange,
9836 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009837
9838 QualType Types[] = {
9839 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9840 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9841 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009842 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009843 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009844 QualType SizeType;
9845 for (unsigned I = 0; I != NumTypes; ++I)
9846 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9847 SizeType = Types[I];
9848 break;
9849 }
Mike Stump11289f42009-09-09 15:08:12 +00009850
Eli Friedman9562f392012-01-25 23:20:27 +00009851 // Note that we can return a VariableArrayType here in the case where
9852 // the element type was a dependent VariableArrayType.
9853 IntegerLiteral *ArraySize
9854 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9855 /*FIXME*/BracketsRange.getBegin());
9856 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009857 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009858 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009859}
Mike Stump11289f42009-09-09 15:08:12 +00009860
Douglas Gregord6ff3322009-08-04 16:50:30 +00009861template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009862QualType
9863TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009864 ArrayType::ArraySizeModifier SizeMod,
9865 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009866 unsigned IndexTypeQuals,
9867 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009868 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009869 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009870}
9871
9872template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009873QualType
Mike Stump11289f42009-09-09 15:08:12 +00009874TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009875 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009876 unsigned IndexTypeQuals,
9877 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009878 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009879 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009880}
Mike Stump11289f42009-09-09 15:08:12 +00009881
Douglas Gregord6ff3322009-08-04 16:50:30 +00009882template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009883QualType
9884TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009885 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009886 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009887 unsigned IndexTypeQuals,
9888 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009889 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009890 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009891 IndexTypeQuals, BracketsRange);
9892}
9893
9894template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009895QualType
9896TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009897 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009898 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009899 unsigned IndexTypeQuals,
9900 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009901 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009902 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009903 IndexTypeQuals, BracketsRange);
9904}
9905
9906template<typename Derived>
9907QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009908 unsigned NumElements,
9909 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009910 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009911 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009912}
Mike Stump11289f42009-09-09 15:08:12 +00009913
Douglas Gregord6ff3322009-08-04 16:50:30 +00009914template<typename Derived>
9915QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9916 unsigned NumElements,
9917 SourceLocation AttributeLoc) {
9918 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9919 NumElements, true);
9920 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009921 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9922 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009923 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009924}
Mike Stump11289f42009-09-09 15:08:12 +00009925
Douglas Gregord6ff3322009-08-04 16:50:30 +00009926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009927QualType
9928TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009929 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009930 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009931 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009932}
Mike Stump11289f42009-09-09 15:08:12 +00009933
Douglas Gregord6ff3322009-08-04 16:50:30 +00009934template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009935QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9936 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00009937 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009938 const FunctionProtoType::ExtProtoInfo &EPI) {
9939 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009940 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009941 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009942 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009943}
Mike Stump11289f42009-09-09 15:08:12 +00009944
Douglas Gregord6ff3322009-08-04 16:50:30 +00009945template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009946QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9947 return SemaRef.Context.getFunctionNoProtoType(T);
9948}
9949
9950template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009951QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9952 assert(D && "no decl found");
9953 if (D->isInvalidDecl()) return QualType();
9954
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009955 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009956 TypeDecl *Ty;
9957 if (isa<UsingDecl>(D)) {
9958 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009959 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009960 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9961
9962 // A valid resolved using typename decl points to exactly one type decl.
9963 assert(++Using->shadow_begin() == Using->shadow_end());
9964 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009965
John McCallb96ec562009-12-04 22:46:56 +00009966 } else {
9967 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9968 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9969 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9970 }
9971
9972 return SemaRef.Context.getTypeDeclType(Ty);
9973}
9974
9975template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009976QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9977 SourceLocation Loc) {
9978 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009979}
9980
9981template<typename Derived>
9982QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9983 return SemaRef.Context.getTypeOfType(Underlying);
9984}
9985
9986template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009987QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9988 SourceLocation Loc) {
9989 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009990}
9991
9992template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009993QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9994 UnaryTransformType::UTTKind UKind,
9995 SourceLocation Loc) {
9996 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9997}
9998
9999template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010000QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010001 TemplateName Template,
10002 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010003 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010004 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010005}
Mike Stump11289f42009-09-09 15:08:12 +000010006
Douglas Gregor1135c352009-08-06 05:28:30 +000010007template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010008QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10009 SourceLocation KWLoc) {
10010 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10011}
10012
10013template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010014TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010015TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010016 bool TemplateKW,
10017 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010018 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010019 Template);
10020}
10021
10022template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010023TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010024TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10025 const IdentifierInfo &Name,
10026 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010027 QualType ObjectType,
10028 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010029 UnqualifiedId TemplateName;
10030 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010031 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010032 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010033 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010034 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010035 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010036 /*EnteringContext=*/false,
10037 Template);
John McCall31f82722010-11-12 08:19:04 +000010038 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010039}
Mike Stump11289f42009-09-09 15:08:12 +000010040
Douglas Gregora16548e2009-08-11 05:31:07 +000010041template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010042TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010043TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010044 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010045 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010046 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010047 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010048 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010049 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010050 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010051 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010052 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010053 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010054 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010055 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010056 /*EnteringContext=*/false,
10057 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010058 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010059}
Chad Rosier1dcde962012-08-08 18:46:20 +000010060
Douglas Gregor71395fa2009-11-04 00:56:37 +000010061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010062ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010063TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10064 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010065 Expr *OrigCallee,
10066 Expr *First,
10067 Expr *Second) {
10068 Expr *Callee = OrigCallee->IgnoreParenCasts();
10069 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010070
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010071 if (First->getObjectKind() == OK_ObjCProperty) {
10072 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10073 if (BinaryOperator::isAssignmentOp(Opc))
10074 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10075 First, Second);
10076 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10077 if (Result.isInvalid())
10078 return ExprError();
10079 First = Result.get();
10080 }
10081
10082 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10083 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10084 if (Result.isInvalid())
10085 return ExprError();
10086 Second = Result.get();
10087 }
10088
Douglas Gregora16548e2009-08-11 05:31:07 +000010089 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010090 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010091 if (!First->getType()->isOverloadableType() &&
10092 !Second->getType()->isOverloadableType())
10093 return getSema().CreateBuiltinArraySubscriptExpr(First,
10094 Callee->getLocStart(),
10095 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010096 } else if (Op == OO_Arrow) {
10097 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010098 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10099 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010100 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010101 // The argument is not of overloadable type, so try to create a
10102 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010103 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010104 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010105
John McCallb268a282010-08-23 23:25:46 +000010106 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010107 }
10108 } else {
John McCallb268a282010-08-23 23:25:46 +000010109 if (!First->getType()->isOverloadableType() &&
10110 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010111 // Neither of the arguments is an overloadable type, so try to
10112 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010113 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010114 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010115 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010116 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010118
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010119 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010120 }
10121 }
Mike Stump11289f42009-09-09 15:08:12 +000010122
10123 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010124 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010125 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010126
John McCallb268a282010-08-23 23:25:46 +000010127 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010128 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010129 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010130 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010131 // If we've resolved this to a particular non-member function, just call
10132 // that function. If we resolved it to a member function,
10133 // CreateOverloaded* will find that function for us.
10134 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10135 if (!isa<CXXMethodDecl>(ND))
10136 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010137 }
Mike Stump11289f42009-09-09 15:08:12 +000010138
Douglas Gregora16548e2009-08-11 05:31:07 +000010139 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010140 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010141 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010142
Douglas Gregora16548e2009-08-11 05:31:07 +000010143 // Create the overloaded operator invocation for unary operators.
10144 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010145 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010146 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010147 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010148 }
Mike Stump11289f42009-09-09 15:08:12 +000010149
Douglas Gregore9d62932011-07-15 16:25:15 +000010150 if (Op == OO_Subscript) {
10151 SourceLocation LBrace;
10152 SourceLocation RBrace;
10153
10154 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10155 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10156 LBrace = SourceLocation::getFromRawEncoding(
10157 NameLoc.CXXOperatorName.BeginOpNameLoc);
10158 RBrace = SourceLocation::getFromRawEncoding(
10159 NameLoc.CXXOperatorName.EndOpNameLoc);
10160 } else {
10161 LBrace = Callee->getLocStart();
10162 RBrace = OpLoc;
10163 }
10164
10165 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10166 First, Second);
10167 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010168
Douglas Gregora16548e2009-08-11 05:31:07 +000010169 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010170 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010171 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010172 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10173 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010175
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010176 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010177}
Mike Stump11289f42009-09-09 15:08:12 +000010178
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010179template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010180ExprResult
John McCallb268a282010-08-23 23:25:46 +000010181TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010182 SourceLocation OperatorLoc,
10183 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010184 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010185 TypeSourceInfo *ScopeType,
10186 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010187 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010188 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010189 QualType BaseType = Base->getType();
10190 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010191 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010192 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010193 !BaseType->getAs<PointerType>()->getPointeeType()
10194 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010195 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010196 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010197 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010198 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010199 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010200 /*FIXME?*/true);
10201 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010202
Douglas Gregor678f90d2010-02-25 01:56:36 +000010203 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010204 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10205 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10206 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10207 NameInfo.setNamedTypeInfo(DestroyedType);
10208
Richard Smith8e4a3862012-05-15 06:15:11 +000010209 // The scope type is now known to be a valid nested name specifier
10210 // component. Tack it on to the end of the nested name specifier.
10211 if (ScopeType)
10212 SS.Extend(SemaRef.Context, SourceLocation(),
10213 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010214
Abramo Bagnara7945c982012-01-27 09:46:47 +000010215 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010216 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010217 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010218 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010219 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010220 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010221 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010222}
10223
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010224template<typename Derived>
10225StmtResult
10226TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010227 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010228 CapturedDecl *CD = S->getCapturedDecl();
10229 unsigned NumParams = CD->getNumParams();
10230 unsigned ContextParamPos = CD->getContextParamPosition();
10231 SmallVector<Sema::CapturedParamNameType, 4> Params;
10232 for (unsigned I = 0; I < NumParams; ++I) {
10233 if (I != ContextParamPos) {
10234 Params.push_back(
10235 std::make_pair(
10236 CD->getParam(I)->getName(),
10237 getDerived().TransformType(CD->getParam(I)->getType())));
10238 } else {
10239 Params.push_back(std::make_pair(StringRef(), QualType()));
10240 }
10241 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010242 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010243 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010244 StmtResult Body;
10245 {
10246 Sema::CompoundScopeRAII CompoundScope(getSema());
10247 Body = getDerived().TransformStmt(S->getCapturedStmt());
10248 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010249
10250 if (Body.isInvalid()) {
10251 getSema().ActOnCapturedRegionError();
10252 return StmtError();
10253 }
10254
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010255 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010256}
10257
Douglas Gregord6ff3322009-08-04 16:50:30 +000010258} // end namespace clang
10259
10260#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H