blob: dc0b5c288c5a4251fae4037496e698e462c73447 [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,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002378 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002379 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002380 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002381 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002382 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002383 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002384 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002385
Douglas Gregordb121ba2009-12-14 16:27:04 +00002386 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002387 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002388 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002389 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002390 RequiresZeroInit, ConstructKind,
2391 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 }
2393
2394 /// \brief Build a new object-construction expression.
2395 ///
2396 /// By default, performs semantic analysis to build the new expression.
2397 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002398 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2399 SourceLocation LParenLoc,
2400 MultiExprArg Args,
2401 SourceLocation RParenLoc) {
2402 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002404 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 RParenLoc);
2406 }
2407
2408 /// \brief Build a new object-construction expression.
2409 ///
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002412 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2413 SourceLocation LParenLoc,
2414 MultiExprArg Args,
2415 SourceLocation RParenLoc) {
2416 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002418 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 RParenLoc);
2420 }
Mike Stump11289f42009-09-09 15:08:12 +00002421
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 /// \brief Build a new member reference expression.
2423 ///
2424 /// By default, performs semantic analysis to build the new expression.
2425 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002426 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002427 QualType BaseType,
2428 bool IsArrow,
2429 SourceLocation OperatorLoc,
2430 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002431 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002432 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002433 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002434 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002436 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002437
John McCallb268a282010-08-23 23:25:46 +00002438 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002439 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002440 SS, TemplateKWLoc,
2441 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002442 MemberNameInfo,
2443 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 }
2445
John McCall10eae182009-11-30 22:42:35 +00002446 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002447 ///
2448 /// By default, performs semantic analysis to build the new expression.
2449 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002450 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2451 SourceLocation OperatorLoc,
2452 bool IsArrow,
2453 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002454 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002455 NamedDecl *FirstQualifierInScope,
2456 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002457 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002458 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002459 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002460
John McCallb268a282010-08-23 23:25:46 +00002461 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002462 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002463 SS, TemplateKWLoc,
2464 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002465 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002466 }
Mike Stump11289f42009-09-09 15:08:12 +00002467
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002468 /// \brief Build a new noexcept expression.
2469 ///
2470 /// By default, performs semantic analysis to build the new expression.
2471 /// Subclasses may override this routine to provide different behavior.
2472 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2473 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2474 }
2475
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002476 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002477 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2478 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002479 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002480 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002481 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002482 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2483 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002484 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002485
2486 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2487 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002488 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002489 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002490
Patrick Beard0caa3942012-04-19 00:25:12 +00002491 /// \brief Build a new Objective-C boxed expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
2495 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2496 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002498
Ted Kremeneke65b0862012-03-06 20:05:56 +00002499 /// \brief Build a new Objective-C array literal.
2500 ///
2501 /// By default, performs semantic analysis to build the new expression.
2502 /// Subclasses may override this routine to provide different behavior.
2503 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2504 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002505 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002506 MultiExprArg(Elements, NumElements));
2507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002508
2509 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002510 Expr *Base, Expr *Key,
2511 ObjCMethodDecl *getterMethod,
2512 ObjCMethodDecl *setterMethod) {
2513 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2514 getterMethod, setterMethod);
2515 }
2516
2517 /// \brief Build a new Objective-C dictionary literal.
2518 ///
2519 /// By default, performs semantic analysis to build the new expression.
2520 /// Subclasses may override this routine to provide different behavior.
2521 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2522 ObjCDictionaryElement *Elements,
2523 unsigned NumElements) {
2524 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2525 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002526
James Dennett2a4d13c2012-06-15 07:13:21 +00002527 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002528 ///
2529 /// By default, performs semantic analysis to build the new expression.
2530 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002531 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002532 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002534 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002535 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002536
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002537 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002538 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002539 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002540 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002541 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002542 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002543 MultiExprArg Args,
2544 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002545 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2546 ReceiverTypeInfo->getType(),
2547 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002548 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002549 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002550 }
2551
2552 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002553 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002554 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002555 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002556 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002557 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002558 MultiExprArg Args,
2559 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002560 return SemaRef.BuildInstanceMessage(Receiver,
2561 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002562 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002563 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002564 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002565 }
2566
Douglas Gregord51d90d2010-04-26 20:11:03 +00002567 /// \brief Build a new Objective-C ivar reference expression.
2568 ///
2569 /// By default, performs semantic analysis to build the new expression.
2570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002571 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002572 SourceLocation IvarLoc,
2573 bool IsArrow, bool IsFreeIvar) {
2574 // FIXME: We lose track of the IsFreeIvar bit.
2575 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002576 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2577 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002578 /*FIXME:*/IvarLoc, IsArrow,
2579 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002580 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002581 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002582 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002583 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002584
2585 /// \brief Build a new Objective-C property reference expression.
2586 ///
2587 /// By default, performs semantic analysis to build the new expression.
2588 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002589 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002590 ObjCPropertyDecl *Property,
2591 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002592 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002593 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2594 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2595 /*FIXME:*/PropertyLoc,
2596 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002597 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002598 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002599 NameInfo,
2600 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002602
John McCallb7bd14f2010-12-02 01:19:52 +00002603 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002604 ///
2605 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002606 /// Subclasses may override this routine to provide different behavior.
2607 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2608 ObjCMethodDecl *Getter,
2609 ObjCMethodDecl *Setter,
2610 SourceLocation PropertyLoc) {
2611 // Since these expressions can only be value-dependent, we do not
2612 // need to perform semantic analysis again.
2613 return Owned(
2614 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2615 VK_LValue, OK_ObjCProperty,
2616 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002617 }
2618
Douglas Gregord51d90d2010-04-26 20:11:03 +00002619 /// \brief Build a new Objective-C "isa" expression.
2620 ///
2621 /// By default, performs semantic analysis to build the new expression.
2622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002623 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002624 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002625 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002626 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2627 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002628 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002629 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002630 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002631 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002632 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002634
Douglas Gregora16548e2009-08-11 05:31:07 +00002635 /// \brief Build a new shuffle vector expression.
2636 ///
2637 /// By default, performs semantic analysis to build the new expression.
2638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002639 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002640 MultiExprArg SubExprs,
2641 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002642 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002643 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002644 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2645 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2646 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002647 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002648
Douglas Gregora16548e2009-08-11 05:31:07 +00002649 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002650 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002651 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2652 SemaRef.Context.BuiltinFnTy,
2653 VK_RValue, BuiltinLoc);
2654 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2655 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002656 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002657
2658 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002659 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002660 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002661 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002662
Douglas Gregora16548e2009-08-11 05:31:07 +00002663 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002664 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002665 }
John McCall31f82722010-11-12 08:19:04 +00002666
Hal Finkelc4d7c822013-09-18 03:29:45 +00002667 /// \brief Build a new convert vector expression.
2668 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2669 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2670 SourceLocation RParenLoc) {
2671 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2672 BuiltinLoc, RParenLoc);
2673 }
2674
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002675 /// \brief Build a new template argument pack expansion.
2676 ///
2677 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002678 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002679 /// different behavior.
2680 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002681 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002682 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002683 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002684 case TemplateArgument::Expression: {
2685 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002686 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2687 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002688 if (Result.isInvalid())
2689 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002690
Douglas Gregor98318c22011-01-03 21:37:45 +00002691 return TemplateArgumentLoc(Result.get(), Result.get());
2692 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002693
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002694 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002695 return TemplateArgumentLoc(TemplateArgument(
2696 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002697 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002698 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002699 Pattern.getTemplateNameLoc(),
2700 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002701
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002702 case TemplateArgument::Null:
2703 case TemplateArgument::Integral:
2704 case TemplateArgument::Declaration:
2705 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002706 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002707 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002708 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002709
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002710 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002711 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002712 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002713 EllipsisLoc,
2714 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002715 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2716 Expansion);
2717 break;
2718 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002719
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002720 return TemplateArgumentLoc();
2721 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002722
Douglas Gregor968f23a2011-01-03 19:31:53 +00002723 /// \brief Build a new expression pack expansion.
2724 ///
2725 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002726 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002727 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002728 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002729 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002730 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002731 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002732
2733 /// \brief Build a new atomic operation expression.
2734 ///
2735 /// By default, performs semantic analysis to build the new expression.
2736 /// Subclasses may override this routine to provide different behavior.
2737 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2738 MultiExprArg SubExprs,
2739 QualType RetTy,
2740 AtomicExpr::AtomicOp Op,
2741 SourceLocation RParenLoc) {
2742 // Just create the expression; there is not any interesting semantic
2743 // analysis here because we can't actually build an AtomicExpr until
2744 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002745 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002746 RParenLoc);
2747 }
2748
John McCall31f82722010-11-12 08:19:04 +00002749private:
Douglas Gregor14454802011-02-25 02:25:35 +00002750 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2751 QualType ObjectType,
2752 NamedDecl *FirstQualifierInScope,
2753 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002754
2755 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2756 QualType ObjectType,
2757 NamedDecl *FirstQualifierInScope,
2758 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002759
2760 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2761 NamedDecl *FirstQualifierInScope,
2762 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002763};
Douglas Gregora16548e2009-08-11 05:31:07 +00002764
Douglas Gregorebe10102009-08-20 07:17:43 +00002765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002766StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002767 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002768 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002769
Douglas Gregorebe10102009-08-20 07:17:43 +00002770 switch (S->getStmtClass()) {
2771 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002772
Douglas Gregorebe10102009-08-20 07:17:43 +00002773 // Transform individual statement nodes
2774#define STMT(Node, Parent) \
2775 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002776#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002777#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002778#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002779
Douglas Gregorebe10102009-08-20 07:17:43 +00002780 // Transform expressions by calling TransformExpr.
2781#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002782#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002783#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002784#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002785 {
John McCalldadc5752010-08-24 06:29:42 +00002786 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002787 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002788 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002789
Richard Smith945f8d32013-01-14 22:39:08 +00002790 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002791 }
Mike Stump11289f42009-09-09 15:08:12 +00002792 }
2793
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002794 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002795}
Mike Stump11289f42009-09-09 15:08:12 +00002796
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002797template<typename Derived>
2798OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2799 if (!S)
2800 return S;
2801
2802 switch (S->getClauseKind()) {
2803 default: break;
2804 // Transform individual clause nodes
2805#define OPENMP_CLAUSE(Name, Class) \
2806 case OMPC_ ## Name : \
2807 return getDerived().Transform ## Class(cast<Class>(S));
2808#include "clang/Basic/OpenMPKinds.def"
2809 }
2810
2811 return S;
2812}
2813
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregore922c772009-08-04 22:27:00 +00002815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002816ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002817 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002818 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002819
2820 switch (E->getStmtClass()) {
2821 case Stmt::NoStmtClass: break;
2822#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002823#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002824#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002825 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002826#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002827 }
2828
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002829 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002830}
2831
2832template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002833ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2834 bool CXXDirectInit) {
2835 // Initializers are instantiated like expressions, except that various outer
2836 // layers are stripped.
2837 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002838 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002839
2840 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2841 Init = ExprTemp->getSubExpr();
2842
Richard Smithe6ca4752013-05-30 22:40:16 +00002843 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2844 Init = MTE->GetTemporaryExpr();
2845
Richard Smithd59b8322012-12-19 01:39:02 +00002846 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2847 Init = Binder->getSubExpr();
2848
2849 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2850 Init = ICE->getSubExprAsWritten();
2851
Richard Smithcc1b96d2013-06-12 22:31:48 +00002852 if (CXXStdInitializerListExpr *ILE =
2853 dyn_cast<CXXStdInitializerListExpr>(Init))
2854 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2855
Richard Smith38a549b2012-12-21 08:13:35 +00002856 // If this is not a direct-initializer, we only need to reconstruct
2857 // InitListExprs. Other forms of copy-initialization will be a no-op if
2858 // the initializer is already the right type.
2859 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2860 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2861 return getDerived().TransformExpr(Init);
2862
2863 // Revert value-initialization back to empty parens.
2864 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2865 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002866 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002867 Parens.getEnd());
2868 }
2869
2870 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2871 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002872 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002873 SourceLocation());
2874
2875 // Revert initialization by constructor back to a parenthesized or braced list
2876 // of expressions. Any other form of initializer can just be reused directly.
2877 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002878 return getDerived().TransformExpr(Init);
2879
2880 SmallVector<Expr*, 8> NewArgs;
2881 bool ArgChanged = false;
2882 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2883 /*IsCall*/true, NewArgs, &ArgChanged))
2884 return ExprError();
2885
2886 // If this was list initialization, revert to list form.
2887 if (Construct->isListInitialization())
2888 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2889 Construct->getLocEnd(),
2890 Construct->getType());
2891
Richard Smithd59b8322012-12-19 01:39:02 +00002892 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002893 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002894 if (Parens.isInvalid()) {
2895 // This was a variable declaration's initialization for which no initializer
2896 // was specified.
2897 assert(NewArgs.empty() &&
2898 "no parens or braces but have direct init with arguments?");
2899 return ExprEmpty();
2900 }
Richard Smithd59b8322012-12-19 01:39:02 +00002901 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2902 Parens.getEnd());
2903}
2904
2905template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002906bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2907 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002908 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002909 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002910 bool *ArgChanged) {
2911 for (unsigned I = 0; I != NumInputs; ++I) {
2912 // If requested, drop call arguments that need to be dropped.
2913 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2914 if (ArgChanged)
2915 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002916
Douglas Gregora3efea12011-01-03 19:04:46 +00002917 break;
2918 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002919
Douglas Gregor968f23a2011-01-03 19:31:53 +00002920 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2921 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002922
Chris Lattner01cf8db2011-07-20 06:58:45 +00002923 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002924 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2925 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
Douglas Gregor968f23a2011-01-03 19:31:53 +00002927 // Determine whether the set of unexpanded parameter packs can and should
2928 // be expanded.
2929 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002930 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002931 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2932 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002933 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2934 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002935 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002936 Expand, RetainExpansion,
2937 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002938 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002939
Douglas Gregor968f23a2011-01-03 19:31:53 +00002940 if (!Expand) {
2941 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002942 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002943 // expansion.
2944 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2945 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2946 if (OutPattern.isInvalid())
2947 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
2949 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002950 Expansion->getEllipsisLoc(),
2951 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002952 if (Out.isInvalid())
2953 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Douglas Gregor968f23a2011-01-03 19:31:53 +00002955 if (ArgChanged)
2956 *ArgChanged = true;
2957 Outputs.push_back(Out.get());
2958 continue;
2959 }
John McCall542e7c62011-07-06 07:30:07 +00002960
2961 // Record right away that the argument was changed. This needs
2962 // to happen even if the array expands to nothing.
2963 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002964
Douglas Gregor968f23a2011-01-03 19:31:53 +00002965 // The transform has determined that we should perform an elementwise
2966 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002967 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002968 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2969 ExprResult Out = getDerived().TransformExpr(Pattern);
2970 if (Out.isInvalid())
2971 return true;
2972
Richard Smith9467be42014-06-06 17:33:35 +00002973 // FIXME: Can this happen? We should not try to expand the pack
2974 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002975 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002976 Out = getDerived().RebuildPackExpansion(
2977 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002978 if (Out.isInvalid())
2979 return true;
2980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002981
Douglas Gregor968f23a2011-01-03 19:31:53 +00002982 Outputs.push_back(Out.get());
2983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Richard Smith9467be42014-06-06 17:33:35 +00002985 // If we're supposed to retain a pack expansion, do so by temporarily
2986 // forgetting the partially-substituted parameter pack.
2987 if (RetainExpansion) {
2988 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2989
2990 ExprResult Out = getDerived().TransformExpr(Pattern);
2991 if (Out.isInvalid())
2992 return true;
2993
2994 Out = getDerived().RebuildPackExpansion(
2995 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
2996 if (Out.isInvalid())
2997 return true;
2998
2999 Outputs.push_back(Out.get());
3000 }
3001
Douglas Gregor968f23a2011-01-03 19:31:53 +00003002 continue;
3003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003004
Richard Smithd59b8322012-12-19 01:39:02 +00003005 ExprResult Result =
3006 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3007 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003008 if (Result.isInvalid())
3009 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregora3efea12011-01-03 19:04:46 +00003011 if (Result.get() != Inputs[I] && ArgChanged)
3012 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
3014 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003016
Douglas Gregora3efea12011-01-03 19:04:46 +00003017 return false;
3018}
3019
3020template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003021NestedNameSpecifierLoc
3022TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3023 NestedNameSpecifierLoc NNS,
3024 QualType ObjectType,
3025 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003026 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003027 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003028 Qualifier = Qualifier.getPrefix())
3029 Qualifiers.push_back(Qualifier);
3030
3031 CXXScopeSpec SS;
3032 while (!Qualifiers.empty()) {
3033 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3034 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003035
Douglas Gregor14454802011-02-25 02:25:35 +00003036 switch (QNNS->getKind()) {
3037 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003038 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003039 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003040 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003041 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003042 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003043 FirstQualifierInScope, false))
3044 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
Douglas Gregor14454802011-02-25 02:25:35 +00003046 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003047
Douglas Gregor14454802011-02-25 02:25:35 +00003048 case NestedNameSpecifier::Namespace: {
3049 NamespaceDecl *NS
3050 = cast_or_null<NamespaceDecl>(
3051 getDerived().TransformDecl(
3052 Q.getLocalBeginLoc(),
3053 QNNS->getAsNamespace()));
3054 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3055 break;
3056 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003057
Douglas Gregor14454802011-02-25 02:25:35 +00003058 case NestedNameSpecifier::NamespaceAlias: {
3059 NamespaceAliasDecl *Alias
3060 = cast_or_null<NamespaceAliasDecl>(
3061 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3062 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003063 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003064 Q.getLocalEndLoc());
3065 break;
3066 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
Douglas Gregor14454802011-02-25 02:25:35 +00003068 case NestedNameSpecifier::Global:
3069 // There is no meaningful transformation that one could perform on the
3070 // global scope.
3071 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3072 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor14454802011-02-25 02:25:35 +00003074 case NestedNameSpecifier::TypeSpecWithTemplate:
3075 case NestedNameSpecifier::TypeSpec: {
3076 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3077 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003078
Douglas Gregor14454802011-02-25 02:25:35 +00003079 if (!TL)
3080 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Douglas Gregor14454802011-02-25 02:25:35 +00003082 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003083 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003084 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003085 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003086 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003087 if (TL.getType()->isEnumeralType())
3088 SemaRef.Diag(TL.getBeginLoc(),
3089 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003090 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3091 Q.getLocalEndLoc());
3092 break;
3093 }
Richard Trieude756fb2011-05-07 01:36:37 +00003094 // If the nested-name-specifier is an invalid type def, don't emit an
3095 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003096 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3097 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003098 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003099 << TL.getType() << SS.getRange();
3100 }
Douglas Gregor14454802011-02-25 02:25:35 +00003101 return NestedNameSpecifierLoc();
3102 }
Douglas Gregore16af532011-02-28 18:50:33 +00003103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003104
Douglas Gregore16af532011-02-28 18:50:33 +00003105 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003106 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003107 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003108 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Douglas Gregor14454802011-02-25 02:25:35 +00003110 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003111 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003112 !getDerived().AlwaysRebuild())
3113 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003114
3115 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003116 // nested-name-specifier, do so.
3117 if (SS.location_size() == NNS.getDataLength() &&
3118 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3119 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3120
3121 // Allocate new nested-name-specifier location information.
3122 return SS.getWithLocInContext(SemaRef.Context);
3123}
3124
3125template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003126DeclarationNameInfo
3127TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003128::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003129 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003130 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003131 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003132
3133 switch (Name.getNameKind()) {
3134 case DeclarationName::Identifier:
3135 case DeclarationName::ObjCZeroArgSelector:
3136 case DeclarationName::ObjCOneArgSelector:
3137 case DeclarationName::ObjCMultiArgSelector:
3138 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003139 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003140 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003141 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003142
Douglas Gregorf816bd72009-09-03 22:13:48 +00003143 case DeclarationName::CXXConstructorName:
3144 case DeclarationName::CXXDestructorName:
3145 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003146 TypeSourceInfo *NewTInfo;
3147 CanQualType NewCanTy;
3148 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003149 NewTInfo = getDerived().TransformType(OldTInfo);
3150 if (!NewTInfo)
3151 return DeclarationNameInfo();
3152 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003153 }
3154 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003155 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003156 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003157 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003158 if (NewT.isNull())
3159 return DeclarationNameInfo();
3160 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3161 }
Mike Stump11289f42009-09-09 15:08:12 +00003162
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003163 DeclarationName NewName
3164 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3165 NewCanTy);
3166 DeclarationNameInfo NewNameInfo(NameInfo);
3167 NewNameInfo.setName(NewName);
3168 NewNameInfo.setNamedTypeInfo(NewTInfo);
3169 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003170 }
Mike Stump11289f42009-09-09 15:08:12 +00003171 }
3172
David Blaikie83d382b2011-09-23 05:06:16 +00003173 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003174}
3175
3176template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003177TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003178TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3179 TemplateName Name,
3180 SourceLocation NameLoc,
3181 QualType ObjectType,
3182 NamedDecl *FirstQualifierInScope) {
3183 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3184 TemplateDecl *Template = QTN->getTemplateDecl();
3185 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003186
Douglas Gregor9db53502011-03-02 18:07:45 +00003187 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003188 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003189 Template));
3190 if (!TransTemplate)
3191 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003192
Douglas Gregor9db53502011-03-02 18:07:45 +00003193 if (!getDerived().AlwaysRebuild() &&
3194 SS.getScopeRep() == QTN->getQualifier() &&
3195 TransTemplate == Template)
3196 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor9db53502011-03-02 18:07:45 +00003198 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3199 TransTemplate);
3200 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003201
Douglas Gregor9db53502011-03-02 18:07:45 +00003202 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3203 if (SS.getScopeRep()) {
3204 // These apply to the scope specifier, not the template.
3205 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003206 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003207 }
3208
Douglas Gregor9db53502011-03-02 18:07:45 +00003209 if (!getDerived().AlwaysRebuild() &&
3210 SS.getScopeRep() == DTN->getQualifier() &&
3211 ObjectType.isNull())
3212 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003213
Douglas Gregor9db53502011-03-02 18:07:45 +00003214 if (DTN->isIdentifier()) {
3215 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003216 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003217 NameLoc,
3218 ObjectType,
3219 FirstQualifierInScope);
3220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregor9db53502011-03-02 18:07:45 +00003222 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3223 ObjectType);
3224 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003225
Douglas Gregor9db53502011-03-02 18:07:45 +00003226 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3227 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003228 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003229 Template));
3230 if (!TransTemplate)
3231 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Douglas Gregor9db53502011-03-02 18:07:45 +00003233 if (!getDerived().AlwaysRebuild() &&
3234 TransTemplate == Template)
3235 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003236
Douglas Gregor9db53502011-03-02 18:07:45 +00003237 return TemplateName(TransTemplate);
3238 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
Douglas Gregor9db53502011-03-02 18:07:45 +00003240 if (SubstTemplateTemplateParmPackStorage *SubstPack
3241 = Name.getAsSubstTemplateTemplateParmPack()) {
3242 TemplateTemplateParmDecl *TransParam
3243 = cast_or_null<TemplateTemplateParmDecl>(
3244 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3245 if (!TransParam)
3246 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003247
Douglas Gregor9db53502011-03-02 18:07:45 +00003248 if (!getDerived().AlwaysRebuild() &&
3249 TransParam == SubstPack->getParameterPack())
3250 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003251
3252 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003253 SubstPack->getArgumentPack());
3254 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003255
Douglas Gregor9db53502011-03-02 18:07:45 +00003256 // These should be getting filtered out before they reach the AST.
3257 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003258}
3259
3260template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003261void TreeTransform<Derived>::InventTemplateArgumentLoc(
3262 const TemplateArgument &Arg,
3263 TemplateArgumentLoc &Output) {
3264 SourceLocation Loc = getDerived().getBaseLocation();
3265 switch (Arg.getKind()) {
3266 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003267 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003268 break;
3269
3270 case TemplateArgument::Type:
3271 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003272 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
John McCall0ad16662009-10-29 08:12:44 +00003274 break;
3275
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003276 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003277 case TemplateArgument::TemplateExpansion: {
3278 NestedNameSpecifierLocBuilder Builder;
3279 TemplateName Template = Arg.getAsTemplate();
3280 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3281 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3282 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3283 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
Douglas Gregor9d802122011-03-02 17:09:35 +00003285 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003286 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003287 Builder.getWithLocInContext(SemaRef.Context),
3288 Loc);
3289 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003290 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003291 Builder.getWithLocInContext(SemaRef.Context),
3292 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003293
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003294 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003295 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003296
John McCall0ad16662009-10-29 08:12:44 +00003297 case TemplateArgument::Expression:
3298 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3299 break;
3300
3301 case TemplateArgument::Declaration:
3302 case TemplateArgument::Integral:
3303 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003304 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003305 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003306 break;
3307 }
3308}
3309
3310template<typename Derived>
3311bool TreeTransform<Derived>::TransformTemplateArgument(
3312 const TemplateArgumentLoc &Input,
3313 TemplateArgumentLoc &Output) {
3314 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003315 switch (Arg.getKind()) {
3316 case TemplateArgument::Null:
3317 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003318 case TemplateArgument::Pack:
3319 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003320 case TemplateArgument::NullPtr:
3321 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003322
Douglas Gregore922c772009-08-04 22:27:00 +00003323 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003324 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003325 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003326 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003327
3328 DI = getDerived().TransformType(DI);
3329 if (!DI) return true;
3330
3331 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3332 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003333 }
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003335 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003336 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3337 if (QualifierLoc) {
3338 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3339 if (!QualifierLoc)
3340 return true;
3341 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003342
Douglas Gregordf846d12011-03-02 18:46:51 +00003343 CXXScopeSpec SS;
3344 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003345 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003346 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3347 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003348 if (Template.isNull())
3349 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregor9d802122011-03-02 17:09:35 +00003351 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003352 Input.getTemplateNameLoc());
3353 return false;
3354 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003355
3356 case TemplateArgument::TemplateExpansion:
3357 llvm_unreachable("Caller should expand pack expansions");
3358
Douglas Gregore922c772009-08-04 22:27:00 +00003359 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003360 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003361 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003362 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003363
John McCall0ad16662009-10-29 08:12:44 +00003364 Expr *InputExpr = Input.getSourceExpression();
3365 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3366
Chris Lattnercdb591a2011-04-25 20:37:58 +00003367 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003368 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003369 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003370 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003371 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003372 }
Douglas Gregore922c772009-08-04 22:27:00 +00003373 }
Mike Stump11289f42009-09-09 15:08:12 +00003374
Douglas Gregore922c772009-08-04 22:27:00 +00003375 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003376 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003377}
3378
Douglas Gregorfe921a72010-12-20 23:36:19 +00003379/// \brief Iterator adaptor that invents template argument location information
3380/// for each of the template arguments in its underlying iterator.
3381template<typename Derived, typename InputIterator>
3382class TemplateArgumentLocInventIterator {
3383 TreeTransform<Derived> &Self;
3384 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregorfe921a72010-12-20 23:36:19 +00003386public:
3387 typedef TemplateArgumentLoc value_type;
3388 typedef TemplateArgumentLoc reference;
3389 typedef typename std::iterator_traits<InputIterator>::difference_type
3390 difference_type;
3391 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregorfe921a72010-12-20 23:36:19 +00003393 class pointer {
3394 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
Douglas Gregorfe921a72010-12-20 23:36:19 +00003396 public:
3397 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003398
Douglas Gregorfe921a72010-12-20 23:36:19 +00003399 const TemplateArgumentLoc *operator->() const { return &Arg; }
3400 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003401
Douglas Gregorfe921a72010-12-20 23:36:19 +00003402 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregorfe921a72010-12-20 23:36:19 +00003404 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3405 InputIterator Iter)
3406 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregorfe921a72010-12-20 23:36:19 +00003408 TemplateArgumentLocInventIterator &operator++() {
3409 ++Iter;
3410 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003411 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregorfe921a72010-12-20 23:36:19 +00003413 TemplateArgumentLocInventIterator operator++(int) {
3414 TemplateArgumentLocInventIterator Old(*this);
3415 ++(*this);
3416 return Old;
3417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregorfe921a72010-12-20 23:36:19 +00003419 reference operator*() const {
3420 TemplateArgumentLoc Result;
3421 Self.InventTemplateArgumentLoc(*Iter, Result);
3422 return Result;
3423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Douglas Gregorfe921a72010-12-20 23:36:19 +00003425 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
Douglas Gregorfe921a72010-12-20 23:36:19 +00003427 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3428 const TemplateArgumentLocInventIterator &Y) {
3429 return X.Iter == Y.Iter;
3430 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003431
Douglas Gregorfe921a72010-12-20 23:36:19 +00003432 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3433 const TemplateArgumentLocInventIterator &Y) {
3434 return X.Iter != Y.Iter;
3435 }
3436};
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor42cafa82010-12-20 17:42:22 +00003438template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003439template<typename InputIterator>
3440bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3441 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003442 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003443 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003444 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003445 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003447 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3448 // Unpack argument packs, which we translate them into separate
3449 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003450 // FIXME: We could do much better if we could guarantee that the
3451 // TemplateArgumentLocInfo for the pack expansion would be usable for
3452 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003453 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003454 TemplateArgument::pack_iterator>
3455 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003456 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003457 In.getArgument().pack_begin()),
3458 PackLocIterator(*this,
3459 In.getArgument().pack_end()),
3460 Outputs))
3461 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003463 continue;
3464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003465
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003466 if (In.getArgument().isPackExpansion()) {
3467 // We have a pack expansion, for which we will be substituting into
3468 // the pattern.
3469 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003470 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003471 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003472 = getSema().getTemplateArgumentPackExpansionPattern(
3473 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
Chris Lattner01cf8db2011-07-20 06:58:45 +00003475 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003476 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3477 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003478
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003479 // Determine whether the set of unexpanded parameter packs can and should
3480 // be expanded.
3481 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003482 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003483 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003484 if (getDerived().TryExpandParameterPacks(Ellipsis,
3485 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003486 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003487 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003488 RetainExpansion,
3489 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003490 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003491
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003492 if (!Expand) {
3493 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003494 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003495 // expansion.
3496 TemplateArgumentLoc OutPattern;
3497 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3498 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3499 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003500
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003501 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3502 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003503 if (Out.getArgument().isNull())
3504 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003505
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003506 Outputs.addArgument(Out);
3507 continue;
3508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003509
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003510 // The transform has determined that we should perform an elementwise
3511 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003512 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003513 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3514
3515 if (getDerived().TransformTemplateArgument(Pattern, Out))
3516 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003518 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003519 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3520 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003521 if (Out.getArgument().isNull())
3522 return true;
3523 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003525 Outputs.addArgument(Out);
3526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
Douglas Gregor48d24112011-01-10 20:53:55 +00003528 // If we're supposed to retain a pack expansion, do so by temporarily
3529 // forgetting the partially-substituted parameter pack.
3530 if (RetainExpansion) {
3531 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003532
Douglas Gregor48d24112011-01-10 20:53:55 +00003533 if (getDerived().TransformTemplateArgument(Pattern, Out))
3534 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003536 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3537 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003538 if (Out.getArgument().isNull())
3539 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003540
Douglas Gregor48d24112011-01-10 20:53:55 +00003541 Outputs.addArgument(Out);
3542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003544 continue;
3545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003546
3547 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003548 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003549 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor42cafa82010-12-20 17:42:22 +00003551 Outputs.addArgument(Out);
3552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregor42cafa82010-12-20 17:42:22 +00003554 return false;
3555
3556}
3557
Douglas Gregord6ff3322009-08-04 16:50:30 +00003558//===----------------------------------------------------------------------===//
3559// Type transformation
3560//===----------------------------------------------------------------------===//
3561
3562template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003563QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003564 if (getDerived().AlreadyTransformed(T))
3565 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003566
John McCall550e0c22009-10-21 00:40:46 +00003567 // Temporary workaround. All of these transformations should
3568 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003569 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3570 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
John McCall31f82722010-11-12 08:19:04 +00003572 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003573
John McCall550e0c22009-10-21 00:40:46 +00003574 if (!NewDI)
3575 return QualType();
3576
3577 return NewDI->getType();
3578}
3579
3580template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003581TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003582 // Refine the base location to the type's location.
3583 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3584 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003585 if (getDerived().AlreadyTransformed(DI->getType()))
3586 return DI;
3587
3588 TypeLocBuilder TLB;
3589
3590 TypeLoc TL = DI->getTypeLoc();
3591 TLB.reserve(TL.getFullDataSize());
3592
John McCall31f82722010-11-12 08:19:04 +00003593 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003594 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003595 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003596
John McCallbcd03502009-12-07 02:54:59 +00003597 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003598}
3599
3600template<typename Derived>
3601QualType
John McCall31f82722010-11-12 08:19:04 +00003602TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003603 switch (T.getTypeLocClass()) {
3604#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003605#define TYPELOC(CLASS, PARENT) \
3606 case TypeLoc::CLASS: \
3607 return getDerived().Transform##CLASS##Type(TLB, \
3608 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003609#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003610 }
Mike Stump11289f42009-09-09 15:08:12 +00003611
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003612 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003613}
3614
3615/// FIXME: By default, this routine adds type qualifiers only to types
3616/// that can have qualifiers, and silently suppresses those qualifiers
3617/// that are not permitted (e.g., qualifiers on reference or function
3618/// types). This is the right thing for template instantiation, but
3619/// probably not for other clients.
3620template<typename Derived>
3621QualType
3622TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003623 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003624 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003625
John McCall31f82722010-11-12 08:19:04 +00003626 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003627 if (Result.isNull())
3628 return QualType();
3629
3630 // Silently suppress qualifiers if the result type can't be qualified.
3631 // FIXME: this is the right thing for template instantiation, but
3632 // probably not for other clients.
3633 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003634 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003635
John McCall31168b02011-06-15 23:02:42 +00003636 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003637 // resulting type.
3638 if (Quals.hasObjCLifetime()) {
3639 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3640 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003641 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003642 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003643 // A lifetime qualifier applied to a substituted template parameter
3644 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003645 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003646 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003647 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3648 QualType Replacement = SubstTypeParam->getReplacementType();
3649 Qualifiers Qs = Replacement.getQualifiers();
3650 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003651 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003652 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3653 Qs);
3654 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003655 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003656 Replacement);
3657 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003658 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3659 // 'auto' types behave the same way as template parameters.
3660 QualType Deduced = AutoTy->getDeducedType();
3661 Qualifiers Qs = Deduced.getQualifiers();
3662 Qs.removeObjCLifetime();
3663 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3664 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003665 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3666 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003667 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003668 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003669 // Otherwise, complain about the addition of a qualifier to an
3670 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003671 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003672 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003673 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003674
Douglas Gregore46db902011-06-17 22:11:49 +00003675 Quals.removeObjCLifetime();
3676 }
3677 }
3678 }
John McCallcb0f89a2010-06-05 06:41:15 +00003679 if (!Quals.empty()) {
3680 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003681 // BuildQualifiedType might not add qualifiers if they are invalid.
3682 if (Result.hasLocalQualifiers())
3683 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003684 // No location information to preserve.
3685 }
John McCall550e0c22009-10-21 00:40:46 +00003686
3687 return Result;
3688}
3689
Douglas Gregor14454802011-02-25 02:25:35 +00003690template<typename Derived>
3691TypeLoc
3692TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3693 QualType ObjectType,
3694 NamedDecl *UnqualLookup,
3695 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003696 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003697 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003699 TypeSourceInfo *TSI =
3700 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3701 if (TSI)
3702 return TSI->getTypeLoc();
3703 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003704}
3705
Douglas Gregor579c15f2011-03-02 18:32:08 +00003706template<typename Derived>
3707TypeSourceInfo *
3708TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3709 QualType ObjectType,
3710 NamedDecl *UnqualLookup,
3711 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003712 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003713 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003714
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003715 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3716 UnqualLookup, SS);
3717}
3718
3719template <typename Derived>
3720TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3721 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3722 CXXScopeSpec &SS) {
3723 QualType T = TL.getType();
3724 assert(!getDerived().AlreadyTransformed(T));
3725
Douglas Gregor579c15f2011-03-02 18:32:08 +00003726 TypeLocBuilder TLB;
3727 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregor579c15f2011-03-02 18:32:08 +00003729 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003730 TemplateSpecializationTypeLoc SpecTL =
3731 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Douglas Gregor579c15f2011-03-02 18:32:08 +00003733 TemplateName Template
3734 = getDerived().TransformTemplateName(SS,
3735 SpecTL.getTypePtr()->getTemplateName(),
3736 SpecTL.getTemplateNameLoc(),
3737 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003738 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003739 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003740
3741 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003742 Template);
3743 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003744 DependentTemplateSpecializationTypeLoc SpecTL =
3745 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Douglas Gregor579c15f2011-03-02 18:32:08 +00003747 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003748 = getDerived().RebuildTemplateName(SS,
3749 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003750 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003751 ObjectType, UnqualLookup);
3752 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003753 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003754
3755 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003756 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003757 Template,
3758 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003759 } else {
3760 // Nothing special needs to be done for these.
3761 Result = getDerived().TransformType(TLB, TL);
3762 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003763
3764 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003765 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregor579c15f2011-03-02 18:32:08 +00003767 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3768}
3769
John McCall550e0c22009-10-21 00:40:46 +00003770template <class TyLoc> static inline
3771QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3772 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3773 NewT.setNameLoc(T.getNameLoc());
3774 return T.getType();
3775}
3776
John McCall550e0c22009-10-21 00:40:46 +00003777template<typename Derived>
3778QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003779 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003780 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3781 NewT.setBuiltinLoc(T.getBuiltinLoc());
3782 if (T.needsExtraLocalData())
3783 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3784 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003785}
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregord6ff3322009-08-04 16:50:30 +00003787template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003788QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003789 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003790 // FIXME: recurse?
3791 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003792}
Mike Stump11289f42009-09-09 15:08:12 +00003793
Reid Kleckner0503a872013-12-05 01:23:43 +00003794template <typename Derived>
3795QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3796 AdjustedTypeLoc TL) {
3797 // Adjustments applied during transformation are handled elsewhere.
3798 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3799}
3800
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003802QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3803 DecayedTypeLoc TL) {
3804 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3805 if (OriginalType.isNull())
3806 return QualType();
3807
3808 QualType Result = TL.getType();
3809 if (getDerived().AlwaysRebuild() ||
3810 OriginalType != TL.getOriginalLoc().getType())
3811 Result = SemaRef.Context.getDecayedType(OriginalType);
3812 TLB.push<DecayedTypeLoc>(Result);
3813 // Nothing to set for DecayedTypeLoc.
3814 return Result;
3815}
3816
3817template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003818QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003819 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003820 QualType PointeeType
3821 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003822 if (PointeeType.isNull())
3823 return QualType();
3824
3825 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003826 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003827 // A dependent pointer type 'T *' has is being transformed such
3828 // that an Objective-C class type is being replaced for 'T'. The
3829 // resulting pointer type is an ObjCObjectPointerType, not a
3830 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003831 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003832
John McCall8b07ec22010-05-15 11:32:37 +00003833 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3834 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003835 return Result;
3836 }
John McCall31f82722010-11-12 08:19:04 +00003837
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003838 if (getDerived().AlwaysRebuild() ||
3839 PointeeType != TL.getPointeeLoc().getType()) {
3840 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3841 if (Result.isNull())
3842 return QualType();
3843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
John McCall31168b02011-06-15 23:02:42 +00003845 // Objective-C ARC can add lifetime qualifiers to the type that we're
3846 // pointing to.
3847 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003848
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003849 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3850 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003851 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003852}
Mike Stump11289f42009-09-09 15:08:12 +00003853
3854template<typename Derived>
3855QualType
John McCall550e0c22009-10-21 00:40:46 +00003856TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003857 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003858 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003859 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3860 if (PointeeType.isNull())
3861 return QualType();
3862
3863 QualType Result = TL.getType();
3864 if (getDerived().AlwaysRebuild() ||
3865 PointeeType != TL.getPointeeLoc().getType()) {
3866 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003867 TL.getSigilLoc());
3868 if (Result.isNull())
3869 return QualType();
3870 }
3871
Douglas Gregor049211a2010-04-22 16:50:51 +00003872 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003873 NewT.setSigilLoc(TL.getSigilLoc());
3874 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003875}
3876
John McCall70dd5f62009-10-30 00:06:24 +00003877/// Transforms a reference type. Note that somewhat paradoxically we
3878/// don't care whether the type itself is an l-value type or an r-value
3879/// type; we only care if the type was *written* as an l-value type
3880/// or an r-value type.
3881template<typename Derived>
3882QualType
3883TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003884 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003885 const ReferenceType *T = TL.getTypePtr();
3886
3887 // Note that this works with the pointee-as-written.
3888 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3889 if (PointeeType.isNull())
3890 return QualType();
3891
3892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 PointeeType != T->getPointeeTypeAsWritten()) {
3895 Result = getDerived().RebuildReferenceType(PointeeType,
3896 T->isSpelledAsLValue(),
3897 TL.getSigilLoc());
3898 if (Result.isNull())
3899 return QualType();
3900 }
3901
John McCall31168b02011-06-15 23:02:42 +00003902 // Objective-C ARC can add lifetime qualifiers to the type that we're
3903 // referring to.
3904 TLB.TypeWasModifiedSafely(
3905 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3906
John McCall70dd5f62009-10-30 00:06:24 +00003907 // r-value references can be rebuilt as l-value references.
3908 ReferenceTypeLoc NewTL;
3909 if (isa<LValueReferenceType>(Result))
3910 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3911 else
3912 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3913 NewTL.setSigilLoc(TL.getSigilLoc());
3914
3915 return Result;
3916}
3917
Mike Stump11289f42009-09-09 15:08:12 +00003918template<typename Derived>
3919QualType
John McCall550e0c22009-10-21 00:40:46 +00003920TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003921 LValueReferenceTypeLoc TL) {
3922 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003923}
3924
Mike Stump11289f42009-09-09 15:08:12 +00003925template<typename Derived>
3926QualType
John McCall550e0c22009-10-21 00:40:46 +00003927TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003928 RValueReferenceTypeLoc TL) {
3929 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003930}
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregord6ff3322009-08-04 16:50:30 +00003932template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003933QualType
John McCall550e0c22009-10-21 00:40:46 +00003934TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003935 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003936 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937 if (PointeeType.isNull())
3938 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003939
Abramo Bagnara509357842011-03-05 14:42:21 +00003940 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003941 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003942 if (OldClsTInfo) {
3943 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3944 if (!NewClsTInfo)
3945 return QualType();
3946 }
3947
3948 const MemberPointerType *T = TL.getTypePtr();
3949 QualType OldClsType = QualType(T->getClass(), 0);
3950 QualType NewClsType;
3951 if (NewClsTInfo)
3952 NewClsType = NewClsTInfo->getType();
3953 else {
3954 NewClsType = getDerived().TransformType(OldClsType);
3955 if (NewClsType.isNull())
3956 return QualType();
3957 }
Mike Stump11289f42009-09-09 15:08:12 +00003958
John McCall550e0c22009-10-21 00:40:46 +00003959 QualType Result = TL.getType();
3960 if (getDerived().AlwaysRebuild() ||
3961 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003962 NewClsType != OldClsType) {
3963 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003964 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003965 if (Result.isNull())
3966 return QualType();
3967 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968
Reid Kleckner0503a872013-12-05 01:23:43 +00003969 // If we had to adjust the pointee type when building a member pointer, make
3970 // sure to push TypeLoc info for it.
3971 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3972 if (MPT && PointeeType != MPT->getPointeeType()) {
3973 assert(isa<AdjustedType>(MPT->getPointeeType()));
3974 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3975 }
3976
John McCall550e0c22009-10-21 00:40:46 +00003977 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3978 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003979 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003980
3981 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003982}
3983
Mike Stump11289f42009-09-09 15:08:12 +00003984template<typename Derived>
3985QualType
John McCall550e0c22009-10-21 00:40:46 +00003986TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003987 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003988 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003989 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003990 if (ElementType.isNull())
3991 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003992
John McCall550e0c22009-10-21 00:40:46 +00003993 QualType Result = TL.getType();
3994 if (getDerived().AlwaysRebuild() ||
3995 ElementType != T->getElementType()) {
3996 Result = getDerived().RebuildConstantArrayType(ElementType,
3997 T->getSizeModifier(),
3998 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003999 T->getIndexTypeCVRQualifiers(),
4000 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004001 if (Result.isNull())
4002 return QualType();
4003 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004004
4005 // We might have either a ConstantArrayType or a VariableArrayType now:
4006 // a ConstantArrayType is allowed to have an element type which is a
4007 // VariableArrayType if the type is dependent. Fortunately, all array
4008 // types have the same location layout.
4009 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004010 NewTL.setLBracketLoc(TL.getLBracketLoc());
4011 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004012
John McCall550e0c22009-10-21 00:40:46 +00004013 Expr *Size = TL.getSizeExpr();
4014 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004015 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4016 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004017 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4018 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004019 }
4020 NewTL.setSizeExpr(Size);
4021
4022 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023}
Mike Stump11289f42009-09-09 15:08:12 +00004024
Douglas Gregord6ff3322009-08-04 16:50:30 +00004025template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004026QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004027 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004028 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004029 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004030 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004031 if (ElementType.isNull())
4032 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004033
John McCall550e0c22009-10-21 00:40:46 +00004034 QualType Result = TL.getType();
4035 if (getDerived().AlwaysRebuild() ||
4036 ElementType != T->getElementType()) {
4037 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004038 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004039 T->getIndexTypeCVRQualifiers(),
4040 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004041 if (Result.isNull())
4042 return QualType();
4043 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004044
John McCall550e0c22009-10-21 00:40:46 +00004045 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4046 NewTL.setLBracketLoc(TL.getLBracketLoc());
4047 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004048 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004049
4050 return Result;
4051}
4052
4053template<typename Derived>
4054QualType
4055TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004056 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004057 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004058 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4059 if (ElementType.isNull())
4060 return QualType();
4061
John McCalldadc5752010-08-24 06:29:42 +00004062 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004063 = getDerived().TransformExpr(T->getSizeExpr());
4064 if (SizeResult.isInvalid())
4065 return QualType();
4066
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004067 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004068
4069 QualType Result = TL.getType();
4070 if (getDerived().AlwaysRebuild() ||
4071 ElementType != T->getElementType() ||
4072 Size != T->getSizeExpr()) {
4073 Result = getDerived().RebuildVariableArrayType(ElementType,
4074 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004075 Size,
John McCall550e0c22009-10-21 00:40:46 +00004076 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004077 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
4080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004081
Serge Pavlov774c6d02014-02-06 03:49:11 +00004082 // We might have constant size array now, but fortunately it has the same
4083 // location layout.
4084 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004085 NewTL.setLBracketLoc(TL.getLBracketLoc());
4086 NewTL.setRBracketLoc(TL.getRBracketLoc());
4087 NewTL.setSizeExpr(Size);
4088
4089 return Result;
4090}
4091
4092template<typename Derived>
4093QualType
4094TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004095 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004096 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004097 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4098 if (ElementType.isNull())
4099 return QualType();
4100
Richard Smith764d2fe2011-12-20 02:08:33 +00004101 // Array bounds are constant expressions.
4102 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4103 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004104
John McCall33ddac02011-01-19 10:06:00 +00004105 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4106 Expr *origSize = TL.getSizeExpr();
4107 if (!origSize) origSize = T->getSizeExpr();
4108
4109 ExprResult sizeResult
4110 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004111 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004112 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004113 return QualType();
4114
John McCall33ddac02011-01-19 10:06:00 +00004115 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004116
4117 QualType Result = TL.getType();
4118 if (getDerived().AlwaysRebuild() ||
4119 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004120 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004121 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4122 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004123 size,
John McCall550e0c22009-10-21 00:40:46 +00004124 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004125 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004126 if (Result.isNull())
4127 return QualType();
4128 }
John McCall550e0c22009-10-21 00:40:46 +00004129
4130 // We might have any sort of array type now, but fortunately they
4131 // all have the same location layout.
4132 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4133 NewTL.setLBracketLoc(TL.getLBracketLoc());
4134 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004135 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004136
4137 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138}
Mike Stump11289f42009-09-09 15:08:12 +00004139
4140template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004141QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004142 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004143 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004144 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004145
4146 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004147 QualType ElementType = getDerived().TransformType(T->getElementType());
4148 if (ElementType.isNull())
4149 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004150
Richard Smith764d2fe2011-12-20 02:08:33 +00004151 // Vector sizes are constant expressions.
4152 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4153 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004154
John McCalldadc5752010-08-24 06:29:42 +00004155 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004156 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157 if (Size.isInvalid())
4158 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall550e0c22009-10-21 00:40:46 +00004160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004162 ElementType != T->getElementType() ||
4163 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004164 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004165 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004166 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004167 if (Result.isNull())
4168 return QualType();
4169 }
John McCall550e0c22009-10-21 00:40:46 +00004170
4171 // Result might be dependent or not.
4172 if (isa<DependentSizedExtVectorType>(Result)) {
4173 DependentSizedExtVectorTypeLoc NewTL
4174 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4175 NewTL.setNameLoc(TL.getNameLoc());
4176 } else {
4177 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4178 NewTL.setNameLoc(TL.getNameLoc());
4179 }
4180
4181 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182}
Mike Stump11289f42009-09-09 15:08:12 +00004183
4184template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004185QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004186 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004187 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004188 QualType ElementType = getDerived().TransformType(T->getElementType());
4189 if (ElementType.isNull())
4190 return QualType();
4191
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
4194 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004195 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004196 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004197 if (Result.isNull())
4198 return QualType();
4199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004200
John McCall550e0c22009-10-21 00:40:46 +00004201 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4202 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004203
John McCall550e0c22009-10-21 00:40:46 +00004204 return Result;
4205}
4206
4207template<typename Derived>
4208QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004209 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004210 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004211 QualType ElementType = getDerived().TransformType(T->getElementType());
4212 if (ElementType.isNull())
4213 return QualType();
4214
4215 QualType Result = TL.getType();
4216 if (getDerived().AlwaysRebuild() ||
4217 ElementType != T->getElementType()) {
4218 Result = getDerived().RebuildExtVectorType(ElementType,
4219 T->getNumElements(),
4220 /*FIXME*/ SourceLocation());
4221 if (Result.isNull())
4222 return QualType();
4223 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004224
John McCall550e0c22009-10-21 00:40:46 +00004225 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4226 NewTL.setNameLoc(TL.getNameLoc());
4227
4228 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004229}
Mike Stump11289f42009-09-09 15:08:12 +00004230
David Blaikie05785d12013-02-20 22:23:23 +00004231template <typename Derived>
4232ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4233 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4234 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004235 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004236 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004237
Douglas Gregor715e4612011-01-14 22:40:04 +00004238 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004239 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004240 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004241 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004242 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004243
Douglas Gregor715e4612011-01-14 22:40:04 +00004244 TypeLocBuilder TLB;
4245 TypeLoc NewTL = OldDI->getTypeLoc();
4246 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004247
4248 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004249 OldExpansionTL.getPatternLoc());
4250 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004251 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004252
4253 Result = RebuildPackExpansionType(Result,
4254 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004255 OldExpansionTL.getEllipsisLoc(),
4256 NumExpansions);
4257 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004258 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004259
Douglas Gregor715e4612011-01-14 22:40:04 +00004260 PackExpansionTypeLoc NewExpansionTL
4261 = TLB.push<PackExpansionTypeLoc>(Result);
4262 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4263 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4264 } else
4265 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004266 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004267 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004268
John McCall8fb0d9d2011-05-01 22:35:37 +00004269 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004270 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004271
4272 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4273 OldParm->getDeclContext(),
4274 OldParm->getInnerLocStart(),
4275 OldParm->getLocation(),
4276 OldParm->getIdentifier(),
4277 NewDI->getType(),
4278 NewDI,
4279 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004280 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004281 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4282 OldParm->getFunctionScopeIndex() + indexAdjustment);
4283 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004284}
4285
4286template<typename Derived>
4287bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004288 TransformFunctionTypeParams(SourceLocation Loc,
4289 ParmVarDecl **Params, unsigned NumParams,
4290 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004291 SmallVectorImpl<QualType> &OutParamTypes,
4292 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004293 int indexAdjustment = 0;
4294
Douglas Gregordd472162011-01-07 00:20:55 +00004295 for (unsigned i = 0; i != NumParams; ++i) {
4296 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004297 assert(OldParm->getFunctionScopeIndex() == i);
4298
David Blaikie05785d12013-02-20 22:23:23 +00004299 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004300 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004301 if (OldParm->isParameterPack()) {
4302 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004303 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004304
Douglas Gregor5499af42011-01-05 23:12:31 +00004305 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004306 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004307 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004308 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4309 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004310 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4311
Douglas Gregor5499af42011-01-05 23:12:31 +00004312 // Determine whether we should expand the parameter packs.
4313 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004314 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004315 Optional<unsigned> OrigNumExpansions =
4316 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004317 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004318 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4319 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004320 Unexpanded,
4321 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004322 RetainExpansion,
4323 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004324 return true;
4325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004326
Douglas Gregor5499af42011-01-05 23:12:31 +00004327 if (ShouldExpand) {
4328 // Expand the function parameter pack into multiple, separate
4329 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004330 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004331 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004333 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004334 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004335 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004336 OrigNumExpansions,
4337 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004338 if (!NewParm)
4339 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004340
Douglas Gregordd472162011-01-07 00:20:55 +00004341 OutParamTypes.push_back(NewParm->getType());
4342 if (PVars)
4343 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004344 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004345
4346 // If we're supposed to retain a pack expansion, do so by temporarily
4347 // forgetting the partially-substituted parameter pack.
4348 if (RetainExpansion) {
4349 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004350 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004351 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004352 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004353 OrigNumExpansions,
4354 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004355 if (!NewParm)
4356 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004357
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004358 OutParamTypes.push_back(NewParm->getType());
4359 if (PVars)
4360 PVars->push_back(NewParm);
4361 }
4362
John McCall8fb0d9d2011-05-01 22:35:37 +00004363 // The next parameter should have the same adjustment as the
4364 // last thing we pushed, but we post-incremented indexAdjustment
4365 // on every push. Also, if we push nothing, the adjustment should
4366 // go down by one.
4367 indexAdjustment--;
4368
Douglas Gregor5499af42011-01-05 23:12:31 +00004369 // We're done with the pack expansion.
4370 continue;
4371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
4373 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004374 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4376 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004377 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004378 NumExpansions,
4379 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004380 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004381 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004382 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004383 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004384
John McCall58f10c32010-03-11 09:03:00 +00004385 if (!NewParm)
4386 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004387
Douglas Gregordd472162011-01-07 00:20:55 +00004388 OutParamTypes.push_back(NewParm->getType());
4389 if (PVars)
4390 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004391 continue;
4392 }
John McCall58f10c32010-03-11 09:03:00 +00004393
4394 // Deal with the possibility that we don't have a parameter
4395 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004396 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004397 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004398 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004399 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004400 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004401 = dyn_cast<PackExpansionType>(OldType)) {
4402 // We have a function parameter pack that may need to be expanded.
4403 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004404 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004405 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004406
Douglas Gregor5499af42011-01-05 23:12:31 +00004407 // Determine whether we should expand the parameter packs.
4408 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004409 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004410 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004411 Unexpanded,
4412 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004413 RetainExpansion,
4414 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004415 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004417
Douglas Gregor5499af42011-01-05 23:12:31 +00004418 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004419 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004420 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004421 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004422 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4423 QualType NewType = getDerived().TransformType(Pattern);
4424 if (NewType.isNull())
4425 return true;
John McCall58f10c32010-03-11 09:03:00 +00004426
Douglas Gregordd472162011-01-07 00:20:55 +00004427 OutParamTypes.push_back(NewType);
4428 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004429 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004430 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004431
Douglas Gregor5499af42011-01-05 23:12:31 +00004432 // We're done with the pack expansion.
4433 continue;
4434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004435
Douglas Gregor48d24112011-01-10 20:53:55 +00004436 // If we're supposed to retain a pack expansion, do so by temporarily
4437 // forgetting the partially-substituted parameter pack.
4438 if (RetainExpansion) {
4439 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4440 QualType NewType = getDerived().TransformType(Pattern);
4441 if (NewType.isNull())
4442 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004443
Douglas Gregor48d24112011-01-10 20:53:55 +00004444 OutParamTypes.push_back(NewType);
4445 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004446 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004447 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004448
Chad Rosier1dcde962012-08-08 18:46:20 +00004449 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 // expansion.
4451 OldType = Expansion->getPattern();
4452 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004453 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4454 NewType = getDerived().TransformType(OldType);
4455 } else {
4456 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004458
Douglas Gregor5499af42011-01-05 23:12:31 +00004459 if (NewType.isNull())
4460 return true;
4461
4462 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004463 NewType = getSema().Context.getPackExpansionType(NewType,
4464 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004465
Douglas Gregordd472162011-01-07 00:20:55 +00004466 OutParamTypes.push_back(NewType);
4467 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004468 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004469 }
4470
John McCall8fb0d9d2011-05-01 22:35:37 +00004471#ifndef NDEBUG
4472 if (PVars) {
4473 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4474 if (ParmVarDecl *parm = (*PVars)[i])
4475 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004476 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004477#endif
4478
4479 return false;
4480}
John McCall58f10c32010-03-11 09:03:00 +00004481
4482template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004483QualType
John McCall550e0c22009-10-21 00:40:46 +00004484TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004485 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004486 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004487}
4488
4489template<typename Derived>
4490QualType
4491TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4492 FunctionProtoTypeLoc TL,
4493 CXXRecordDecl *ThisContext,
4494 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004495 // Transform the parameters and return type.
4496 //
Richard Smithf623c962012-04-17 00:58:00 +00004497 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004498 // When the function has a trailing return type, we instantiate the
4499 // parameters before the return type, since the return type can then refer
4500 // to the parameters themselves (via decltype, sizeof, etc.).
4501 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004502 SmallVector<QualType, 4> ParamTypes;
4503 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004504 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004505
Douglas Gregor7fb25412010-10-01 18:44:50 +00004506 QualType ResultType;
4507
Richard Smith1226c602012-08-14 22:51:13 +00004508 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004509 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004510 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004511 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004512 return QualType();
4513
Douglas Gregor3024f072012-04-16 07:05:22 +00004514 {
4515 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004516 // If a declaration declares a member function or member function
4517 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004518 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004519 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004520 // declarator.
4521 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004522
Alp Toker42a16a62014-01-25 23:51:36 +00004523 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004524 if (ResultType.isNull())
4525 return QualType();
4526 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004527 }
4528 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004529 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004530 if (ResultType.isNull())
4531 return QualType();
4532
Alp Toker9cacbab2014-01-20 20:26:09 +00004533 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004534 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004535 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004536 return QualType();
4537 }
4538
Richard Smithf623c962012-04-17 00:58:00 +00004539 // FIXME: Need to transform the exception-specification too.
4540
John McCall550e0c22009-10-21 00:40:46 +00004541 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004542 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004543 T->getNumParams() != ParamTypes.size() ||
4544 !std::equal(T->param_type_begin(), T->param_type_end(),
4545 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004546 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004547 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004548 if (Result.isNull())
4549 return QualType();
4550 }
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCall550e0c22009-10-21 00:40:46 +00004552 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004553 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004554 NewTL.setLParenLoc(TL.getLParenLoc());
4555 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004556 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004557 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4558 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004559
4560 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004561}
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563template<typename Derived>
4564QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004565 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004566 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004567 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004568 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004569 if (ResultType.isNull())
4570 return QualType();
4571
4572 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004573 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004574 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4575
4576 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004577 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004578 NewTL.setLParenLoc(TL.getLParenLoc());
4579 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004580 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004581
4582 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
John McCallb96ec562009-12-04 22:46:56 +00004585template<typename Derived> QualType
4586TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004587 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004588 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004589 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004590 if (!D)
4591 return QualType();
4592
4593 QualType Result = TL.getType();
4594 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4595 Result = getDerived().RebuildUnresolvedUsingType(D);
4596 if (Result.isNull())
4597 return QualType();
4598 }
4599
4600 // We might get an arbitrary type spec type back. We should at
4601 // least always get a type spec type, though.
4602 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4603 NewTL.setNameLoc(TL.getNameLoc());
4604
4605 return Result;
4606}
4607
Douglas Gregord6ff3322009-08-04 16:50:30 +00004608template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004609QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004610 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004611 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004612 TypedefNameDecl *Typedef
4613 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4614 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004615 if (!Typedef)
4616 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004617
John McCall550e0c22009-10-21 00:40:46 +00004618 QualType Result = TL.getType();
4619 if (getDerived().AlwaysRebuild() ||
4620 Typedef != T->getDecl()) {
4621 Result = getDerived().RebuildTypedefType(Typedef);
4622 if (Result.isNull())
4623 return QualType();
4624 }
Mike Stump11289f42009-09-09 15:08:12 +00004625
John McCall550e0c22009-10-21 00:40:46 +00004626 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4627 NewTL.setNameLoc(TL.getNameLoc());
4628
4629 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004630}
Mike Stump11289f42009-09-09 15:08:12 +00004631
Douglas Gregord6ff3322009-08-04 16:50:30 +00004632template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004633QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004634 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004635 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004636 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4637 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004638
John McCalldadc5752010-08-24 06:29:42 +00004639 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640 if (E.isInvalid())
4641 return QualType();
4642
Eli Friedmane4f22df2012-02-29 04:03:55 +00004643 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4644 if (E.isInvalid())
4645 return QualType();
4646
John McCall550e0c22009-10-21 00:40:46 +00004647 QualType Result = TL.getType();
4648 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004649 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004650 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004651 if (Result.isNull())
4652 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004653 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004654 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004655
John McCall550e0c22009-10-21 00:40:46 +00004656 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004657 NewTL.setTypeofLoc(TL.getTypeofLoc());
4658 NewTL.setLParenLoc(TL.getLParenLoc());
4659 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004660
4661 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662}
Mike Stump11289f42009-09-09 15:08:12 +00004663
4664template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004665QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004666 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004667 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4668 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4669 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004670 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004671
John McCall550e0c22009-10-21 00:40:46 +00004672 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004673 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4674 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004675 if (Result.isNull())
4676 return QualType();
4677 }
Mike Stump11289f42009-09-09 15:08:12 +00004678
John McCall550e0c22009-10-21 00:40:46 +00004679 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004680 NewTL.setTypeofLoc(TL.getTypeofLoc());
4681 NewTL.setLParenLoc(TL.getLParenLoc());
4682 NewTL.setRParenLoc(TL.getRParenLoc());
4683 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004684
4685 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686}
Mike Stump11289f42009-09-09 15:08:12 +00004687
4688template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004689QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004690 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004691 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004692
Douglas Gregore922c772009-08-04 22:27:00 +00004693 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4695 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004696
John McCalldadc5752010-08-24 06:29:42 +00004697 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004698 if (E.isInvalid())
4699 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004700
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004701 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004702 if (E.isInvalid())
4703 return QualType();
4704
John McCall550e0c22009-10-21 00:40:46 +00004705 QualType Result = TL.getType();
4706 if (getDerived().AlwaysRebuild() ||
4707 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004708 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004709 if (Result.isNull())
4710 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004712 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004713
John McCall550e0c22009-10-21 00:40:46 +00004714 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4715 NewTL.setNameLoc(TL.getNameLoc());
4716
4717 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004718}
4719
4720template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004721QualType TreeTransform<Derived>::TransformUnaryTransformType(
4722 TypeLocBuilder &TLB,
4723 UnaryTransformTypeLoc TL) {
4724 QualType Result = TL.getType();
4725 if (Result->isDependentType()) {
4726 const UnaryTransformType *T = TL.getTypePtr();
4727 QualType NewBase =
4728 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4729 Result = getDerived().RebuildUnaryTransformType(NewBase,
4730 T->getUTTKind(),
4731 TL.getKWLoc());
4732 if (Result.isNull())
4733 return QualType();
4734 }
4735
4736 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4737 NewTL.setKWLoc(TL.getKWLoc());
4738 NewTL.setParensRange(TL.getParensRange());
4739 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4740 return Result;
4741}
4742
4743template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004744QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4745 AutoTypeLoc TL) {
4746 const AutoType *T = TL.getTypePtr();
4747 QualType OldDeduced = T->getDeducedType();
4748 QualType NewDeduced;
4749 if (!OldDeduced.isNull()) {
4750 NewDeduced = getDerived().TransformType(OldDeduced);
4751 if (NewDeduced.isNull())
4752 return QualType();
4753 }
4754
4755 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004756 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4757 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004758 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004759 if (Result.isNull())
4760 return QualType();
4761 }
4762
4763 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4764 NewTL.setNameLoc(TL.getNameLoc());
4765
4766 return Result;
4767}
4768
4769template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004770QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004771 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004772 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004773 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004774 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4775 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004776 if (!Record)
4777 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004778
John McCall550e0c22009-10-21 00:40:46 +00004779 QualType Result = TL.getType();
4780 if (getDerived().AlwaysRebuild() ||
4781 Record != T->getDecl()) {
4782 Result = getDerived().RebuildRecordType(Record);
4783 if (Result.isNull())
4784 return QualType();
4785 }
Mike Stump11289f42009-09-09 15:08:12 +00004786
John McCall550e0c22009-10-21 00:40:46 +00004787 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4788 NewTL.setNameLoc(TL.getNameLoc());
4789
4790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004791}
Mike Stump11289f42009-09-09 15:08:12 +00004792
4793template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004794QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004795 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004796 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004797 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004798 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4799 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004800 if (!Enum)
4801 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004802
John McCall550e0c22009-10-21 00:40:46 +00004803 QualType Result = TL.getType();
4804 if (getDerived().AlwaysRebuild() ||
4805 Enum != T->getDecl()) {
4806 Result = getDerived().RebuildEnumType(Enum);
4807 if (Result.isNull())
4808 return QualType();
4809 }
Mike Stump11289f42009-09-09 15:08:12 +00004810
John McCall550e0c22009-10-21 00:40:46 +00004811 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4812 NewTL.setNameLoc(TL.getNameLoc());
4813
4814 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004815}
John McCallfcc33b02009-09-05 00:15:47 +00004816
John McCalle78aac42010-03-10 03:28:59 +00004817template<typename Derived>
4818QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4819 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004820 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004821 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4822 TL.getTypePtr()->getDecl());
4823 if (!D) return QualType();
4824
4825 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4826 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4827 return T;
4828}
4829
Douglas Gregord6ff3322009-08-04 16:50:30 +00004830template<typename Derived>
4831QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004832 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004833 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004834 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004835}
4836
Mike Stump11289f42009-09-09 15:08:12 +00004837template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004838QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004839 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004840 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004841 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004842
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004843 // Substitute into the replacement type, which itself might involve something
4844 // that needs to be transformed. This only tends to occur with default
4845 // template arguments of template template parameters.
4846 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4847 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4848 if (Replacement.isNull())
4849 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004850
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004851 // Always canonicalize the replacement type.
4852 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4853 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004854 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004855 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004856
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004857 // Propagate type-source information.
4858 SubstTemplateTypeParmTypeLoc NewTL
4859 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4860 NewTL.setNameLoc(TL.getNameLoc());
4861 return Result;
4862
John McCallcebee162009-10-18 09:09:24 +00004863}
4864
4865template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004866QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4867 TypeLocBuilder &TLB,
4868 SubstTemplateTypeParmPackTypeLoc TL) {
4869 return TransformTypeSpecType(TLB, TL);
4870}
4871
4872template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004873QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004874 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004875 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004876 const TemplateSpecializationType *T = TL.getTypePtr();
4877
Douglas Gregordf846d12011-03-02 18:46:51 +00004878 // The nested-name-specifier never matters in a TemplateSpecializationType,
4879 // because we can't have a dependent nested-name-specifier anyway.
4880 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004881 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004882 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4883 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004884 if (Template.isNull())
4885 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004886
John McCall31f82722010-11-12 08:19:04 +00004887 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4888}
4889
Eli Friedman0dfb8892011-10-06 23:00:33 +00004890template<typename Derived>
4891QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4892 AtomicTypeLoc TL) {
4893 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4894 if (ValueType.isNull())
4895 return QualType();
4896
4897 QualType Result = TL.getType();
4898 if (getDerived().AlwaysRebuild() ||
4899 ValueType != TL.getValueLoc().getType()) {
4900 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4901 if (Result.isNull())
4902 return QualType();
4903 }
4904
4905 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4906 NewTL.setKWLoc(TL.getKWLoc());
4907 NewTL.setLParenLoc(TL.getLParenLoc());
4908 NewTL.setRParenLoc(TL.getRParenLoc());
4909
4910 return Result;
4911}
4912
Chad Rosier1dcde962012-08-08 18:46:20 +00004913 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004914 /// container that provides a \c getArgLoc() member function.
4915 ///
4916 /// This iterator is intended to be used with the iterator form of
4917 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4918 template<typename ArgLocContainer>
4919 class TemplateArgumentLocContainerIterator {
4920 ArgLocContainer *Container;
4921 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004922
Douglas Gregorfe921a72010-12-20 23:36:19 +00004923 public:
4924 typedef TemplateArgumentLoc value_type;
4925 typedef TemplateArgumentLoc reference;
4926 typedef int difference_type;
4927 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004928
Douglas Gregorfe921a72010-12-20 23:36:19 +00004929 class pointer {
4930 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004931
Douglas Gregorfe921a72010-12-20 23:36:19 +00004932 public:
4933 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004934
Douglas Gregorfe921a72010-12-20 23:36:19 +00004935 const TemplateArgumentLoc *operator->() const {
4936 return &Arg;
4937 }
4938 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004939
4940
Douglas Gregorfe921a72010-12-20 23:36:19 +00004941 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004942
Douglas Gregorfe921a72010-12-20 23:36:19 +00004943 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4944 unsigned Index)
4945 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
Douglas Gregorfe921a72010-12-20 23:36:19 +00004947 TemplateArgumentLocContainerIterator &operator++() {
4948 ++Index;
4949 return *this;
4950 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004951
Douglas Gregorfe921a72010-12-20 23:36:19 +00004952 TemplateArgumentLocContainerIterator operator++(int) {
4953 TemplateArgumentLocContainerIterator Old(*this);
4954 ++(*this);
4955 return Old;
4956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004957
Douglas Gregorfe921a72010-12-20 23:36:19 +00004958 TemplateArgumentLoc operator*() const {
4959 return Container->getArgLoc(Index);
4960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004961
Douglas Gregorfe921a72010-12-20 23:36:19 +00004962 pointer operator->() const {
4963 return pointer(Container->getArgLoc(Index));
4964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
Douglas Gregorfe921a72010-12-20 23:36:19 +00004966 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004967 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004968 return X.Container == Y.Container && X.Index == Y.Index;
4969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004970
Douglas Gregorfe921a72010-12-20 23:36:19 +00004971 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004972 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004973 return !(X == Y);
4974 }
4975 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004976
4977
John McCall31f82722010-11-12 08:19:04 +00004978template <typename Derived>
4979QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4980 TypeLocBuilder &TLB,
4981 TemplateSpecializationTypeLoc TL,
4982 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004983 TemplateArgumentListInfo NewTemplateArgs;
4984 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4985 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004986 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4987 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004988 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004989 ArgIterator(TL, TL.getNumArgs()),
4990 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004991 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004992
John McCall0ad16662009-10-29 08:12:44 +00004993 // FIXME: maybe don't rebuild if all the template arguments are the same.
4994
4995 QualType Result =
4996 getDerived().RebuildTemplateSpecializationType(Template,
4997 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004998 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004999
5000 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005001 // Specializations of template template parameters are represented as
5002 // TemplateSpecializationTypes, and substitution of type alias templates
5003 // within a dependent context can transform them into
5004 // DependentTemplateSpecializationTypes.
5005 if (isa<DependentTemplateSpecializationType>(Result)) {
5006 DependentTemplateSpecializationTypeLoc NewTL
5007 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005008 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005009 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005010 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005011 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005012 NewTL.setLAngleLoc(TL.getLAngleLoc());
5013 NewTL.setRAngleLoc(TL.getRAngleLoc());
5014 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5015 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5016 return Result;
5017 }
5018
John McCall0ad16662009-10-29 08:12:44 +00005019 TemplateSpecializationTypeLoc NewTL
5020 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005021 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005022 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5023 NewTL.setLAngleLoc(TL.getLAngleLoc());
5024 NewTL.setRAngleLoc(TL.getRAngleLoc());
5025 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5026 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005027 }
Mike Stump11289f42009-09-09 15:08:12 +00005028
John McCall0ad16662009-10-29 08:12:44 +00005029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005030}
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregor5a064722011-02-28 17:23:35 +00005032template <typename Derived>
5033QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5034 TypeLocBuilder &TLB,
5035 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005036 TemplateName Template,
5037 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005038 TemplateArgumentListInfo NewTemplateArgs;
5039 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5040 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5041 typedef TemplateArgumentLocContainerIterator<
5042 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005043 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005044 ArgIterator(TL, TL.getNumArgs()),
5045 NewTemplateArgs))
5046 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005047
Douglas Gregor5a064722011-02-28 17:23:35 +00005048 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005049
Douglas Gregor5a064722011-02-28 17:23:35 +00005050 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5051 QualType Result
5052 = getSema().Context.getDependentTemplateSpecializationType(
5053 TL.getTypePtr()->getKeyword(),
5054 DTN->getQualifier(),
5055 DTN->getIdentifier(),
5056 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005057
Douglas Gregor5a064722011-02-28 17:23:35 +00005058 DependentTemplateSpecializationTypeLoc NewTL
5059 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005060 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005061 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005062 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005063 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005064 NewTL.setLAngleLoc(TL.getLAngleLoc());
5065 NewTL.setRAngleLoc(TL.getRAngleLoc());
5066 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5067 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5068 return Result;
5069 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005070
5071 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005072 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005073 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005074 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005075
Douglas Gregor5a064722011-02-28 17:23:35 +00005076 if (!Result.isNull()) {
5077 /// FIXME: Wrap this in an elaborated-type-specifier?
5078 TemplateSpecializationTypeLoc NewTL
5079 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005080 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005081 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005082 NewTL.setLAngleLoc(TL.getLAngleLoc());
5083 NewTL.setRAngleLoc(TL.getRAngleLoc());
5084 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5085 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005087
Douglas Gregor5a064722011-02-28 17:23:35 +00005088 return Result;
5089}
5090
Mike Stump11289f42009-09-09 15:08:12 +00005091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005092QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005093TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005094 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005095 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005096
Douglas Gregor844cb502011-03-01 18:12:44 +00005097 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005098 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005099 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005100 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005101 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5102 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005103 return QualType();
5104 }
Mike Stump11289f42009-09-09 15:08:12 +00005105
John McCall31f82722010-11-12 08:19:04 +00005106 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5107 if (NamedT.isNull())
5108 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005109
Richard Smith3f1b5d02011-05-05 21:57:07 +00005110 // C++0x [dcl.type.elab]p2:
5111 // If the identifier resolves to a typedef-name or the simple-template-id
5112 // resolves to an alias template specialization, the
5113 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005114 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5115 if (const TemplateSpecializationType *TST =
5116 NamedT->getAs<TemplateSpecializationType>()) {
5117 TemplateName Template = TST->getTemplateName();
5118 if (TypeAliasTemplateDecl *TAT =
5119 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5120 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5121 diag::err_tag_reference_non_tag) << 4;
5122 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5123 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005124 }
5125 }
5126
John McCall550e0c22009-10-21 00:40:46 +00005127 QualType Result = TL.getType();
5128 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005129 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005130 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005131 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005132 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005133 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005134 if (Result.isNull())
5135 return QualType();
5136 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005137
Abramo Bagnara6150c882010-05-11 21:36:43 +00005138 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005139 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005140 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005141 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005142}
Mike Stump11289f42009-09-09 15:08:12 +00005143
5144template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005145QualType TreeTransform<Derived>::TransformAttributedType(
5146 TypeLocBuilder &TLB,
5147 AttributedTypeLoc TL) {
5148 const AttributedType *oldType = TL.getTypePtr();
5149 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5150 if (modifiedType.isNull())
5151 return QualType();
5152
5153 QualType result = TL.getType();
5154
5155 // FIXME: dependent operand expressions?
5156 if (getDerived().AlwaysRebuild() ||
5157 modifiedType != oldType->getModifiedType()) {
5158 // TODO: this is really lame; we should really be rebuilding the
5159 // equivalent type from first principles.
5160 QualType equivalentType
5161 = getDerived().TransformType(oldType->getEquivalentType());
5162 if (equivalentType.isNull())
5163 return QualType();
5164 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5165 modifiedType,
5166 equivalentType);
5167 }
5168
5169 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5170 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5171 if (TL.hasAttrOperand())
5172 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5173 if (TL.hasAttrExprOperand())
5174 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5175 else if (TL.hasAttrEnumOperand())
5176 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5177
5178 return result;
5179}
5180
5181template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005182QualType
5183TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5184 ParenTypeLoc TL) {
5185 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5186 if (Inner.isNull())
5187 return QualType();
5188
5189 QualType Result = TL.getType();
5190 if (getDerived().AlwaysRebuild() ||
5191 Inner != TL.getInnerLoc().getType()) {
5192 Result = getDerived().RebuildParenType(Inner);
5193 if (Result.isNull())
5194 return QualType();
5195 }
5196
5197 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5198 NewTL.setLParenLoc(TL.getLParenLoc());
5199 NewTL.setRParenLoc(TL.getRParenLoc());
5200 return Result;
5201}
5202
5203template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005204QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005205 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005206 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005207
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005208 NestedNameSpecifierLoc QualifierLoc
5209 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5210 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005211 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005212
John McCallc392f372010-06-11 00:33:02 +00005213 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005214 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005215 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005216 QualifierLoc,
5217 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005218 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005219 if (Result.isNull())
5220 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221
Abramo Bagnarad7548482010-05-19 21:37:53 +00005222 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5223 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005224 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5225
Abramo Bagnarad7548482010-05-19 21:37:53 +00005226 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005227 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005228 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005229 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005230 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005231 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005232 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005233 NewTL.setNameLoc(TL.getNameLoc());
5234 }
John McCall550e0c22009-10-21 00:40:46 +00005235 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005236}
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005239QualType TreeTransform<Derived>::
5240 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005241 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005242 NestedNameSpecifierLoc QualifierLoc;
5243 if (TL.getQualifierLoc()) {
5244 QualifierLoc
5245 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5246 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005247 return QualType();
5248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005249
John McCall31f82722010-11-12 08:19:04 +00005250 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005251 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005252}
5253
5254template<typename Derived>
5255QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005256TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5257 DependentTemplateSpecializationTypeLoc TL,
5258 NestedNameSpecifierLoc QualifierLoc) {
5259 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005260
Douglas Gregora7a795b2011-03-01 20:11:18 +00005261 TemplateArgumentListInfo NewTemplateArgs;
5262 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5263 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
Douglas Gregora7a795b2011-03-01 20:11:18 +00005265 typedef TemplateArgumentLocContainerIterator<
5266 DependentTemplateSpecializationTypeLoc> ArgIterator;
5267 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5268 ArgIterator(TL, TL.getNumArgs()),
5269 NewTemplateArgs))
5270 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005271
Douglas Gregora7a795b2011-03-01 20:11:18 +00005272 QualType Result
5273 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5274 QualifierLoc,
5275 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005276 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005277 NewTemplateArgs);
5278 if (Result.isNull())
5279 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005280
Douglas Gregora7a795b2011-03-01 20:11:18 +00005281 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5282 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005283
Douglas Gregora7a795b2011-03-01 20:11:18 +00005284 // Copy information relevant to the template specialization.
5285 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005286 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005287 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005288 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005289 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5290 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005291 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005292 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005293
Douglas Gregora7a795b2011-03-01 20:11:18 +00005294 // Copy information relevant to the elaborated type.
5295 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005296 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005297 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005298 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5299 DependentTemplateSpecializationTypeLoc SpecTL
5300 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005301 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005302 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005303 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005304 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005305 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5306 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005307 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005308 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005309 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005310 TemplateSpecializationTypeLoc SpecTL
5311 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005312 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005313 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005314 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5315 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005316 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005317 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005318 }
5319 return Result;
5320}
5321
5322template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005323QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5324 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005325 QualType Pattern
5326 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005327 if (Pattern.isNull())
5328 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005329
5330 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005331 if (getDerived().AlwaysRebuild() ||
5332 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005333 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005334 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005335 TL.getEllipsisLoc(),
5336 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005337 if (Result.isNull())
5338 return QualType();
5339 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005340
Douglas Gregor822d0302011-01-12 17:07:58 +00005341 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5342 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5343 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005344}
5345
5346template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005347QualType
5348TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005349 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005350 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005351 TLB.pushFullCopy(TL);
5352 return TL.getType();
5353}
5354
5355template<typename Derived>
5356QualType
5357TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005358 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005359 // ObjCObjectType is never dependent.
5360 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005361 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362}
Mike Stump11289f42009-09-09 15:08:12 +00005363
5364template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005365QualType
5366TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005367 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005368 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005369 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005370 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005371}
5372
Douglas Gregord6ff3322009-08-04 16:50:30 +00005373//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005374// Statement transformation
5375//===----------------------------------------------------------------------===//
5376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005378TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005379 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005380}
5381
5382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005383StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005384TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5385 return getDerived().TransformCompoundStmt(S, false);
5386}
5387
5388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005389StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005390TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005391 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005392 Sema::CompoundScopeRAII CompoundScope(getSema());
5393
John McCall1ababa62010-08-27 19:56:05 +00005394 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005395 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005396 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005397 for (auto *B : S->body()) {
5398 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005399 if (Result.isInvalid()) {
5400 // Immediately fail if this was a DeclStmt, since it's very
5401 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005402 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005403 return StmtError();
5404
5405 // Otherwise, just keep processing substatements and fail later.
5406 SubStmtInvalid = true;
5407 continue;
5408 }
Mike Stump11289f42009-09-09 15:08:12 +00005409
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005410 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005411 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005412 }
Mike Stump11289f42009-09-09 15:08:12 +00005413
John McCall1ababa62010-08-27 19:56:05 +00005414 if (SubStmtInvalid)
5415 return StmtError();
5416
Douglas Gregorebe10102009-08-20 07:17:43 +00005417 if (!getDerived().AlwaysRebuild() &&
5418 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005419 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005420
5421 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005422 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005423 S->getRBracLoc(),
5424 IsStmtExpr);
5425}
Mike Stump11289f42009-09-09 15:08:12 +00005426
Douglas Gregorebe10102009-08-20 07:17:43 +00005427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005428StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005429TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005430 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005431 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005432 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5433 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005434
Eli Friedman06577382009-11-19 03:14:00 +00005435 // Transform the left-hand case value.
5436 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005437 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005438 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005439 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005440
Eli Friedman06577382009-11-19 03:14:00 +00005441 // Transform the right-hand case value (for the GNU case-range extension).
5442 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005443 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005444 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005445 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005446 }
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregorebe10102009-08-20 07:17:43 +00005448 // Build the case statement.
5449 // Case statements are always rebuilt so that they will attached to their
5450 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005451 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005452 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005453 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005454 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005455 S->getColonLoc());
5456 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregorebe10102009-08-20 07:17:43 +00005459 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005460 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005461 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005462 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregorebe10102009-08-20 07:17:43 +00005464 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005465 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005466}
5467
5468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005469StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005470TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005471 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005472 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005473 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005474 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregorebe10102009-08-20 07:17:43 +00005476 // Default statements are always rebuilt
5477 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005478 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005479}
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorebe10102009-08-20 07:17:43 +00005481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005482StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005483TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005484 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005487
Chris Lattnercab02a62011-02-17 20:34:02 +00005488 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5489 S->getDecl());
5490 if (!LD)
5491 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005492
5493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005495 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005496 cast<LabelDecl>(LD), SourceLocation(),
5497 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005498}
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregorebe10102009-08-20 07:17:43 +00005500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005501StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005502TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5503 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5504 if (SubStmt.isInvalid())
5505 return StmtError();
5506
5507 // TODO: transform attributes
5508 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5509 return S;
5510
5511 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5512 S->getAttrs(),
5513 SubStmt.get());
5514}
5515
5516template<typename Derived>
5517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005519 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005520 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005521 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005522 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005523 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005524 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005525 getDerived().TransformDefinition(
5526 S->getConditionVariable()->getLocation(),
5527 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005528 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005529 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005530 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005531 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005532
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005533 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005534 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005535
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005536 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005537 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005538 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005539 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005540 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
John McCallb268a282010-08-23 23:25:46 +00005543 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005544 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005546
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005547 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005548 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005550
Douglas Gregorebe10102009-08-20 07:17:43 +00005551 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005552 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005553 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005555
Douglas Gregorebe10102009-08-20 07:17:43 +00005556 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005557 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005558 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005559 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregorebe10102009-08-20 07:17:43 +00005561 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005562 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005563 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 Then.get() == S->getThen() &&
5565 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005566 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005568 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005569 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005570 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005571}
5572
5573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005574StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005575TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005576 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005577 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005578 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005579 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005580 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005581 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005582 getDerived().TransformDefinition(
5583 S->getConditionVariable()->getLocation(),
5584 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005585 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005587 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005588 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005589
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005590 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005592 }
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregorebe10102009-08-20 07:17:43 +00005594 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005595 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005596 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005597 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005599 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005602 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005607 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5608 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005609}
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregorebe10102009-08-20 07:17:43 +00005611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005612StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005613TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005615 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005616 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005617 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005618 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005619 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005620 getDerived().TransformDefinition(
5621 S->getConditionVariable()->getLocation(),
5622 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005623 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005624 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005625 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005626 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005627
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005628 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005629 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005630
5631 if (S->getCond()) {
5632 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005633 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5634 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005635 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005636 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005638 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005639 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005640 }
Mike Stump11289f42009-09-09 15:08:12 +00005641
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005642 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005643 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005645
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005647 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005648 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005649 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005650
Douglas Gregorebe10102009-08-20 07:17:43 +00005651 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005652 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005653 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005654 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005655 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005657 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005658 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005659}
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregorebe10102009-08-20 07:17:43 +00005661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005662StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005663TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005664 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005665 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005667 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005669 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005670 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005671 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005672 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005673
Douglas Gregorebe10102009-08-20 07:17:43 +00005674 if (!getDerived().AlwaysRebuild() &&
5675 Cond.get() == S->getCond() &&
5676 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005677 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005678
John McCallb268a282010-08-23 23:25:46 +00005679 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5680 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005681 S->getRParenLoc());
5682}
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005685StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005686TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005687 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005688 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005693 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005694 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005695 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005696 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005697 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005698 getDerived().TransformDefinition(
5699 S->getConditionVariable()->getLocation(),
5700 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005701 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005703 } else {
5704 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005705
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005706 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005707 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005708
5709 if (S->getCond()) {
5710 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005711 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5712 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005713 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005714 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005715 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005716
John McCallb268a282010-08-23 23:25:46 +00005717 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005718 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005719 }
Mike Stump11289f42009-09-09 15:08:12 +00005720
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005721 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005722 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005723 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005724
Douglas Gregorebe10102009-08-20 07:17:43 +00005725 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005726 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005727 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005728 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005729
Richard Smith945f8d32013-01-14 22:39:08 +00005730 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005731 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005732 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005733
Douglas Gregorebe10102009-08-20 07:17:43 +00005734 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005735 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005736 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005737 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005738
Douglas Gregorebe10102009-08-20 07:17:43 +00005739 if (!getDerived().AlwaysRebuild() &&
5740 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005741 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005742 Inc.get() == S->getInc() &&
5743 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005744 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregorebe10102009-08-20 07:17:43 +00005746 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005747 Init.get(), FullCond, ConditionVar,
5748 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005749}
5750
5751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005752StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005753TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005754 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5755 S->getLabel());
5756 if (!LD)
5757 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005758
Douglas Gregorebe10102009-08-20 07:17:43 +00005759 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005760 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005761 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005762}
5763
5764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005765StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005766TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005767 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005768 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005769 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005770 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005771
Douglas Gregorebe10102009-08-20 07:17:43 +00005772 if (!getDerived().AlwaysRebuild() &&
5773 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005774 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005775
5776 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005777 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005778}
5779
5780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005781StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005782TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005783 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005784}
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregorebe10102009-08-20 07:17:43 +00005786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005788TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005789 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005790}
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregorebe10102009-08-20 07:17:43 +00005792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005793StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005794TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005795 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005796 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005797 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005798
Mike Stump11289f42009-09-09 15:08:12 +00005799 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005800 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005801 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005802}
Mike Stump11289f42009-09-09 15:08:12 +00005803
Douglas Gregorebe10102009-08-20 07:17:43 +00005804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005805StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005806TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005807 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005808 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005809 for (auto *D : S->decls()) {
5810 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005811 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005812 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005813
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005814 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005815 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregorebe10102009-08-20 07:17:43 +00005817 Decls.push_back(Transformed);
5818 }
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregorebe10102009-08-20 07:17:43 +00005820 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005821 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005822
Rafael Espindolaab417692013-07-09 12:05:01 +00005823 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005824}
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregorebe10102009-08-20 07:17:43 +00005826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005827StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005828TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005829
Benjamin Kramerf0623432012-08-23 22:51:59 +00005830 SmallVector<Expr*, 8> Constraints;
5831 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005832 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005833
John McCalldadc5752010-08-24 06:29:42 +00005834 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005835 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005836
5837 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Anders Carlssonaaeef072010-01-24 05:50:09 +00005839 // Go through the outputs.
5840 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005841 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005842
Anders Carlssonaaeef072010-01-24 05:50:09 +00005843 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005844 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005845
Anders Carlssonaaeef072010-01-24 05:50:09 +00005846 // Transform the output expr.
5847 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005848 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005849 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005850 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005851
Anders Carlssonaaeef072010-01-24 05:50:09 +00005852 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005853
John McCallb268a282010-08-23 23:25:46 +00005854 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005856
Anders Carlssonaaeef072010-01-24 05:50:09 +00005857 // Go through the inputs.
5858 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005859 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005860
Anders Carlssonaaeef072010-01-24 05:50:09 +00005861 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005862 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Anders Carlssonaaeef072010-01-24 05:50:09 +00005864 // Transform the input expr.
5865 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005866 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005867 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005869
Anders Carlssonaaeef072010-01-24 05:50:09 +00005870 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
John McCallb268a282010-08-23 23:25:46 +00005872 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
Anders Carlssonaaeef072010-01-24 05:50:09 +00005875 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005876 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005877
5878 // Go through the clobbers.
5879 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005880 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005881
5882 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005883 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005884 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5885 S->isVolatile(), S->getNumOutputs(),
5886 S->getNumInputs(), Names.data(),
5887 Constraints, Exprs, AsmString.get(),
5888 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005889}
5890
Chad Rosier32503022012-06-11 20:47:18 +00005891template<typename Derived>
5892StmtResult
5893TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005894 ArrayRef<Token> AsmToks =
5895 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005896
John McCallf413f5e2013-05-03 00:10:13 +00005897 bool HadError = false, HadChange = false;
5898
5899 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5900 SmallVector<Expr*, 8> TransformedExprs;
5901 TransformedExprs.reserve(SrcExprs.size());
5902 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5903 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5904 if (!Result.isUsable()) {
5905 HadError = true;
5906 } else {
5907 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005908 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005909 }
5910 }
5911
5912 if (HadError) return StmtError();
5913 if (!HadChange && !getDerived().AlwaysRebuild())
5914 return Owned(S);
5915
Chad Rosierb6f46c12012-08-15 16:53:30 +00005916 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005917 AsmToks, S->getAsmString(),
5918 S->getNumOutputs(), S->getNumInputs(),
5919 S->getAllConstraints(), S->getClobbers(),
5920 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005921}
Douglas Gregorebe10102009-08-20 07:17:43 +00005922
5923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005924StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005925TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005926 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005927 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005928 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005930
Douglas Gregor96c79492010-04-23 22:50:49 +00005931 // Transform the @catch statements (if present).
5932 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005933 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005934 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005935 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005936 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005938 if (Catch.get() != S->getCatchStmt(I))
5939 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005940 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005941 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005942
Douglas Gregor306de2f2010-04-22 23:59:56 +00005943 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005944 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005945 if (S->getFinallyStmt()) {
5946 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5947 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005948 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005949 }
5950
5951 // If nothing changed, just retain this statement.
5952 if (!getDerived().AlwaysRebuild() &&
5953 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005954 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005955 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005956 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005957
Douglas Gregor306de2f2010-04-22 23:59:56 +00005958 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005959 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005960 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005961}
Mike Stump11289f42009-09-09 15:08:12 +00005962
Douglas Gregorebe10102009-08-20 07:17:43 +00005963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005964StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005965TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005966 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005967 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005968 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005969 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005970 if (FromVar->getTypeSourceInfo()) {
5971 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5972 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005973 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005975
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005976 QualType T;
5977 if (TSInfo)
5978 T = TSInfo->getType();
5979 else {
5980 T = getDerived().TransformType(FromVar->getType());
5981 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005982 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005984
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005985 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5986 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
John McCalldadc5752010-08-24 06:29:42 +00005990 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005991 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005992 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005993
5994 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005995 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005996 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005997}
Mike Stump11289f42009-09-09 15:08:12 +00005998
Douglas Gregorebe10102009-08-20 07:17:43 +00005999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006000StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006001TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006002 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006003 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006004 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006006
Douglas Gregor306de2f2010-04-22 23:59:56 +00006007 // If nothing changed, just retain this statement.
6008 if (!getDerived().AlwaysRebuild() &&
6009 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006010 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006011
6012 // Build a new statement.
6013 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006014 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006015}
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregorebe10102009-08-20 07:17:43 +00006017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006018StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006019TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006020 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006021 if (S->getThrowExpr()) {
6022 Operand = getDerived().TransformExpr(S->getThrowExpr());
6023 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006025 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006026
Douglas Gregor2900c162010-04-22 21:44:01 +00006027 if (!getDerived().AlwaysRebuild() &&
6028 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006029 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006030
John McCallb268a282010-08-23 23:25:46 +00006031 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006032}
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregorebe10102009-08-20 07:17:43 +00006034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006035StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006036TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006037 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006038 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006039 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006040 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006042 Object =
6043 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6044 Object.get());
6045 if (Object.isInvalid())
6046 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006047
Douglas Gregor6148de72010-04-22 22:01:21 +00006048 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006049 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006050 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006052
Douglas Gregor6148de72010-04-22 22:01:21 +00006053 // If nothing change, just retain the current statement.
6054 if (!getDerived().AlwaysRebuild() &&
6055 Object.get() == S->getSynchExpr() &&
6056 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006057 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006058
6059 // Build a new statement.
6060 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006061 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006062}
6063
6064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006065StmtResult
John McCall31168b02011-06-15 23:02:42 +00006066TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6067 ObjCAutoreleasePoolStmt *S) {
6068 // Transform the body.
6069 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6070 if (Body.isInvalid())
6071 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006072
John McCall31168b02011-06-15 23:02:42 +00006073 // If nothing changed, just retain this statement.
6074 if (!getDerived().AlwaysRebuild() &&
6075 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006076 return S;
John McCall31168b02011-06-15 23:02:42 +00006077
6078 // Build a new statement.
6079 return getDerived().RebuildObjCAutoreleasePoolStmt(
6080 S->getAtLoc(), Body.get());
6081}
6082
6083template<typename Derived>
6084StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006085TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006086 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006087 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006088 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006089 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006090 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006091
Douglas Gregorf68a5082010-04-22 23:10:45 +00006092 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006093 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006094 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006096
Douglas Gregorf68a5082010-04-22 23:10:45 +00006097 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006098 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006099 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006100 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006101
Douglas Gregorf68a5082010-04-22 23:10:45 +00006102 // If nothing changed, just retain this statement.
6103 if (!getDerived().AlwaysRebuild() &&
6104 Element.get() == S->getElement() &&
6105 Collection.get() == S->getCollection() &&
6106 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006107 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006108
Douglas Gregorf68a5082010-04-22 23:10:45 +00006109 // Build a new statement.
6110 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006111 Element.get(),
6112 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006113 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006114 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006115}
6116
David Majnemer5f7efef2013-10-15 09:50:08 +00006117template <typename Derived>
6118StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006119 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006120 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006121 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6122 TypeSourceInfo *T =
6123 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006124 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006126
David Majnemer5f7efef2013-10-15 09:50:08 +00006127 Var = getDerived().RebuildExceptionDecl(
6128 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6129 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006130 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006131 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006132 }
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregorebe10102009-08-20 07:17:43 +00006134 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006135 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006136 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006137 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006138
David Majnemer5f7efef2013-10-15 09:50:08 +00006139 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006140 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006141 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006142
David Majnemer5f7efef2013-10-15 09:50:08 +00006143 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006144}
Mike Stump11289f42009-09-09 15:08:12 +00006145
David Majnemer5f7efef2013-10-15 09:50:08 +00006146template <typename Derived>
6147StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006148 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006149 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006150 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006151 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006152
Douglas Gregorebe10102009-08-20 07:17:43 +00006153 // Transform the handlers.
6154 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006155 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006156 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006157 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006158 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006162 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006163 }
Mike Stump11289f42009-09-09 15:08:12 +00006164
David Majnemer5f7efef2013-10-15 09:50:08 +00006165 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006167 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006168
John McCallb268a282010-08-23 23:25:46 +00006169 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006170 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006171}
Mike Stump11289f42009-09-09 15:08:12 +00006172
Richard Smith02e85f32011-04-14 22:09:26 +00006173template<typename Derived>
6174StmtResult
6175TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6176 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6177 if (Range.isInvalid())
6178 return StmtError();
6179
6180 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6181 if (BeginEnd.isInvalid())
6182 return StmtError();
6183
6184 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6185 if (Cond.isInvalid())
6186 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006187 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006188 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006189 if (Cond.isInvalid())
6190 return StmtError();
6191 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006192 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006193
6194 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6195 if (Inc.isInvalid())
6196 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006197 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006198 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006199
6200 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6201 if (LoopVar.isInvalid())
6202 return StmtError();
6203
6204 StmtResult NewStmt = S;
6205 if (getDerived().AlwaysRebuild() ||
6206 Range.get() != S->getRangeStmt() ||
6207 BeginEnd.get() != S->getBeginEndStmt() ||
6208 Cond.get() != S->getCond() ||
6209 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006210 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006211 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6212 S->getColonLoc(), Range.get(),
6213 BeginEnd.get(), Cond.get(),
6214 Inc.get(), LoopVar.get(),
6215 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006216 if (NewStmt.isInvalid())
6217 return StmtError();
6218 }
Richard Smith02e85f32011-04-14 22:09:26 +00006219
6220 StmtResult Body = getDerived().TransformStmt(S->getBody());
6221 if (Body.isInvalid())
6222 return StmtError();
6223
6224 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6225 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006226 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006227 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6228 S->getColonLoc(), Range.get(),
6229 BeginEnd.get(), Cond.get(),
6230 Inc.get(), LoopVar.get(),
6231 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006232 if (NewStmt.isInvalid())
6233 return StmtError();
6234 }
Richard Smith02e85f32011-04-14 22:09:26 +00006235
6236 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006237 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006238
6239 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6240}
6241
John Wiegley1c0675e2011-04-28 01:08:34 +00006242template<typename Derived>
6243StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006244TreeTransform<Derived>::TransformMSDependentExistsStmt(
6245 MSDependentExistsStmt *S) {
6246 // Transform the nested-name-specifier, if any.
6247 NestedNameSpecifierLoc QualifierLoc;
6248 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006249 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006250 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6251 if (!QualifierLoc)
6252 return StmtError();
6253 }
6254
6255 // Transform the declaration name.
6256 DeclarationNameInfo NameInfo = S->getNameInfo();
6257 if (NameInfo.getName()) {
6258 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6259 if (!NameInfo.getName())
6260 return StmtError();
6261 }
6262
6263 // Check whether anything changed.
6264 if (!getDerived().AlwaysRebuild() &&
6265 QualifierLoc == S->getQualifierLoc() &&
6266 NameInfo.getName() == S->getNameInfo().getName())
6267 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006268
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006269 // Determine whether this name exists, if we can.
6270 CXXScopeSpec SS;
6271 SS.Adopt(QualifierLoc);
6272 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006273 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006274 case Sema::IER_Exists:
6275 if (S->isIfExists())
6276 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006277
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006278 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6279
6280 case Sema::IER_DoesNotExist:
6281 if (S->isIfNotExists())
6282 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006283
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006284 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006285
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006286 case Sema::IER_Dependent:
6287 Dependent = true;
6288 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006289
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006290 case Sema::IER_Error:
6291 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006292 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006293
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006294 // We need to continue with the instantiation, so do so now.
6295 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6296 if (SubStmt.isInvalid())
6297 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006298
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006299 // If we have resolved the name, just transform to the substatement.
6300 if (!Dependent)
6301 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006302
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006303 // The name is still dependent, so build a dependent expression again.
6304 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6305 S->isIfExists(),
6306 QualifierLoc,
6307 NameInfo,
6308 SubStmt.get());
6309}
6310
6311template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006312ExprResult
6313TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6314 NestedNameSpecifierLoc QualifierLoc;
6315 if (E->getQualifierLoc()) {
6316 QualifierLoc
6317 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6318 if (!QualifierLoc)
6319 return ExprError();
6320 }
6321
6322 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6323 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6324 if (!PD)
6325 return ExprError();
6326
6327 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6328 if (Base.isInvalid())
6329 return ExprError();
6330
6331 return new (SemaRef.getASTContext())
6332 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6333 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6334 QualifierLoc, E->getMemberLoc());
6335}
6336
David Majnemerfad8f482013-10-15 09:33:02 +00006337template <typename Derived>
6338StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006339 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006340 if (TryBlock.isInvalid())
6341 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006342
6343 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006344 if (Handler.isInvalid())
6345 return StmtError();
6346
David Majnemerfad8f482013-10-15 09:33:02 +00006347 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6348 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006349 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006350
David Majnemerfad8f482013-10-15 09:33:02 +00006351 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006352 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006353}
6354
David Majnemerfad8f482013-10-15 09:33:02 +00006355template <typename Derived>
6356StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006357 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006358 if (Block.isInvalid())
6359 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006360
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006361 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006362}
6363
David Majnemerfad8f482013-10-15 09:33:02 +00006364template <typename Derived>
6365StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006366 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006367 if (FilterExpr.isInvalid())
6368 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006369
David Majnemer7e755502013-10-15 09:30:14 +00006370 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006371 if (Block.isInvalid())
6372 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006373
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006374 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6375 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006376}
6377
David Majnemerfad8f482013-10-15 09:33:02 +00006378template <typename Derived>
6379StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6380 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006381 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6382 else
6383 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6384}
6385
Nico Weber9b982072014-07-07 00:12:30 +00006386template<typename Derived>
6387StmtResult
6388TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6389 return S;
6390}
6391
Alexander Musman64d33f12014-06-04 07:53:32 +00006392//===----------------------------------------------------------------------===//
6393// OpenMP directive transformation
6394//===----------------------------------------------------------------------===//
6395template <typename Derived>
6396StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6397 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006398
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006399 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006400 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006401 ArrayRef<OMPClause *> Clauses = D->clauses();
6402 TClauses.reserve(Clauses.size());
6403 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6404 I != E; ++I) {
6405 if (*I) {
6406 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006407 if (Clause)
6408 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006409 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006410 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006411 }
6412 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006413 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006414 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006415 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006416 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006417 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataevc5e02582014-06-16 07:08:35 +00006418 if (AssociatedStmt.isInvalid() || TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006419 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006420 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006421
Alexander Musman64d33f12014-06-04 07:53:32 +00006422 return getDerived().RebuildOMPExecutableDirective(
6423 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6424 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006425}
6426
Alexander Musman64d33f12014-06-04 07:53:32 +00006427template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006428StmtResult
6429TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6430 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006431 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6432 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006433 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6434 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6435 return Res;
6436}
6437
Alexander Musman64d33f12014-06-04 07:53:32 +00006438template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006439StmtResult
6440TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6441 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006442 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6443 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006444 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6445 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006446 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006447}
6448
Alexey Bataevf29276e2014-06-18 04:14:57 +00006449template <typename Derived>
6450StmtResult
6451TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6452 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006453 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6454 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006455 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6456 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6457 return Res;
6458}
6459
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006460template <typename Derived>
6461StmtResult
6462TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6463 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006464 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6465 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006466 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6467 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6468 return Res;
6469}
6470
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006471template <typename Derived>
6472StmtResult
6473TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6474 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006475 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6476 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006477 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6478 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6479 return Res;
6480}
6481
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006482template <typename Derived>
6483StmtResult
6484TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6485 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006486 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6487 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006488 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6489 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6490 return Res;
6491}
6492
Alexey Bataev4acb8592014-07-07 13:01:15 +00006493template <typename Derived>
6494StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6495 OMPParallelForDirective *D) {
6496 DeclarationNameInfo DirName;
6497 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6498 nullptr, D->getLocStart());
6499 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6500 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6501 return Res;
6502}
6503
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006504template <typename Derived>
6505StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6506 OMPParallelSectionsDirective *D) {
6507 DeclarationNameInfo DirName;
6508 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6509 nullptr, D->getLocStart());
6510 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6511 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6512 return Res;
6513}
6514
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006515template <typename Derived>
6516StmtResult
6517TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6518 DeclarationNameInfo DirName;
6519 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6520 D->getLocStart());
6521 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6522 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6523 return Res;
6524}
6525
Alexander Musman64d33f12014-06-04 07:53:32 +00006526//===----------------------------------------------------------------------===//
6527// OpenMP clause transformation
6528//===----------------------------------------------------------------------===//
6529template <typename Derived>
6530OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006531 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6532 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006533 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006534 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006535 C->getLParenLoc(), C->getLocEnd());
6536}
6537
Alexander Musman64d33f12014-06-04 07:53:32 +00006538template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006539OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006540TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6541 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6542 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006543 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006544 return getDerived().RebuildOMPNumThreadsClause(
6545 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006546}
6547
Alexey Bataev62c87d22014-03-21 04:51:18 +00006548template <typename Derived>
6549OMPClause *
6550TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6551 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6552 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006553 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006554 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006555 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006556}
6557
Alexander Musman8bd31e62014-05-27 15:12:19 +00006558template <typename Derived>
6559OMPClause *
6560TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6561 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6562 if (E.isInvalid())
6563 return 0;
6564 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006565 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006566}
6567
Alexander Musman64d33f12014-06-04 07:53:32 +00006568template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006569OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006570TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006571 return getDerived().RebuildOMPDefaultClause(
6572 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6573 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006574}
6575
Alexander Musman64d33f12014-06-04 07:53:32 +00006576template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006577OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006578TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006579 return getDerived().RebuildOMPProcBindClause(
6580 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6581 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006582}
6583
Alexander Musman64d33f12014-06-04 07:53:32 +00006584template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006585OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006586TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6587 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6588 if (E.isInvalid())
6589 return nullptr;
6590 return getDerived().RebuildOMPScheduleClause(
6591 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6592 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6593}
6594
6595template <typename Derived>
6596OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006597TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6598 // No need to rebuild this clause, no template-dependent parameters.
6599 return C;
6600}
6601
6602template <typename Derived>
6603OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006604TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6605 // No need to rebuild this clause, no template-dependent parameters.
6606 return C;
6607}
6608
6609template <typename Derived>
6610OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006611TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006612 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006613 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006614 for (auto *VE : C->varlists()) {
6615 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006616 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006617 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006618 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006619 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006620 return getDerived().RebuildOMPPrivateClause(
6621 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006622}
6623
Alexander Musman64d33f12014-06-04 07:53:32 +00006624template <typename Derived>
6625OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6626 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006627 llvm::SmallVector<Expr *, 16> Vars;
6628 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006629 for (auto *VE : C->varlists()) {
6630 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006631 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006632 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006633 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006634 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006635 return getDerived().RebuildOMPFirstprivateClause(
6636 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006637}
6638
Alexander Musman64d33f12014-06-04 07:53:32 +00006639template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006640OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006641TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6642 llvm::SmallVector<Expr *, 16> Vars;
6643 Vars.reserve(C->varlist_size());
6644 for (auto *VE : C->varlists()) {
6645 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6646 if (EVar.isInvalid())
6647 return nullptr;
6648 Vars.push_back(EVar.get());
6649 }
6650 return getDerived().RebuildOMPLastprivateClause(
6651 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6652}
6653
6654template <typename Derived>
6655OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006656TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6657 llvm::SmallVector<Expr *, 16> Vars;
6658 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006659 for (auto *VE : C->varlists()) {
6660 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006661 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006662 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006663 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006664 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006665 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6666 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006667}
6668
Alexander Musman64d33f12014-06-04 07:53:32 +00006669template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006670OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006671TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6672 llvm::SmallVector<Expr *, 16> Vars;
6673 Vars.reserve(C->varlist_size());
6674 for (auto *VE : C->varlists()) {
6675 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6676 if (EVar.isInvalid())
6677 return nullptr;
6678 Vars.push_back(EVar.get());
6679 }
6680 CXXScopeSpec ReductionIdScopeSpec;
6681 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6682
6683 DeclarationNameInfo NameInfo = C->getNameInfo();
6684 if (NameInfo.getName()) {
6685 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6686 if (!NameInfo.getName())
6687 return nullptr;
6688 }
6689 return getDerived().RebuildOMPReductionClause(
6690 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6691 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6692}
6693
6694template <typename Derived>
6695OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006696TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6697 llvm::SmallVector<Expr *, 16> Vars;
6698 Vars.reserve(C->varlist_size());
6699 for (auto *VE : C->varlists()) {
6700 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6701 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006702 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006703 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006704 }
6705 ExprResult Step = getDerived().TransformExpr(C->getStep());
6706 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006707 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006708 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6709 C->getLParenLoc(),
6710 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006711}
6712
Alexander Musman64d33f12014-06-04 07:53:32 +00006713template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006714OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006715TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6716 llvm::SmallVector<Expr *, 16> Vars;
6717 Vars.reserve(C->varlist_size());
6718 for (auto *VE : C->varlists()) {
6719 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6720 if (EVar.isInvalid())
6721 return nullptr;
6722 Vars.push_back(EVar.get());
6723 }
6724 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6725 if (Alignment.isInvalid())
6726 return nullptr;
6727 return getDerived().RebuildOMPAlignedClause(
6728 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6729 C->getColonLoc(), C->getLocEnd());
6730}
6731
Alexander Musman64d33f12014-06-04 07:53:32 +00006732template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006733OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006734TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6735 llvm::SmallVector<Expr *, 16> Vars;
6736 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006737 for (auto *VE : C->varlists()) {
6738 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006739 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006740 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006741 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006742 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006743 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6744 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006745}
6746
Alexey Bataevbae9a792014-06-27 10:37:06 +00006747template <typename Derived>
6748OMPClause *
6749TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6750 llvm::SmallVector<Expr *, 16> Vars;
6751 Vars.reserve(C->varlist_size());
6752 for (auto *VE : C->varlists()) {
6753 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6754 if (EVar.isInvalid())
6755 return nullptr;
6756 Vars.push_back(EVar.get());
6757 }
6758 return getDerived().RebuildOMPCopyprivateClause(
6759 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6760}
6761
Douglas Gregorebe10102009-08-20 07:17:43 +00006762//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006763// Expression transformation
6764//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006766ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006767TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006768 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006769}
Mike Stump11289f42009-09-09 15:08:12 +00006770
6771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006772ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006773TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006774 NestedNameSpecifierLoc QualifierLoc;
6775 if (E->getQualifierLoc()) {
6776 QualifierLoc
6777 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6778 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006779 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006780 }
John McCallce546572009-12-08 09:08:17 +00006781
6782 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006783 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6784 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006787
John McCall815039a2010-08-17 21:27:17 +00006788 DeclarationNameInfo NameInfo = E->getNameInfo();
6789 if (NameInfo.getName()) {
6790 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6791 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006793 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006794
6795 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006796 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006797 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006798 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006799 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006800
6801 // Mark it referenced in the new context regardless.
6802 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006803 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006804
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006805 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006806 }
John McCallce546572009-12-08 09:08:17 +00006807
Craig Topperc3ec1492014-05-26 06:22:03 +00006808 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006809 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006810 TemplateArgs = &TransArgs;
6811 TransArgs.setLAngleLoc(E->getLAngleLoc());
6812 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006813 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6814 E->getNumTemplateArgs(),
6815 TransArgs))
6816 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006817 }
6818
Chad Rosier1dcde962012-08-08 18:46:20 +00006819 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006820 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006821}
Mike Stump11289f42009-09-09 15:08:12 +00006822
Douglas Gregora16548e2009-08-11 05:31:07 +00006823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006825TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006826 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006827}
Mike Stump11289f42009-09-09 15:08:12 +00006828
Douglas Gregora16548e2009-08-11 05:31:07 +00006829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006830ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006831TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006832 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006833}
Mike Stump11289f42009-09-09 15:08:12 +00006834
Douglas Gregora16548e2009-08-11 05:31:07 +00006835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006837TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006838 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006839}
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregora16548e2009-08-11 05:31:07 +00006841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006842ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006843TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006844 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006845}
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006848ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006849TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006850 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006851}
6852
6853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006854ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006855TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006856 if (FunctionDecl *FD = E->getDirectCallee())
6857 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006858 return SemaRef.MaybeBindToTemporary(E);
6859}
6860
6861template<typename Derived>
6862ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006863TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6864 ExprResult ControllingExpr =
6865 getDerived().TransformExpr(E->getControllingExpr());
6866 if (ControllingExpr.isInvalid())
6867 return ExprError();
6868
Chris Lattner01cf8db2011-07-20 06:58:45 +00006869 SmallVector<Expr *, 4> AssocExprs;
6870 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006871 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6872 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6873 if (TS) {
6874 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6875 if (!AssocType)
6876 return ExprError();
6877 AssocTypes.push_back(AssocType);
6878 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006879 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006880 }
6881
6882 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6883 if (AssocExpr.isInvalid())
6884 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006885 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006886 }
6887
6888 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6889 E->getDefaultLoc(),
6890 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006891 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006892 AssocTypes,
6893 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006894}
6895
6896template<typename Derived>
6897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006898TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006899 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006900 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006904 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006905
John McCallb268a282010-08-23 23:25:46 +00006906 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 E->getRParen());
6908}
6909
Richard Smithdb2630f2012-10-21 03:28:35 +00006910/// \brief The operand of a unary address-of operator has special rules: it's
6911/// allowed to refer to a non-static member of a class even if there's no 'this'
6912/// object available.
6913template<typename Derived>
6914ExprResult
6915TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6916 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00006917 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00006918 else
6919 return getDerived().TransformExpr(E);
6920}
6921
Mike Stump11289f42009-09-09 15:08:12 +00006922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006923ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006924TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006925 ExprResult SubExpr;
6926 if (E->getOpcode() == UO_AddrOf)
6927 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6928 else
6929 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006930 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006932
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006934 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006935
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6937 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006938 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006939}
Mike Stump11289f42009-09-09 15:08:12 +00006940
Douglas Gregora16548e2009-08-11 05:31:07 +00006941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006942ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006943TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6944 // Transform the type.
6945 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6946 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006947 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006948
Douglas Gregor882211c2010-04-28 22:16:22 +00006949 // Transform all of the components into components similar to what the
6950 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006951 // FIXME: It would be slightly more efficient in the non-dependent case to
6952 // just map FieldDecls, rather than requiring the rebuilder to look for
6953 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006954 // template code that we don't care.
6955 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006956 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006957 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006958 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006959 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6960 const Node &ON = E->getComponent(I);
6961 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006962 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006963 Comp.LocStart = ON.getSourceRange().getBegin();
6964 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006965 switch (ON.getKind()) {
6966 case Node::Array: {
6967 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006968 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006969 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006970 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006971
Douglas Gregor882211c2010-04-28 22:16:22 +00006972 ExprChanged = ExprChanged || Index.get() != FromIndex;
6973 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006974 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006975 break;
6976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006977
Douglas Gregor882211c2010-04-28 22:16:22 +00006978 case Node::Field:
6979 case Node::Identifier:
6980 Comp.isBrackets = false;
6981 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006982 if (!Comp.U.IdentInfo)
6983 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006984
Douglas Gregor882211c2010-04-28 22:16:22 +00006985 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006986
Douglas Gregord1702062010-04-29 00:18:15 +00006987 case Node::Base:
6988 // Will be recomputed during the rebuild.
6989 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006991
Douglas Gregor882211c2010-04-28 22:16:22 +00006992 Components.push_back(Comp);
6993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006994
Douglas Gregor882211c2010-04-28 22:16:22 +00006995 // If nothing changed, retain the existing expression.
6996 if (!getDerived().AlwaysRebuild() &&
6997 Type == E->getTypeSourceInfo() &&
6998 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006999 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007000
Douglas Gregor882211c2010-04-28 22:16:22 +00007001 // Build a new offsetof expression.
7002 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7003 Components.data(), Components.size(),
7004 E->getRParenLoc());
7005}
7006
7007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007008ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007009TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7010 assert(getDerived().AlreadyTransformed(E->getType()) &&
7011 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007012 return E;
John McCall8d69a212010-11-15 23:31:06 +00007013}
7014
7015template<typename Derived>
7016ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007017TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007018 // Rebuild the syntactic form. The original syntactic form has
7019 // opaque-value expressions in it, so strip those away and rebuild
7020 // the result. This is a really awful way of doing this, but the
7021 // better solution (rebuilding the semantic expressions and
7022 // rebinding OVEs as necessary) doesn't work; we'd need
7023 // TreeTransform to not strip away implicit conversions.
7024 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7025 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007026 if (result.isInvalid()) return ExprError();
7027
7028 // If that gives us a pseudo-object result back, the pseudo-object
7029 // expression must have been an lvalue-to-rvalue conversion which we
7030 // should reapply.
7031 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007032 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007033
7034 return result;
7035}
7036
7037template<typename Derived>
7038ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007039TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7040 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007041 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007042 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007043
John McCallbcd03502009-12-07 02:54:59 +00007044 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007045 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007047
John McCall4c98fd82009-11-04 07:28:41 +00007048 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007049 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007050
Peter Collingbournee190dee2011-03-11 19:24:49 +00007051 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7052 E->getKind(),
7053 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 }
Mike Stump11289f42009-09-09 15:08:12 +00007055
Eli Friedmane4f22df2012-02-29 04:03:55 +00007056 // C++0x [expr.sizeof]p1:
7057 // The operand is either an expression, which is an unevaluated operand
7058 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007059 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7060 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007061
Reid Kleckner32506ed2014-06-12 23:03:48 +00007062 // Try to recover if we have something like sizeof(T::X) where X is a type.
7063 // Notably, there must be *exactly* one set of parens if X is a type.
7064 TypeSourceInfo *RecoveryTSI = nullptr;
7065 ExprResult SubExpr;
7066 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7067 if (auto *DRE =
7068 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7069 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7070 PE, DRE, false, &RecoveryTSI);
7071 else
7072 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7073
7074 if (RecoveryTSI) {
7075 return getDerived().RebuildUnaryExprOrTypeTrait(
7076 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7077 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007079
Eli Friedmane4f22df2012-02-29 04:03:55 +00007080 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007081 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007082
Peter Collingbournee190dee2011-03-11 19:24:49 +00007083 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7084 E->getOperatorLoc(),
7085 E->getKind(),
7086 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007087}
Mike Stump11289f42009-09-09 15:08:12 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007091TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007092 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007093 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007095
John McCalldadc5752010-08-24 06:29:42 +00007096 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007097 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007098 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007099
7100
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 if (!getDerived().AlwaysRebuild() &&
7102 LHS.get() == E->getLHS() &&
7103 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007104 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007105
John McCallb268a282010-08-23 23:25:46 +00007106 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007107 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007108 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 E->getRBracketLoc());
7110}
Mike Stump11289f42009-09-09 15:08:12 +00007111
7112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007114TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007115 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007116 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007117 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007118 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007119
7120 // Transform arguments.
7121 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007122 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007123 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007124 &ArgChanged))
7125 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007126
Douglas Gregora16548e2009-08-11 05:31:07 +00007127 if (!getDerived().AlwaysRebuild() &&
7128 Callee.get() == E->getCallee() &&
7129 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007130 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007133 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007135 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007136 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007137 E->getRParenLoc());
7138}
Mike Stump11289f42009-09-09 15:08:12 +00007139
7140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007141ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007143 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007146
Douglas Gregorea972d32011-02-28 21:54:11 +00007147 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007148 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007149 QualifierLoc
7150 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007151
Douglas Gregorea972d32011-02-28 21:54:11 +00007152 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007153 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007154 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007155 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007156
Eli Friedman2cfcef62009-12-04 06:40:45 +00007157 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007158 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7159 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007162
John McCall16df1e52010-03-30 21:47:33 +00007163 NamedDecl *FoundDecl = E->getFoundDecl();
7164 if (FoundDecl == E->getMemberDecl()) {
7165 FoundDecl = Member;
7166 } else {
7167 FoundDecl = cast_or_null<NamedDecl>(
7168 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7169 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007170 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007171 }
7172
Douglas Gregora16548e2009-08-11 05:31:07 +00007173 if (!getDerived().AlwaysRebuild() &&
7174 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007175 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007176 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007177 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007178 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007179
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007180 // Mark it referenced in the new context regardless.
7181 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007182 SemaRef.MarkMemberReferenced(E);
7183
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007184 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007185 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007186
John McCall6b51f282009-11-23 01:53:49 +00007187 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007188 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007189 TransArgs.setLAngleLoc(E->getLAngleLoc());
7190 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007191 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7192 E->getNumTemplateArgs(),
7193 TransArgs))
7194 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007196
Douglas Gregora16548e2009-08-11 05:31:07 +00007197 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007198 SourceLocation FakeOperatorLoc =
7199 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007200
John McCall38836f02010-01-15 08:34:02 +00007201 // FIXME: to do this check properly, we will need to preserve the
7202 // first-qualifier-in-scope here, just in case we had a dependent
7203 // base (and therefore couldn't do the check) and a
7204 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007205 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007206
John McCallb268a282010-08-23 23:25:46 +00007207 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007208 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007209 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007210 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007211 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007212 Member,
John McCall16df1e52010-03-30 21:47:33 +00007213 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007214 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007215 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007216 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007217}
Mike Stump11289f42009-09-09 15:08:12 +00007218
Douglas Gregora16548e2009-08-11 05:31:07 +00007219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007221TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007222 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007225
John McCalldadc5752010-08-24 06:29:42 +00007226 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007227 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007228 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007229
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 if (!getDerived().AlwaysRebuild() &&
7231 LHS.get() == E->getLHS() &&
7232 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007233 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007234
Lang Hames5de91cc2012-10-02 04:45:10 +00007235 Sema::FPContractStateRAII FPContractState(getSema());
7236 getSema().FPFeatures.fp_contract = E->isFPContractable();
7237
Douglas Gregora16548e2009-08-11 05:31:07 +00007238 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007239 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007240}
7241
Mike Stump11289f42009-09-09 15:08:12 +00007242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007243ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007244TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007245 CompoundAssignOperator *E) {
7246 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007247}
Mike Stump11289f42009-09-09 15:08:12 +00007248
Douglas Gregora16548e2009-08-11 05:31:07 +00007249template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007250ExprResult TreeTransform<Derived>::
7251TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7252 // Just rebuild the common and RHS expressions and see whether we
7253 // get any changes.
7254
7255 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7256 if (commonExpr.isInvalid())
7257 return ExprError();
7258
7259 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7260 if (rhs.isInvalid())
7261 return ExprError();
7262
7263 if (!getDerived().AlwaysRebuild() &&
7264 commonExpr.get() == e->getCommon() &&
7265 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007266 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007267
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007268 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007269 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007270 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007271 e->getColonLoc(),
7272 rhs.get());
7273}
7274
7275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007277TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007278 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007279 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007281
John McCalldadc5752010-08-24 06:29:42 +00007282 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007283 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007285
John McCalldadc5752010-08-24 06:29:42 +00007286 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007287 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007289
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 if (!getDerived().AlwaysRebuild() &&
7291 Cond.get() == E->getCond() &&
7292 LHS.get() == E->getLHS() &&
7293 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007294 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007295
John McCallb268a282010-08-23 23:25:46 +00007296 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007297 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007298 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007299 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007300 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007301}
Mike Stump11289f42009-09-09 15:08:12 +00007302
7303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007305TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007306 // Implicit casts are eliminated during transformation, since they
7307 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007308 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007309}
Mike Stump11289f42009-09-09 15:08:12 +00007310
Douglas Gregora16548e2009-08-11 05:31:07 +00007311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007313TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007314 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7315 if (!Type)
7316 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007317
John McCalldadc5752010-08-24 06:29:42 +00007318 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007319 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007320 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007322
Douglas Gregora16548e2009-08-11 05:31:07 +00007323 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007324 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007325 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007326 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007327
John McCall97513962010-01-15 18:39:57 +00007328 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007329 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007331 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007332}
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007336TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007337 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7338 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7339 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007341
John McCalldadc5752010-08-24 06:29:42 +00007342 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007343 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007345
Douglas Gregora16548e2009-08-11 05:31:07 +00007346 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007347 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007348 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007349 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007350
John McCall5d7aa7f2010-01-19 22:33:45 +00007351 // Note: the expression type doesn't necessarily match the
7352 // type-as-written, but that's okay, because it should always be
7353 // derivable from the initializer.
7354
John McCalle15bbff2010-01-18 19:35:47 +00007355 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007356 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007357 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007358}
Mike Stump11289f42009-09-09 15:08:12 +00007359
Douglas Gregora16548e2009-08-11 05:31:07 +00007360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007362TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007363 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007366
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 if (!getDerived().AlwaysRebuild() &&
7368 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007369 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007370
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007372 SourceLocation FakeOperatorLoc =
7373 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007374 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007375 E->getAccessorLoc(),
7376 E->getAccessor());
7377}
Mike Stump11289f42009-09-09 15:08:12 +00007378
Douglas Gregora16548e2009-08-11 05:31:07 +00007379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007381TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007383
Benjamin Kramerf0623432012-08-23 22:51:59 +00007384 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007385 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007386 Inits, &InitChanged))
7387 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007388
Douglas Gregora16548e2009-08-11 05:31:07 +00007389 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007390 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007391
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007392 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007393 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007394}
Mike Stump11289f42009-09-09 15:08:12 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007400
Douglas Gregorebe10102009-08-20 07:17:43 +00007401 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007402 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007403 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007405
Douglas Gregorebe10102009-08-20 07:17:43 +00007406 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007407 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 bool ExprChanged = false;
7409 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7410 DEnd = E->designators_end();
7411 D != DEnd; ++D) {
7412 if (D->isFieldDesignator()) {
7413 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7414 D->getDotLoc(),
7415 D->getFieldLoc()));
7416 continue;
7417 }
Mike Stump11289f42009-09-09 15:08:12 +00007418
Douglas Gregora16548e2009-08-11 05:31:07 +00007419 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007420 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007421 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007423
7424 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007426
Douglas Gregora16548e2009-08-11 05:31:07 +00007427 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007428 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 continue;
7430 }
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007433 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007434 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7435 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007437
John McCalldadc5752010-08-24 06:29:42 +00007438 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007439 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007440 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007441
7442 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007443 End.get(),
7444 D->getLBracketLoc(),
7445 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007446
Douglas Gregora16548e2009-08-11 05:31:07 +00007447 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7448 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007449
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007450 ArrayExprs.push_back(Start.get());
7451 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007452 }
Mike Stump11289f42009-09-09 15:08:12 +00007453
Douglas Gregora16548e2009-08-11 05:31:07 +00007454 if (!getDerived().AlwaysRebuild() &&
7455 Init.get() == E->getInit() &&
7456 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007457 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007458
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007459 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007460 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007461 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007462}
Mike Stump11289f42009-09-09 15:08:12 +00007463
Douglas Gregora16548e2009-08-11 05:31:07 +00007464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007465ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007466TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007467 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007468 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007469
Douglas Gregor3da3c062009-10-28 00:29:27 +00007470 // FIXME: Will we ever have proper type location here? Will we actually
7471 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 QualType T = getDerived().TransformType(E->getType());
7473 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007474 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007475
Douglas Gregora16548e2009-08-11 05:31:07 +00007476 if (!getDerived().AlwaysRebuild() &&
7477 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007478 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007479
Douglas Gregora16548e2009-08-11 05:31:07 +00007480 return getDerived().RebuildImplicitValueInitExpr(T);
7481}
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregora16548e2009-08-11 05:31:07 +00007483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007485TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007486 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7487 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007489
John McCalldadc5752010-08-24 06:29:42 +00007490 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007491 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregora16548e2009-08-11 05:31:07 +00007494 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007495 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007496 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007497 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007498
John McCallb268a282010-08-23 23:25:46 +00007499 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007500 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007501}
7502
7503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007505TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007506 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007507 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007508 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7509 &ArgumentChanged))
7510 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007511
Douglas Gregora16548e2009-08-11 05:31:07 +00007512 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007513 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007514 E->getRParenLoc());
7515}
Mike Stump11289f42009-09-09 15:08:12 +00007516
Douglas Gregora16548e2009-08-11 05:31:07 +00007517/// \brief Transform an address-of-label expression.
7518///
7519/// By default, the transformation of an address-of-label expression always
7520/// rebuilds the expression, so that the label identifier can be resolved to
7521/// the corresponding label statement by semantic analysis.
7522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007523ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007524TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007525 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7526 E->getLabel());
7527 if (!LD)
7528 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007529
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007531 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007532}
Mike Stump11289f42009-09-09 15:08:12 +00007533
7534template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007536TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007537 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007538 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007539 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007540 if (SubStmt.isInvalid()) {
7541 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007543 }
Mike Stump11289f42009-09-09 15:08:12 +00007544
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007546 SubStmt.get() == E->getSubStmt()) {
7547 // Calling this an 'error' is unintuitive, but it does the right thing.
7548 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007549 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007550 }
Mike Stump11289f42009-09-09 15:08:12 +00007551
7552 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007553 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007554 E->getRParenLoc());
7555}
Mike Stump11289f42009-09-09 15:08:12 +00007556
Douglas Gregora16548e2009-08-11 05:31:07 +00007557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007559TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007560 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007561 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007563
John McCalldadc5752010-08-24 06:29:42 +00007564 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007565 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007567
John McCalldadc5752010-08-24 06:29:42 +00007568 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007571
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 if (!getDerived().AlwaysRebuild() &&
7573 Cond.get() == E->getCond() &&
7574 LHS.get() == E->getLHS() &&
7575 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007576 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007579 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 E->getRParenLoc());
7581}
Mike Stump11289f42009-09-09 15:08:12 +00007582
Douglas Gregora16548e2009-08-11 05:31:07 +00007583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007585TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007586 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007587}
7588
7589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007591TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007592 switch (E->getOperator()) {
7593 case OO_New:
7594 case OO_Delete:
7595 case OO_Array_New:
7596 case OO_Array_Delete:
7597 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007598
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007599 case OO_Call: {
7600 // This is a call to an object's operator().
7601 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7602
7603 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007604 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007605 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007606 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007607
7608 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007609 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7610 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007611
7612 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007613 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007614 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007615 Args))
7616 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007617
John McCallb268a282010-08-23 23:25:46 +00007618 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007619 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007620 E->getLocEnd());
7621 }
7622
7623#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7624 case OO_##Name:
7625#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7626#include "clang/Basic/OperatorKinds.def"
7627 case OO_Subscript:
7628 // Handled below.
7629 break;
7630
7631 case OO_Conditional:
7632 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007633
7634 case OO_None:
7635 case NUM_OVERLOADED_OPERATORS:
7636 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007637 }
7638
John McCalldadc5752010-08-24 06:29:42 +00007639 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007640 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007642
Richard Smithdb2630f2012-10-21 03:28:35 +00007643 ExprResult First;
7644 if (E->getOperator() == OO_Amp)
7645 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7646 else
7647 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007649 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007650
John McCalldadc5752010-08-24 06:29:42 +00007651 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007652 if (E->getNumArgs() == 2) {
7653 Second = getDerived().TransformExpr(E->getArg(1));
7654 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007655 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 }
Mike Stump11289f42009-09-09 15:08:12 +00007657
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 if (!getDerived().AlwaysRebuild() &&
7659 Callee.get() == E->getCallee() &&
7660 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007661 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007662 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007663
Lang Hames5de91cc2012-10-02 04:45:10 +00007664 Sema::FPContractStateRAII FPContractState(getSema());
7665 getSema().FPFeatures.fp_contract = E->isFPContractable();
7666
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7668 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007669 Callee.get(),
7670 First.get(),
7671 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007672}
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregora16548e2009-08-11 05:31:07 +00007674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007676TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7677 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007678}
Mike Stump11289f42009-09-09 15:08:12 +00007679
Douglas Gregora16548e2009-08-11 05:31:07 +00007680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007681ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007682TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7683 // Transform the callee.
7684 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7685 if (Callee.isInvalid())
7686 return ExprError();
7687
7688 // Transform exec config.
7689 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7690 if (EC.isInvalid())
7691 return ExprError();
7692
7693 // Transform arguments.
7694 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007695 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007696 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007697 &ArgChanged))
7698 return ExprError();
7699
7700 if (!getDerived().AlwaysRebuild() &&
7701 Callee.get() == E->getCallee() &&
7702 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007703 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007704
7705 // FIXME: Wrong source location information for the '('.
7706 SourceLocation FakeLParenLoc
7707 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7708 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007709 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007710 E->getRParenLoc(), EC.get());
7711}
7712
7713template<typename Derived>
7714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007715TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007716 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7717 if (!Type)
7718 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007719
John McCalldadc5752010-08-24 06:29:42 +00007720 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007721 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007722 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007723 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007724
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007726 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007728 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007729 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007730 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007731 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007732 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007733 E->getAngleBrackets().getEnd(),
7734 // FIXME. this should be '(' location
7735 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007736 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007737 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007738}
Mike Stump11289f42009-09-09 15:08:12 +00007739
Douglas Gregora16548e2009-08-11 05:31:07 +00007740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007742TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7743 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007744}
Mike Stump11289f42009-09-09 15:08:12 +00007745
7746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007747ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007748TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7749 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007750}
7751
Douglas Gregora16548e2009-08-11 05:31:07 +00007752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007753ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007754TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007755 CXXReinterpretCastExpr *E) {
7756 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007757}
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007761TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7762 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007763}
Mike Stump11289f42009-09-09 15:08:12 +00007764
Douglas Gregora16548e2009-08-11 05:31:07 +00007765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007766ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007767TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007768 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007769 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7770 if (!Type)
7771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007772
John McCalldadc5752010-08-24 06:29:42 +00007773 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007774 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007775 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007777
Douglas Gregora16548e2009-08-11 05:31:07 +00007778 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007779 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007780 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007781 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007782
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007783 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007784 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007785 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007786 E->getRParenLoc());
7787}
Mike Stump11289f42009-09-09 15:08:12 +00007788
Douglas Gregora16548e2009-08-11 05:31:07 +00007789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007791TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007792 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007793 TypeSourceInfo *TInfo
7794 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7795 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007797
Douglas Gregora16548e2009-08-11 05:31:07 +00007798 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007799 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007800 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007801
Douglas Gregor9da64192010-04-26 22:37:10 +00007802 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7803 E->getLocStart(),
7804 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 E->getLocEnd());
7806 }
Mike Stump11289f42009-09-09 15:08:12 +00007807
Eli Friedman456f0182012-01-20 01:26:23 +00007808 // We don't know whether the subexpression is potentially evaluated until
7809 // after we perform semantic analysis. We speculatively assume it is
7810 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007811 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007812 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7813 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007814
John McCalldadc5752010-08-24 06:29:42 +00007815 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007816 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007817 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007818
Douglas Gregora16548e2009-08-11 05:31:07 +00007819 if (!getDerived().AlwaysRebuild() &&
7820 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007821 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007822
Douglas Gregor9da64192010-04-26 22:37:10 +00007823 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7824 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007825 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007826 E->getLocEnd());
7827}
7828
7829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007830ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007831TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7832 if (E->isTypeOperand()) {
7833 TypeSourceInfo *TInfo
7834 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7835 if (!TInfo)
7836 return ExprError();
7837
7838 if (!getDerived().AlwaysRebuild() &&
7839 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007840 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007841
Douglas Gregor69735112011-03-06 17:40:41 +00007842 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007843 E->getLocStart(),
7844 TInfo,
7845 E->getLocEnd());
7846 }
7847
Francois Pichet9f4f2072010-09-08 12:20:18 +00007848 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7849
7850 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7851 if (SubExpr.isInvalid())
7852 return ExprError();
7853
7854 if (!getDerived().AlwaysRebuild() &&
7855 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007856 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007857
7858 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7859 E->getLocStart(),
7860 SubExpr.get(),
7861 E->getLocEnd());
7862}
7863
7864template<typename Derived>
7865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007866TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007867 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007868}
Mike Stump11289f42009-09-09 15:08:12 +00007869
Douglas Gregora16548e2009-08-11 05:31:07 +00007870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007871ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007872TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007873 CXXNullPtrLiteralExpr *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
John McCall47f29ea2009-12-08 09:21:05 +00007879TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007880 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007881
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007882 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7883 // Make sure that we capture 'this'.
7884 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007885 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007887
Douglas Gregorb15af892010-01-07 23:12:05 +00007888 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007889}
Mike Stump11289f42009-09-09 15:08:12 +00007890
Douglas Gregora16548e2009-08-11 05:31:07 +00007891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007893TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007894 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007895 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 if (!getDerived().AlwaysRebuild() &&
7899 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007900 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007901
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007902 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7903 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007904}
Mike Stump11289f42009-09-09 15:08:12 +00007905
Douglas Gregora16548e2009-08-11 05:31:07 +00007906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007907ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007908TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007909 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007910 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7911 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007912 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007914
Chandler Carruth794da4c2010-02-08 06:42:49 +00007915 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007916 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007917 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007918
Douglas Gregor033f6752009-12-23 23:03:06 +00007919 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007920}
Mike Stump11289f42009-09-09 15:08:12 +00007921
Douglas Gregora16548e2009-08-11 05:31:07 +00007922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007923ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007924TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7925 FieldDecl *Field
7926 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7927 E->getField()));
7928 if (!Field)
7929 return ExprError();
7930
7931 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007932 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007933
7934 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7935}
7936
7937template<typename Derived>
7938ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007939TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7940 CXXScalarValueInitExpr *E) {
7941 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7942 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007944
Douglas Gregora16548e2009-08-11 05:31:07 +00007945 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007946 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007947 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007948
Chad Rosier1dcde962012-08-08 18:46:20 +00007949 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007950 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007951 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007952}
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregora16548e2009-08-11 05:31:07 +00007954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007956TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007957 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007958 TypeSourceInfo *AllocTypeInfo
7959 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7960 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007962
Douglas Gregora16548e2009-08-11 05:31:07 +00007963 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007964 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007967
Douglas Gregora16548e2009-08-11 05:31:07 +00007968 // Transform the placement arguments (if any).
7969 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007970 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007971 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007972 E->getNumPlacementArgs(), true,
7973 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007975
Sebastian Redl6047f072012-02-16 12:22:20 +00007976 // Transform the initializer (if any).
7977 Expr *OldInit = E->getInitializer();
7978 ExprResult NewInit;
7979 if (OldInit)
7980 NewInit = getDerived().TransformExpr(OldInit);
7981 if (NewInit.isInvalid())
7982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007983
Sebastian Redl6047f072012-02-16 12:22:20 +00007984 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007985 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007986 if (E->getOperatorNew()) {
7987 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007988 getDerived().TransformDecl(E->getLocStart(),
7989 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007990 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007991 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007992 }
7993
Craig Topperc3ec1492014-05-26 06:22:03 +00007994 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007995 if (E->getOperatorDelete()) {
7996 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007997 getDerived().TransformDecl(E->getLocStart(),
7998 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007999 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008000 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008002
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008004 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008006 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008007 OperatorNew == E->getOperatorNew() &&
8008 OperatorDelete == E->getOperatorDelete() &&
8009 !ArgumentChanged) {
8010 // Mark any declarations we need as referenced.
8011 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008012 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008013 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008014 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008015 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008016
Sebastian Redl6047f072012-02-16 12:22:20 +00008017 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008018 QualType ElementType
8019 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8020 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8021 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8022 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008023 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008024 }
8025 }
8026 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008027
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008028 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008029 }
Mike Stump11289f42009-09-09 15:08:12 +00008030
Douglas Gregor0744ef62010-09-07 21:49:58 +00008031 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008032 if (!ArraySize.get()) {
8033 // If no array size was specified, but the new expression was
8034 // instantiated with an array type (e.g., "new T" where T is
8035 // instantiated with "int[4]"), extract the outer bound from the
8036 // array type as our array size. We do this with constant and
8037 // dependently-sized array types.
8038 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8039 if (!ArrayT) {
8040 // Do nothing
8041 } else if (const ConstantArrayType *ConsArrayT
8042 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008043 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8044 SemaRef.Context.getSizeType(),
8045 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008046 AllocType = ConsArrayT->getElementType();
8047 } else if (const DependentSizedArrayType *DepArrayT
8048 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8049 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008050 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008051 AllocType = DepArrayT->getElementType();
8052 }
8053 }
8054 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008055
Douglas Gregora16548e2009-08-11 05:31:07 +00008056 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8057 E->isGlobalNew(),
8058 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008059 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008060 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008061 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008062 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008063 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008064 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008065 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008066 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008067}
Mike Stump11289f42009-09-09 15:08:12 +00008068
Douglas Gregora16548e2009-08-11 05:31:07 +00008069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008071TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008072 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008075
Douglas Gregord2d9da02010-02-26 00:38:10 +00008076 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008077 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008078 if (E->getOperatorDelete()) {
8079 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008080 getDerived().TransformDecl(E->getLocStart(),
8081 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008082 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008083 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008084 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008085
Douglas Gregora16548e2009-08-11 05:31:07 +00008086 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008087 Operand.get() == E->getArgument() &&
8088 OperatorDelete == E->getOperatorDelete()) {
8089 // Mark any declarations we need as referenced.
8090 // FIXME: instantiation-specific.
8091 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008092 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008093
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008094 if (!E->getArgument()->isTypeDependent()) {
8095 QualType Destroyed = SemaRef.Context.getBaseElementType(
8096 E->getDestroyedType());
8097 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8098 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008099 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008100 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008101 }
8102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008103
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008104 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008105 }
Mike Stump11289f42009-09-09 15:08:12 +00008106
Douglas Gregora16548e2009-08-11 05:31:07 +00008107 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8108 E->isGlobalDelete(),
8109 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008110 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008111}
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregora16548e2009-08-11 05:31:07 +00008113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008114ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008115TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008116 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008117 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008118 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008120
John McCallba7bf592010-08-24 05:47:05 +00008121 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008122 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008123 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008124 E->getOperatorLoc(),
8125 E->isArrow()? tok::arrow : tok::period,
8126 ObjectTypePtr,
8127 MayBePseudoDestructor);
8128 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008129 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008130
John McCallba7bf592010-08-24 05:47:05 +00008131 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008132 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8133 if (QualifierLoc) {
8134 QualifierLoc
8135 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8136 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008137 return ExprError();
8138 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008139 CXXScopeSpec SS;
8140 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008141
Douglas Gregor678f90d2010-02-25 01:56:36 +00008142 PseudoDestructorTypeStorage Destroyed;
8143 if (E->getDestroyedTypeInfo()) {
8144 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008145 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008146 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008147 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008148 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008149 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008150 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008151 // We aren't likely to be able to resolve the identifier down to a type
8152 // now anyway, so just retain the identifier.
8153 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8154 E->getDestroyedTypeLoc());
8155 } else {
8156 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008157 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008158 *E->getDestroyedTypeIdentifier(),
8159 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008160 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008161 SS, ObjectTypePtr,
8162 false);
8163 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008164 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008165
Douglas Gregor678f90d2010-02-25 01:56:36 +00008166 Destroyed
8167 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8168 E->getDestroyedTypeLoc());
8169 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008170
Craig Topperc3ec1492014-05-26 06:22:03 +00008171 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008172 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008173 CXXScopeSpec EmptySS;
8174 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008175 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008176 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008177 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008178 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008179
John McCallb268a282010-08-23 23:25:46 +00008180 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008181 E->getOperatorLoc(),
8182 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008183 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008184 ScopeTypeInfo,
8185 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008186 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008187 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008188}
Mike Stump11289f42009-09-09 15:08:12 +00008189
Douglas Gregorad8a3362009-09-04 17:36:40 +00008190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008191ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008192TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008193 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008194 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8195 Sema::LookupOrdinaryName);
8196
8197 // Transform all the decls.
8198 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8199 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008200 NamedDecl *InstD = static_cast<NamedDecl*>(
8201 getDerived().TransformDecl(Old->getNameLoc(),
8202 *I));
John McCall84d87672009-12-10 09:41:52 +00008203 if (!InstD) {
8204 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8205 // This can happen because of dependent hiding.
8206 if (isa<UsingShadowDecl>(*I))
8207 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008208 else {
8209 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008210 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008211 }
John McCall84d87672009-12-10 09:41:52 +00008212 }
John McCalle66edc12009-11-24 19:00:30 +00008213
8214 // Expand using declarations.
8215 if (isa<UsingDecl>(InstD)) {
8216 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008217 for (auto *I : UD->shadows())
8218 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008219 continue;
8220 }
8221
8222 R.addDecl(InstD);
8223 }
8224
8225 // Resolve a kind, but don't do any further analysis. If it's
8226 // ambiguous, the callee needs to deal with it.
8227 R.resolveKind();
8228
8229 // Rebuild the nested-name qualifier, if present.
8230 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008231 if (Old->getQualifierLoc()) {
8232 NestedNameSpecifierLoc QualifierLoc
8233 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8234 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008235 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008236
Douglas Gregor0da1d432011-02-28 20:01:57 +00008237 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008238 }
8239
Douglas Gregor9262f472010-04-27 18:19:34 +00008240 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008241 CXXRecordDecl *NamingClass
8242 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8243 Old->getNameLoc(),
8244 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008245 if (!NamingClass) {
8246 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008247 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008249
Douglas Gregorda7be082010-04-27 16:10:10 +00008250 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008251 }
8252
Abramo Bagnara7945c982012-01-27 09:46:47 +00008253 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8254
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008255 // If we have neither explicit template arguments, nor the template keyword,
8256 // it's a normal declaration name.
8257 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008258 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8259
8260 // If we have template arguments, rebuild them, then rebuild the
8261 // templateid expression.
8262 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008263 if (Old->hasExplicitTemplateArgs() &&
8264 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008265 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008266 TransArgs)) {
8267 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008268 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008269 }
John McCalle66edc12009-11-24 19:00:30 +00008270
Abramo Bagnara7945c982012-01-27 09:46:47 +00008271 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008272 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008273}
Mike Stump11289f42009-09-09 15:08:12 +00008274
Douglas Gregora16548e2009-08-11 05:31:07 +00008275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008276ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008277TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8278 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008279 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008280 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8281 TypeSourceInfo *From = E->getArg(I);
8282 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008283 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008284 TypeLocBuilder TLB;
8285 TLB.reserve(FromTL.getFullDataSize());
8286 QualType To = getDerived().TransformType(TLB, FromTL);
8287 if (To.isNull())
8288 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008289
Douglas Gregor29c42f22012-02-24 07:38:34 +00008290 if (To == From->getType())
8291 Args.push_back(From);
8292 else {
8293 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8294 ArgChanged = true;
8295 }
8296 continue;
8297 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008298
Douglas Gregor29c42f22012-02-24 07:38:34 +00008299 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008300
Douglas Gregor29c42f22012-02-24 07:38:34 +00008301 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008302 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008303 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8304 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8305 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008306
Douglas Gregor29c42f22012-02-24 07:38:34 +00008307 // Determine whether the set of unexpanded parameter packs can and should
8308 // be expanded.
8309 bool Expand = true;
8310 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008311 Optional<unsigned> OrigNumExpansions =
8312 ExpansionTL.getTypePtr()->getNumExpansions();
8313 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008314 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8315 PatternTL.getSourceRange(),
8316 Unexpanded,
8317 Expand, RetainExpansion,
8318 NumExpansions))
8319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008320
Douglas Gregor29c42f22012-02-24 07:38:34 +00008321 if (!Expand) {
8322 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008323 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008324 // expansion.
8325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008326
Douglas Gregor29c42f22012-02-24 07:38:34 +00008327 TypeLocBuilder TLB;
8328 TLB.reserve(From->getTypeLoc().getFullDataSize());
8329
8330 QualType To = getDerived().TransformType(TLB, PatternTL);
8331 if (To.isNull())
8332 return ExprError();
8333
Chad Rosier1dcde962012-08-08 18:46:20 +00008334 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008335 PatternTL.getSourceRange(),
8336 ExpansionTL.getEllipsisLoc(),
8337 NumExpansions);
8338 if (To.isNull())
8339 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008340
Douglas Gregor29c42f22012-02-24 07:38:34 +00008341 PackExpansionTypeLoc ToExpansionTL
8342 = TLB.push<PackExpansionTypeLoc>(To);
8343 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8344 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8345 continue;
8346 }
8347
8348 // Expand the pack expansion by substituting for each argument in the
8349 // pack(s).
8350 for (unsigned I = 0; I != *NumExpansions; ++I) {
8351 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8352 TypeLocBuilder TLB;
8353 TLB.reserve(PatternTL.getFullDataSize());
8354 QualType To = getDerived().TransformType(TLB, PatternTL);
8355 if (To.isNull())
8356 return ExprError();
8357
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008358 if (To->containsUnexpandedParameterPack()) {
8359 To = getDerived().RebuildPackExpansionType(To,
8360 PatternTL.getSourceRange(),
8361 ExpansionTL.getEllipsisLoc(),
8362 NumExpansions);
8363 if (To.isNull())
8364 return ExprError();
8365
8366 PackExpansionTypeLoc ToExpansionTL
8367 = TLB.push<PackExpansionTypeLoc>(To);
8368 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8369 }
8370
Douglas Gregor29c42f22012-02-24 07:38:34 +00008371 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008373
Douglas Gregor29c42f22012-02-24 07:38:34 +00008374 if (!RetainExpansion)
8375 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008376
Douglas Gregor29c42f22012-02-24 07:38:34 +00008377 // If we're supposed to retain a pack expansion, do so by temporarily
8378 // forgetting the partially-substituted parameter pack.
8379 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8380
8381 TypeLocBuilder TLB;
8382 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008383
Douglas Gregor29c42f22012-02-24 07:38:34 +00008384 QualType To = getDerived().TransformType(TLB, PatternTL);
8385 if (To.isNull())
8386 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008387
8388 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008389 PatternTL.getSourceRange(),
8390 ExpansionTL.getEllipsisLoc(),
8391 NumExpansions);
8392 if (To.isNull())
8393 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008394
Douglas Gregor29c42f22012-02-24 07:38:34 +00008395 PackExpansionTypeLoc ToExpansionTL
8396 = TLB.push<PackExpansionTypeLoc>(To);
8397 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8398 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008400
Douglas Gregor29c42f22012-02-24 07:38:34 +00008401 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008402 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008403
8404 return getDerived().RebuildTypeTrait(E->getTrait(),
8405 E->getLocStart(),
8406 Args,
8407 E->getLocEnd());
8408}
8409
8410template<typename Derived>
8411ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008412TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8413 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8414 if (!T)
8415 return ExprError();
8416
8417 if (!getDerived().AlwaysRebuild() &&
8418 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008419 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008420
8421 ExprResult SubExpr;
8422 {
8423 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8424 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8425 if (SubExpr.isInvalid())
8426 return ExprError();
8427
8428 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008429 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008430 }
8431
8432 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8433 E->getLocStart(),
8434 T,
8435 SubExpr.get(),
8436 E->getLocEnd());
8437}
8438
8439template<typename Derived>
8440ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008441TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8442 ExprResult SubExpr;
8443 {
8444 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8445 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8446 if (SubExpr.isInvalid())
8447 return ExprError();
8448
8449 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008450 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008451 }
8452
8453 return getDerived().RebuildExpressionTrait(
8454 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8455}
8456
Reid Kleckner32506ed2014-06-12 23:03:48 +00008457template <typename Derived>
8458ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8459 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8460 TypeSourceInfo **RecoveryTSI) {
8461 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8462 DRE, AddrTaken, RecoveryTSI);
8463
8464 // Propagate both errors and recovered types, which return ExprEmpty.
8465 if (!NewDRE.isUsable())
8466 return NewDRE;
8467
8468 // We got an expr, wrap it up in parens.
8469 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8470 return PE;
8471 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8472 PE->getRParen());
8473}
8474
8475template <typename Derived>
8476ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8477 DependentScopeDeclRefExpr *E) {
8478 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8479 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008480}
8481
8482template<typename Derived>
8483ExprResult
8484TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8485 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008486 bool IsAddressOfOperand,
8487 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008488 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008489 NestedNameSpecifierLoc QualifierLoc
8490 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8491 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008492 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008493 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008494
John McCall31f82722010-11-12 08:19:04 +00008495 // TODO: If this is a conversion-function-id, verify that the
8496 // destination type name (if present) resolves the same way after
8497 // instantiation as it did in the local scope.
8498
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008499 DeclarationNameInfo NameInfo
8500 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8501 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008503
John McCalle66edc12009-11-24 19:00:30 +00008504 if (!E->hasExplicitTemplateArgs()) {
8505 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008506 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008507 // Note: it is sufficient to compare the Name component of NameInfo:
8508 // if name has not changed, DNLoc has not changed either.
8509 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008510 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008511
Reid Kleckner32506ed2014-06-12 23:03:48 +00008512 return getDerived().RebuildDependentScopeDeclRefExpr(
8513 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8514 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008515 }
John McCall6b51f282009-11-23 01:53:49 +00008516
8517 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008518 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8519 E->getNumTemplateArgs(),
8520 TransArgs))
8521 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008522
Reid Kleckner32506ed2014-06-12 23:03:48 +00008523 return getDerived().RebuildDependentScopeDeclRefExpr(
8524 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8525 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008526}
8527
8528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008530TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008531 // CXXConstructExprs other than for list-initialization and
8532 // CXXTemporaryObjectExpr are always implicit, so when we have
8533 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008534 if ((E->getNumArgs() == 1 ||
8535 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008536 (!getDerived().DropCallArgument(E->getArg(0))) &&
8537 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008538 return getDerived().TransformExpr(E->getArg(0));
8539
Douglas Gregora16548e2009-08-11 05:31:07 +00008540 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8541
8542 QualType T = getDerived().TransformType(E->getType());
8543 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008544 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008545
8546 CXXConstructorDecl *Constructor
8547 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008548 getDerived().TransformDecl(E->getLocStart(),
8549 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008550 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008552
Douglas Gregora16548e2009-08-11 05:31:07 +00008553 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008554 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008555 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008556 &ArgumentChanged))
8557 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008558
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 if (!getDerived().AlwaysRebuild() &&
8560 T == E->getType() &&
8561 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008562 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008563 // Mark the constructor as referenced.
8564 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008565 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008566 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008567 }
Mike Stump11289f42009-09-09 15:08:12 +00008568
Douglas Gregordb121ba2009-12-14 16:27:04 +00008569 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8570 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008571 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008572 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008573 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008574 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008575 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008576 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008577}
Mike Stump11289f42009-09-09 15:08:12 +00008578
Douglas Gregora16548e2009-08-11 05:31:07 +00008579/// \brief Transform a C++ temporary-binding expression.
8580///
Douglas Gregor363b1512009-12-24 18:51:59 +00008581/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8582/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008585TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008586 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008587}
Mike Stump11289f42009-09-09 15:08:12 +00008588
John McCall5d413782010-12-06 08:20:24 +00008589/// \brief Transform a C++ expression that contains cleanups that should
8590/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008591///
John McCall5d413782010-12-06 08:20:24 +00008592/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008593/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008595ExprResult
John McCall5d413782010-12-06 08:20:24 +00008596TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008597 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008598}
Mike Stump11289f42009-09-09 15:08:12 +00008599
Douglas Gregora16548e2009-08-11 05:31:07 +00008600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008601ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008602TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008603 CXXTemporaryObjectExpr *E) {
8604 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8605 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008607
Douglas Gregora16548e2009-08-11 05:31:07 +00008608 CXXConstructorDecl *Constructor
8609 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008610 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008611 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008612 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008614
Douglas Gregora16548e2009-08-11 05:31:07 +00008615 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008616 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008617 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008618 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008619 &ArgumentChanged))
8620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008621
Douglas Gregora16548e2009-08-11 05:31:07 +00008622 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008623 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008624 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008625 !ArgumentChanged) {
8626 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008627 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008628 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008630
Richard Smithd59b8322012-12-19 01:39:02 +00008631 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008632 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8633 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008634 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008635 E->getLocEnd());
8636}
Mike Stump11289f42009-09-09 15:08:12 +00008637
Douglas Gregora16548e2009-08-11 05:31:07 +00008638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008639ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008640TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008641
8642 // Transform any init-capture expressions before entering the scope of the
8643 // lambda body, because they are not semantically within that scope.
8644 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8645 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8646 E->explicit_capture_begin());
8647
8648 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8649 CEnd = E->capture_end();
8650 C != CEnd; ++C) {
8651 if (!C->isInitCapture())
8652 continue;
8653 EnterExpressionEvaluationContext EEEC(getSema(),
8654 Sema::PotentiallyEvaluated);
8655 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8656 C->getCapturedVar()->getInit(),
8657 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8658
8659 if (NewExprInitResult.isInvalid())
8660 return ExprError();
8661 Expr *NewExprInit = NewExprInitResult.get();
8662
8663 VarDecl *OldVD = C->getCapturedVar();
8664 QualType NewInitCaptureType =
8665 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8666 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8667 NewExprInit);
8668 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008669 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8670 std::make_pair(NewExprInitResult, NewInitCaptureType);
8671
8672 }
8673
Faisal Vali524ca282013-11-12 01:40:44 +00008674 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008675 // Transform the template parameters, and add them to the current
8676 // instantiation scope. The null case is handled correctly.
8677 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8678 E->getTemplateParameterList());
8679
8680 // Check to see if the TypeSourceInfo of the call operator needs to
8681 // be transformed, and if so do the transformation in the
8682 // CurrentInstantiationScope.
8683
8684 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8685 FunctionProtoTypeLoc OldCallOpFPTL =
8686 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008687 TypeSourceInfo *NewCallOpTSI = nullptr;
8688
Faisal Vali2cba1332013-10-23 06:44:28 +00008689 const bool CallOpWasAlreadyTransformed =
8690 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8691
8692 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8693 if (CallOpWasAlreadyTransformed)
8694 NewCallOpTSI = OldCallOpTSI;
8695 else {
8696 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8697 // The transformation MUST be done in the CurrentInstantiationScope since
8698 // it introduces a mapping of the original to the newly created
8699 // transformed parameters.
8700
8701 TypeLocBuilder NewCallOpTLBuilder;
8702 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8703 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008704 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008705 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8706 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008707 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008708 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8709 // the vector below - this will be used to synthesize the
8710 // NewCallOperator. Additionally, add the parameters of the untransformed
8711 // lambda call operator to the CurrentInstantiationScope.
8712 SmallVector<ParmVarDecl *, 4> Params;
8713 {
8714 FunctionProtoTypeLoc NewCallOpFPTL =
8715 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8716 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008717 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008718
8719 for (unsigned I = 0; I < NewNumArgs; ++I) {
8720 // If this call operator's type does not require transformation,
8721 // the parameters do not get added to the current instantiation scope,
8722 // - so ADD them! This allows the following to compile when the enclosing
8723 // template is specialized and the entire lambda expression has to be
8724 // transformed.
8725 // template<class T> void foo(T t) {
8726 // auto L = [](auto a) {
8727 // auto M = [](char b) { <-- note: non-generic lambda
8728 // auto N = [](auto c) {
8729 // int x = sizeof(a);
8730 // x = sizeof(b); <-- specifically this line
8731 // x = sizeof(c);
8732 // };
8733 // };
8734 // };
8735 // }
8736 // foo('a')
8737 if (CallOpWasAlreadyTransformed)
8738 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8739 NewParamDeclArray[I]);
8740 // Add to Params array, so these parameters can be used to create
8741 // the newly transformed call operator.
8742 Params.push_back(NewParamDeclArray[I]);
8743 }
8744 }
8745
8746 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008747 return ExprError();
8748
Eli Friedmand564afb2012-09-19 01:18:11 +00008749 // Create the local class that will describe the lambda.
8750 CXXRecordDecl *Class
8751 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008752 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008753 /*KnownDependent=*/false,
8754 E->getCaptureDefault());
8755
Eli Friedmand564afb2012-09-19 01:18:11 +00008756 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8757
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008758 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008759 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008760 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008761 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008762 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008763 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008764 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008765
Faisal Vali2cba1332013-10-23 06:44:28 +00008766 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8767
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008768 return getDerived().TransformLambdaScope(E, NewCallOperator,
8769 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008770}
8771
8772template<typename Derived>
8773ExprResult
8774TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008775 CXXMethodDecl *CallOperator,
8776 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008777 bool Invalid = false;
8778
Douglas Gregorb4328232012-02-14 00:00:48 +00008779 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008780 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8781 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008782
Faisal Vali2b391ab2013-09-26 19:54:12 +00008783 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008784 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008785 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008786 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008787 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008788 E->hasExplicitParameters(),
8789 E->hasExplicitResultType(),
8790 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008791
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008792 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008793 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008794 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008795 CEnd = E->capture_end();
8796 C != CEnd; ++C) {
8797 // When we hit the first implicit capture, tell Sema that we've finished
8798 // the list of explicit captures.
8799 if (!FinishedExplicitCaptures && C->isImplicit()) {
8800 getSema().finishLambdaExplicitCaptures(LSI);
8801 FinishedExplicitCaptures = true;
8802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008803
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008804 // Capturing 'this' is trivial.
8805 if (C->capturesThis()) {
8806 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8807 continue;
8808 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008809
Richard Smithba71c082013-05-16 06:20:58 +00008810 // Rebuild init-captures, including the implied field declaration.
8811 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008812
8813 InitCaptureInfoTy InitExprTypePair =
8814 InitCaptureExprsAndTypes[C - E->capture_begin()];
8815 ExprResult Init = InitExprTypePair.first;
8816 QualType InitQualType = InitExprTypePair.second;
8817 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008818 Invalid = true;
8819 continue;
8820 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008821 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008822 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8823 OldVD->getLocation(), InitExprTypePair.second,
8824 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008825 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008826 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008827 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008828 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008829 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008830 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008831 continue;
8832 }
8833
8834 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8835
Douglas Gregor3e308b12012-02-14 19:27:52 +00008836 // Determine the capture kind for Sema.
8837 Sema::TryCaptureKind Kind
8838 = C->isImplicit()? Sema::TryCapture_Implicit
8839 : C->getCaptureKind() == LCK_ByCopy
8840 ? Sema::TryCapture_ExplicitByVal
8841 : Sema::TryCapture_ExplicitByRef;
8842 SourceLocation EllipsisLoc;
8843 if (C->isPackExpansion()) {
8844 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8845 bool ShouldExpand = false;
8846 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008847 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008848 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8849 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008850 Unexpanded,
8851 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008852 NumExpansions)) {
8853 Invalid = true;
8854 continue;
8855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008856
Douglas Gregor3e308b12012-02-14 19:27:52 +00008857 if (ShouldExpand) {
8858 // The transform has determined that we should perform an expansion;
8859 // transform and capture each of the arguments.
8860 // expansion of the pattern. Do so.
8861 VarDecl *Pack = C->getCapturedVar();
8862 for (unsigned I = 0; I != *NumExpansions; ++I) {
8863 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8864 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008865 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008866 Pack));
8867 if (!CapturedVar) {
8868 Invalid = true;
8869 continue;
8870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008871
Douglas Gregor3e308b12012-02-14 19:27:52 +00008872 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008873 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8874 }
Richard Smith9467be42014-06-06 17:33:35 +00008875
8876 // FIXME: Retain a pack expansion if RetainExpansion is true.
8877
Douglas Gregor3e308b12012-02-14 19:27:52 +00008878 continue;
8879 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008880
Douglas Gregor3e308b12012-02-14 19:27:52 +00008881 EllipsisLoc = C->getEllipsisLoc();
8882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008884 // Transform the captured variable.
8885 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008886 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008887 C->getCapturedVar()));
8888 if (!CapturedVar) {
8889 Invalid = true;
8890 continue;
8891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008892
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008893 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008894 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008895 }
8896 if (!FinishedExplicitCaptures)
8897 getSema().finishLambdaExplicitCaptures(LSI);
8898
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008899
8900 // Enter a new evaluation context to insulate the lambda from any
8901 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008902 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008903
8904 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008905 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008906 /*IsInstantiation=*/true);
8907 return ExprError();
8908 }
8909
8910 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008911 StmtResult Body = getDerived().TransformStmt(E->getBody());
8912 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008913 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008914 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008915 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008916 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008917
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008918 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008919 /*CurScope=*/nullptr,
8920 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008921}
8922
8923template<typename Derived>
8924ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008925TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008926 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008927 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8928 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008930
Douglas Gregora16548e2009-08-11 05:31:07 +00008931 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008932 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008933 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008934 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008935 &ArgumentChanged))
8936 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008937
Douglas Gregora16548e2009-08-11 05:31:07 +00008938 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008939 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008940 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008941 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008942
Douglas Gregora16548e2009-08-11 05:31:07 +00008943 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008944 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008945 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008946 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008947 E->getRParenLoc());
8948}
Mike Stump11289f42009-09-09 15:08:12 +00008949
Douglas Gregora16548e2009-08-11 05:31:07 +00008950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008951ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008952TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008953 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008954 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008955 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008956 Expr *OldBase;
8957 QualType BaseType;
8958 QualType ObjectType;
8959 if (!E->isImplicitAccess()) {
8960 OldBase = E->getBase();
8961 Base = getDerived().TransformExpr(OldBase);
8962 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008964
John McCall2d74de92009-12-01 22:10:20 +00008965 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008966 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008967 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008968 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008969 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008970 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008971 ObjectTy,
8972 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008973 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008974 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008975
John McCallba7bf592010-08-24 05:47:05 +00008976 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008977 BaseType = ((Expr*) Base.get())->getType();
8978 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008979 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008980 BaseType = getDerived().TransformType(E->getBaseType());
8981 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8982 }
Mike Stump11289f42009-09-09 15:08:12 +00008983
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008984 // Transform the first part of the nested-name-specifier that qualifies
8985 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008986 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008987 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008988 E->getFirstQualifierFoundInScope(),
8989 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008990
Douglas Gregore16af532011-02-28 18:50:33 +00008991 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008992 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008993 QualifierLoc
8994 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8995 ObjectType,
8996 FirstQualifierInScope);
8997 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008998 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008999 }
Mike Stump11289f42009-09-09 15:08:12 +00009000
Abramo Bagnara7945c982012-01-27 09:46:47 +00009001 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9002
John McCall31f82722010-11-12 08:19:04 +00009003 // TODO: If this is a conversion-function-id, verify that the
9004 // destination type name (if present) resolves the same way after
9005 // instantiation as it did in the local scope.
9006
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009007 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009008 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009009 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009011
John McCall2d74de92009-12-01 22:10:20 +00009012 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009013 // This is a reference to a member without an explicitly-specified
9014 // template argument list. Optimize for this common case.
9015 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009016 Base.get() == OldBase &&
9017 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009018 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009019 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009020 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009021 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009022
John McCallb268a282010-08-23 23:25:46 +00009023 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009024 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009025 E->isArrow(),
9026 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009027 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009028 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009029 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009030 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009031 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009032 }
9033
John McCall6b51f282009-11-23 01:53:49 +00009034 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009035 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9036 E->getNumTemplateArgs(),
9037 TransArgs))
9038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009039
John McCallb268a282010-08-23 23:25:46 +00009040 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009041 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009042 E->isArrow(),
9043 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009044 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009045 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009046 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009047 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009048 &TransArgs);
9049}
9050
9051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009053TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009054 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009055 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009056 QualType BaseType;
9057 if (!Old->isImplicitAccess()) {
9058 Base = getDerived().TransformExpr(Old->getBase());
9059 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009060 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009061 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009062 Old->isArrow());
9063 if (Base.isInvalid())
9064 return ExprError();
9065 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009066 } else {
9067 BaseType = getDerived().TransformType(Old->getBaseType());
9068 }
John McCall10eae182009-11-30 22:42:35 +00009069
Douglas Gregor0da1d432011-02-28 20:01:57 +00009070 NestedNameSpecifierLoc QualifierLoc;
9071 if (Old->getQualifierLoc()) {
9072 QualifierLoc
9073 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9074 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009075 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009076 }
9077
Abramo Bagnara7945c982012-01-27 09:46:47 +00009078 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9079
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009080 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009081 Sema::LookupOrdinaryName);
9082
9083 // Transform all the decls.
9084 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9085 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009086 NamedDecl *InstD = static_cast<NamedDecl*>(
9087 getDerived().TransformDecl(Old->getMemberLoc(),
9088 *I));
John McCall84d87672009-12-10 09:41:52 +00009089 if (!InstD) {
9090 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9091 // This can happen because of dependent hiding.
9092 if (isa<UsingShadowDecl>(*I))
9093 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009094 else {
9095 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009096 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009097 }
John McCall84d87672009-12-10 09:41:52 +00009098 }
John McCall10eae182009-11-30 22:42:35 +00009099
9100 // Expand using declarations.
9101 if (isa<UsingDecl>(InstD)) {
9102 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009103 for (auto *I : UD->shadows())
9104 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009105 continue;
9106 }
9107
9108 R.addDecl(InstD);
9109 }
9110
9111 R.resolveKind();
9112
Douglas Gregor9262f472010-04-27 18:19:34 +00009113 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009114 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009115 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009116 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009117 Old->getMemberLoc(),
9118 Old->getNamingClass()));
9119 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009120 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
Douglas Gregorda7be082010-04-27 16:10:10 +00009122 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
John McCall10eae182009-11-30 22:42:35 +00009125 TemplateArgumentListInfo TransArgs;
9126 if (Old->hasExplicitTemplateArgs()) {
9127 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9128 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009129 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9130 Old->getNumTemplateArgs(),
9131 TransArgs))
9132 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009133 }
John McCall38836f02010-01-15 08:34:02 +00009134
9135 // FIXME: to do this check properly, we will need to preserve the
9136 // first-qualifier-in-scope here, just in case we had a dependent
9137 // base (and therefore couldn't do the check) and a
9138 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009139 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009140
John McCallb268a282010-08-23 23:25:46 +00009141 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009142 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009143 Old->getOperatorLoc(),
9144 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009145 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009146 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009147 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009148 R,
9149 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009150 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009151}
9152
9153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009154ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009155TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009156 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009157 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9158 if (SubExpr.isInvalid())
9159 return ExprError();
9160
9161 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009162 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009163
9164 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9165}
9166
9167template<typename Derived>
9168ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009169TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009170 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9171 if (Pattern.isInvalid())
9172 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009173
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009174 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009175 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009176
Douglas Gregorb8840002011-01-14 21:20:45 +00009177 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9178 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009179}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009180
9181template<typename Derived>
9182ExprResult
9183TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9184 // If E is not value-dependent, then nothing will change when we transform it.
9185 // Note: This is an instantiation-centric view.
9186 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009187 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009188
9189 // Note: None of the implementations of TryExpandParameterPacks can ever
9190 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009191 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009192 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9193 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009194 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009195 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009196 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009197 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009198 ShouldExpand, RetainExpansion,
9199 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009200 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009201
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009202 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009203 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009204
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009205 NamedDecl *Pack = E->getPack();
9206 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009207 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009208 Pack));
9209 if (!Pack)
9210 return ExprError();
9211 }
9212
Chad Rosier1dcde962012-08-08 18:46:20 +00009213
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009214 // We now know the length of the parameter pack, so build a new expression
9215 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009216 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9217 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009218 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009219}
9220
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009221template<typename Derived>
9222ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009223TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9224 SubstNonTypeTemplateParmPackExpr *E) {
9225 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009226 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009227}
9228
9229template<typename Derived>
9230ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009231TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9232 SubstNonTypeTemplateParmExpr *E) {
9233 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009234 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009235}
9236
9237template<typename Derived>
9238ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009239TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9240 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009241 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009242}
9243
9244template<typename Derived>
9245ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009246TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9247 MaterializeTemporaryExpr *E) {
9248 return getDerived().TransformExpr(E->GetTemporaryExpr());
9249}
Chad Rosier1dcde962012-08-08 18:46:20 +00009250
Douglas Gregorfe314812011-06-21 17:03:29 +00009251template<typename Derived>
9252ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009253TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9254 CXXStdInitializerListExpr *E) {
9255 return getDerived().TransformExpr(E->getSubExpr());
9256}
9257
9258template<typename Derived>
9259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009260TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009261 return SemaRef.MaybeBindToTemporary(E);
9262}
9263
9264template<typename Derived>
9265ExprResult
9266TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009267 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009268}
9269
9270template<typename Derived>
9271ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009272TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9273 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9274 if (SubExpr.isInvalid())
9275 return ExprError();
9276
9277 if (!getDerived().AlwaysRebuild() &&
9278 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009279 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009280
9281 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009282}
9283
9284template<typename Derived>
9285ExprResult
9286TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9287 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009288 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009289 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009290 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009291 /*IsCall=*/false, Elements, &ArgChanged))
9292 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Ted Kremeneke65b0862012-03-06 20:05:56 +00009294 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9295 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009296
Ted Kremeneke65b0862012-03-06 20:05:56 +00009297 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9298 Elements.data(),
9299 Elements.size());
9300}
9301
9302template<typename Derived>
9303ExprResult
9304TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009305 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009306 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009307 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009308 bool ArgChanged = false;
9309 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9310 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009311
Ted Kremeneke65b0862012-03-06 20:05:56 +00009312 if (OrigElement.isPackExpansion()) {
9313 // This key/value element is a pack expansion.
9314 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9315 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9316 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9317 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9318
9319 // Determine whether the set of unexpanded parameter packs can
9320 // and should be expanded.
9321 bool Expand = true;
9322 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009323 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9324 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009325 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9326 OrigElement.Value->getLocEnd());
9327 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9328 PatternRange,
9329 Unexpanded,
9330 Expand, RetainExpansion,
9331 NumExpansions))
9332 return ExprError();
9333
9334 if (!Expand) {
9335 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009336 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009337 // expansion.
9338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9339 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9340 if (Key.isInvalid())
9341 return ExprError();
9342
9343 if (Key.get() != OrigElement.Key)
9344 ArgChanged = true;
9345
9346 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9347 if (Value.isInvalid())
9348 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009349
Ted Kremeneke65b0862012-03-06 20:05:56 +00009350 if (Value.get() != OrigElement.Value)
9351 ArgChanged = true;
9352
Chad Rosier1dcde962012-08-08 18:46:20 +00009353 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009354 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9355 };
9356 Elements.push_back(Expansion);
9357 continue;
9358 }
9359
9360 // Record right away that the argument was changed. This needs
9361 // to happen even if the array expands to nothing.
9362 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009363
Ted Kremeneke65b0862012-03-06 20:05:56 +00009364 // The transform has determined that we should perform an elementwise
9365 // expansion of the pattern. Do so.
9366 for (unsigned I = 0; I != *NumExpansions; ++I) {
9367 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9368 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9369 if (Key.isInvalid())
9370 return ExprError();
9371
9372 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9373 if (Value.isInvalid())
9374 return ExprError();
9375
Chad Rosier1dcde962012-08-08 18:46:20 +00009376 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009377 Key.get(), Value.get(), SourceLocation(), NumExpansions
9378 };
9379
9380 // If any unexpanded parameter packs remain, we still have a
9381 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009382 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009383 if (Key.get()->containsUnexpandedParameterPack() ||
9384 Value.get()->containsUnexpandedParameterPack())
9385 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009386
Ted Kremeneke65b0862012-03-06 20:05:56 +00009387 Elements.push_back(Element);
9388 }
9389
Richard Smith9467be42014-06-06 17:33:35 +00009390 // FIXME: Retain a pack expansion if RetainExpansion is true.
9391
Ted Kremeneke65b0862012-03-06 20:05:56 +00009392 // We've finished with this pack expansion.
9393 continue;
9394 }
9395
9396 // Transform and check key.
9397 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9398 if (Key.isInvalid())
9399 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009400
Ted Kremeneke65b0862012-03-06 20:05:56 +00009401 if (Key.get() != OrigElement.Key)
9402 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009403
Ted Kremeneke65b0862012-03-06 20:05:56 +00009404 // Transform and check value.
9405 ExprResult Value
9406 = getDerived().TransformExpr(OrigElement.Value);
9407 if (Value.isInvalid())
9408 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009409
Ted Kremeneke65b0862012-03-06 20:05:56 +00009410 if (Value.get() != OrigElement.Value)
9411 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009412
9413 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009414 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009415 };
9416 Elements.push_back(Element);
9417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009418
Ted Kremeneke65b0862012-03-06 20:05:56 +00009419 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9420 return SemaRef.MaybeBindToTemporary(E);
9421
9422 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9423 Elements.data(),
9424 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009425}
9426
Mike Stump11289f42009-09-09 15:08:12 +00009427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009429TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009430 TypeSourceInfo *EncodedTypeInfo
9431 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9432 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009434
Douglas Gregora16548e2009-08-11 05:31:07 +00009435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009436 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009437 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009438
9439 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009440 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009441 E->getRParenLoc());
9442}
Mike Stump11289f42009-09-09 15:08:12 +00009443
Douglas Gregora16548e2009-08-11 05:31:07 +00009444template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009445ExprResult TreeTransform<Derived>::
9446TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009447 // This is a kind of implicit conversion, and it needs to get dropped
9448 // and recomputed for the same general reasons that ImplicitCastExprs
9449 // do, as well a more specific one: this expression is only valid when
9450 // it appears *immediately* as an argument expression.
9451 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009452}
9453
9454template<typename Derived>
9455ExprResult TreeTransform<Derived>::
9456TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009457 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009458 = getDerived().TransformType(E->getTypeInfoAsWritten());
9459 if (!TSInfo)
9460 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009461
John McCall31168b02011-06-15 23:02:42 +00009462 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009463 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009464 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009465
John McCall31168b02011-06-15 23:02:42 +00009466 if (!getDerived().AlwaysRebuild() &&
9467 TSInfo == E->getTypeInfoAsWritten() &&
9468 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009469 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009470
John McCall31168b02011-06-15 23:02:42 +00009471 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009472 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009473 Result.get());
9474}
9475
9476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009478TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009479 // Transform arguments.
9480 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009481 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009482 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009483 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009484 &ArgChanged))
9485 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009486
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009487 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9488 // Class message: transform the receiver type.
9489 TypeSourceInfo *ReceiverTypeInfo
9490 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9491 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009492 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009493
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009494 // If nothing changed, just retain the existing message send.
9495 if (!getDerived().AlwaysRebuild() &&
9496 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009497 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009498
9499 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009500 SmallVector<SourceLocation, 16> SelLocs;
9501 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009502 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9503 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009504 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009505 E->getMethodDecl(),
9506 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009507 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009508 E->getRightLoc());
9509 }
9510
9511 // Instance message: transform the receiver
9512 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9513 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009514 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009515 = getDerived().TransformExpr(E->getInstanceReceiver());
9516 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009517 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009518
9519 // If nothing changed, just retain the existing message send.
9520 if (!getDerived().AlwaysRebuild() &&
9521 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009522 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009523
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009524 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009525 SmallVector<SourceLocation, 16> SelLocs;
9526 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009527 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009528 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009529 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009530 E->getMethodDecl(),
9531 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009532 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009533 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009534}
9535
Mike Stump11289f42009-09-09 15:08:12 +00009536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009538TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009539 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009540}
9541
Mike Stump11289f42009-09-09 15:08:12 +00009542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009544TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009545 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009546}
9547
Mike Stump11289f42009-09-09 15:08:12 +00009548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009550TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009551 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009552 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009553 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009554 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009555
9556 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009557
Douglas Gregord51d90d2010-04-26 20:11:03 +00009558 // If nothing changed, just retain the existing expression.
9559 if (!getDerived().AlwaysRebuild() &&
9560 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009561 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009562
John McCallb268a282010-08-23 23:25:46 +00009563 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009564 E->getLocation(),
9565 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009566}
9567
Mike Stump11289f42009-09-09 15:08:12 +00009568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009570TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009571 // 'super' and types never change. Property never changes. Just
9572 // retain the existing expression.
9573 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009574 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009575
Douglas Gregor9faee212010-04-26 20:47:02 +00009576 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009577 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009578 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009579 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009580
Douglas Gregor9faee212010-04-26 20:47:02 +00009581 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009582
Douglas Gregor9faee212010-04-26 20:47:02 +00009583 // If nothing changed, just retain the existing expression.
9584 if (!getDerived().AlwaysRebuild() &&
9585 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009586 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009587
John McCallb7bd14f2010-12-02 01:19:52 +00009588 if (E->isExplicitProperty())
9589 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9590 E->getExplicitProperty(),
9591 E->getLocation());
9592
9593 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009594 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009595 E->getImplicitPropertyGetter(),
9596 E->getImplicitPropertySetter(),
9597 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009598}
9599
Mike Stump11289f42009-09-09 15:08:12 +00009600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009601ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009602TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9603 // Transform the base expression.
9604 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9605 if (Base.isInvalid())
9606 return ExprError();
9607
9608 // Transform the key expression.
9609 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9610 if (Key.isInvalid())
9611 return ExprError();
9612
9613 // If nothing changed, just retain the existing expression.
9614 if (!getDerived().AlwaysRebuild() &&
9615 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009616 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009617
Chad Rosier1dcde962012-08-08 18:46:20 +00009618 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009619 Base.get(), Key.get(),
9620 E->getAtIndexMethodDecl(),
9621 E->setAtIndexMethodDecl());
9622}
9623
9624template<typename Derived>
9625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009626TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009627 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009628 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009629 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009630 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009631
Douglas Gregord51d90d2010-04-26 20:11:03 +00009632 // If nothing changed, just retain the existing expression.
9633 if (!getDerived().AlwaysRebuild() &&
9634 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009635 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009636
John McCallb268a282010-08-23 23:25:46 +00009637 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009638 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009639 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009640}
9641
Mike Stump11289f42009-09-09 15:08:12 +00009642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009644TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009645 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009646 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009647 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009648 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009649 SubExprs, &ArgumentChanged))
9650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009651
Douglas Gregora16548e2009-08-11 05:31:07 +00009652 if (!getDerived().AlwaysRebuild() &&
9653 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009654 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009655
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009657 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009658 E->getRParenLoc());
9659}
9660
Mike Stump11289f42009-09-09 15:08:12 +00009661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009662ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009663TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9664 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9665 if (SrcExpr.isInvalid())
9666 return ExprError();
9667
9668 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9669 if (!Type)
9670 return ExprError();
9671
9672 if (!getDerived().AlwaysRebuild() &&
9673 Type == E->getTypeSourceInfo() &&
9674 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009675 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009676
9677 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9678 SrcExpr.get(), Type,
9679 E->getRParenLoc());
9680}
9681
9682template<typename Derived>
9683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009684TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009685 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009686
Craig Topperc3ec1492014-05-26 06:22:03 +00009687 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009688 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9689
9690 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009691 blockScope->TheDecl->setBlockMissingReturnType(
9692 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009693
Chris Lattner01cf8db2011-07-20 06:58:45 +00009694 SmallVector<ParmVarDecl*, 4> params;
9695 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009696
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009697 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009698 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9699 oldBlock->param_begin(),
9700 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009701 nullptr, paramTypes, &params)) {
9702 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009703 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009704 }
John McCall490112f2011-02-04 18:33:18 +00009705
Jordan Rosea0a86be2013-03-08 22:25:36 +00009706 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009707 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009708 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009709
Jordan Rose5c382722013-03-08 21:51:21 +00009710 QualType functionType =
9711 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009712 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009713 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009714
9715 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009716 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009717 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009718
9719 if (!oldBlock->blockMissingReturnType()) {
9720 blockScope->HasImplicitReturnType = false;
9721 blockScope->ReturnType = exprResultType;
9722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009723
John McCall3882ace2011-01-05 12:14:39 +00009724 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009725 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009726 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009727 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009728 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009729 }
John McCall3882ace2011-01-05 12:14:39 +00009730
John McCall490112f2011-02-04 18:33:18 +00009731#ifndef NDEBUG
9732 // In builds with assertions, make sure that we captured everything we
9733 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009734 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009735 for (const auto &I : oldBlock->captures()) {
9736 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009737
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009738 // Ignore parameter packs.
9739 if (isa<ParmVarDecl>(oldCapture) &&
9740 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9741 continue;
John McCall490112f2011-02-04 18:33:18 +00009742
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009743 VarDecl *newCapture =
9744 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9745 oldCapture));
9746 assert(blockScope->CaptureMap.count(newCapture));
9747 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009748 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009749 }
9750#endif
9751
9752 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009753 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009754}
9755
Mike Stump11289f42009-09-09 15:08:12 +00009756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009757ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009758TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009759 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009760}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009761
9762template<typename Derived>
9763ExprResult
9764TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009765 QualType RetTy = getDerived().TransformType(E->getType());
9766 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009767 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009768 SubExprs.reserve(E->getNumSubExprs());
9769 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9770 SubExprs, &ArgumentChanged))
9771 return ExprError();
9772
9773 if (!getDerived().AlwaysRebuild() &&
9774 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009775 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009776
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009777 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009778 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009779}
Chad Rosier1dcde962012-08-08 18:46:20 +00009780
Douglas Gregora16548e2009-08-11 05:31:07 +00009781//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009782// Type reconstruction
9783//===----------------------------------------------------------------------===//
9784
Mike Stump11289f42009-09-09 15:08:12 +00009785template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009786QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9787 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009788 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009789 getDerived().getBaseEntity());
9790}
9791
Mike Stump11289f42009-09-09 15:08:12 +00009792template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009793QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9794 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009795 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009796 getDerived().getBaseEntity());
9797}
9798
Mike Stump11289f42009-09-09 15:08:12 +00009799template<typename Derived>
9800QualType
John McCall70dd5f62009-10-30 00:06:24 +00009801TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9802 bool WrittenAsLValue,
9803 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009804 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009805 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009806}
9807
9808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009809QualType
John McCall70dd5f62009-10-30 00:06:24 +00009810TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9811 QualType ClassType,
9812 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009813 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9814 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009815}
9816
9817template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009818QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009819TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9820 ArrayType::ArraySizeModifier SizeMod,
9821 const llvm::APInt *Size,
9822 Expr *SizeExpr,
9823 unsigned IndexTypeQuals,
9824 SourceRange BracketsRange) {
9825 if (SizeExpr || !Size)
9826 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9827 IndexTypeQuals, BracketsRange,
9828 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009829
9830 QualType Types[] = {
9831 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9832 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9833 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009834 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009835 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009836 QualType SizeType;
9837 for (unsigned I = 0; I != NumTypes; ++I)
9838 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9839 SizeType = Types[I];
9840 break;
9841 }
Mike Stump11289f42009-09-09 15:08:12 +00009842
Eli Friedman9562f392012-01-25 23:20:27 +00009843 // Note that we can return a VariableArrayType here in the case where
9844 // the element type was a dependent VariableArrayType.
9845 IntegerLiteral *ArraySize
9846 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9847 /*FIXME*/BracketsRange.getBegin());
9848 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009849 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009850 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009851}
Mike Stump11289f42009-09-09 15:08:12 +00009852
Douglas Gregord6ff3322009-08-04 16:50:30 +00009853template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009854QualType
9855TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009856 ArrayType::ArraySizeModifier SizeMod,
9857 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009858 unsigned IndexTypeQuals,
9859 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009860 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009861 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009862}
9863
9864template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009865QualType
Mike Stump11289f42009-09-09 15:08:12 +00009866TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009867 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009868 unsigned IndexTypeQuals,
9869 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009870 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009871 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009872}
Mike Stump11289f42009-09-09 15:08:12 +00009873
Douglas Gregord6ff3322009-08-04 16:50:30 +00009874template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009875QualType
9876TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009877 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009878 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009879 unsigned IndexTypeQuals,
9880 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009881 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009882 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009883 IndexTypeQuals, BracketsRange);
9884}
9885
9886template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009887QualType
9888TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009889 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009890 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009891 unsigned IndexTypeQuals,
9892 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009893 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009894 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009895 IndexTypeQuals, BracketsRange);
9896}
9897
9898template<typename Derived>
9899QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009900 unsigned NumElements,
9901 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009902 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009903 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009904}
Mike Stump11289f42009-09-09 15:08:12 +00009905
Douglas Gregord6ff3322009-08-04 16:50:30 +00009906template<typename Derived>
9907QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9908 unsigned NumElements,
9909 SourceLocation AttributeLoc) {
9910 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9911 NumElements, true);
9912 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009913 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9914 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009915 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009916}
Mike Stump11289f42009-09-09 15:08:12 +00009917
Douglas Gregord6ff3322009-08-04 16:50:30 +00009918template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009919QualType
9920TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009921 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009922 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009923 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, 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>
Jordan Rose5c382722013-03-08 21:51:21 +00009927QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9928 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00009929 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009930 const FunctionProtoType::ExtProtoInfo &EPI) {
9931 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009932 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009933 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009934 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009935}
Mike Stump11289f42009-09-09 15:08:12 +00009936
Douglas Gregord6ff3322009-08-04 16:50:30 +00009937template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009938QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9939 return SemaRef.Context.getFunctionNoProtoType(T);
9940}
9941
9942template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009943QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9944 assert(D && "no decl found");
9945 if (D->isInvalidDecl()) return QualType();
9946
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009947 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009948 TypeDecl *Ty;
9949 if (isa<UsingDecl>(D)) {
9950 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009951 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009952 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9953
9954 // A valid resolved using typename decl points to exactly one type decl.
9955 assert(++Using->shadow_begin() == Using->shadow_end());
9956 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009957
John McCallb96ec562009-12-04 22:46:56 +00009958 } else {
9959 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9960 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9961 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9962 }
9963
9964 return SemaRef.Context.getTypeDeclType(Ty);
9965}
9966
9967template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009968QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9969 SourceLocation Loc) {
9970 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009971}
9972
9973template<typename Derived>
9974QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9975 return SemaRef.Context.getTypeOfType(Underlying);
9976}
9977
9978template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009979QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9980 SourceLocation Loc) {
9981 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009982}
9983
9984template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009985QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9986 UnaryTransformType::UTTKind UKind,
9987 SourceLocation Loc) {
9988 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9989}
9990
9991template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009992QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009993 TemplateName Template,
9994 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009995 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009996 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009997}
Mike Stump11289f42009-09-09 15:08:12 +00009998
Douglas Gregor1135c352009-08-06 05:28:30 +00009999template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010000QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10001 SourceLocation KWLoc) {
10002 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10003}
10004
10005template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010006TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010007TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010008 bool TemplateKW,
10009 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010010 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010011 Template);
10012}
10013
10014template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010015TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010016TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10017 const IdentifierInfo &Name,
10018 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010019 QualType ObjectType,
10020 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010021 UnqualifiedId TemplateName;
10022 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010023 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010024 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010025 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010026 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010027 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010028 /*EnteringContext=*/false,
10029 Template);
John McCall31f82722010-11-12 08:19:04 +000010030 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010031}
Mike Stump11289f42009-09-09 15:08:12 +000010032
Douglas Gregora16548e2009-08-11 05:31:07 +000010033template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010034TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010035TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010036 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010037 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010038 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010039 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010040 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010041 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010042 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010043 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010044 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010045 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010046 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010047 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010048 /*EnteringContext=*/false,
10049 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010050 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010051}
Chad Rosier1dcde962012-08-08 18:46:20 +000010052
Douglas Gregor71395fa2009-11-04 00:56:37 +000010053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010054ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010055TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10056 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010057 Expr *OrigCallee,
10058 Expr *First,
10059 Expr *Second) {
10060 Expr *Callee = OrigCallee->IgnoreParenCasts();
10061 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010062
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010063 if (First->getObjectKind() == OK_ObjCProperty) {
10064 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10065 if (BinaryOperator::isAssignmentOp(Opc))
10066 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10067 First, Second);
10068 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10069 if (Result.isInvalid())
10070 return ExprError();
10071 First = Result.get();
10072 }
10073
10074 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10075 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10076 if (Result.isInvalid())
10077 return ExprError();
10078 Second = Result.get();
10079 }
10080
Douglas Gregora16548e2009-08-11 05:31:07 +000010081 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010082 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010083 if (!First->getType()->isOverloadableType() &&
10084 !Second->getType()->isOverloadableType())
10085 return getSema().CreateBuiltinArraySubscriptExpr(First,
10086 Callee->getLocStart(),
10087 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010088 } else if (Op == OO_Arrow) {
10089 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010090 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10091 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010092 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010093 // The argument is not of overloadable type, so try to create a
10094 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010095 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010096 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010097
John McCallb268a282010-08-23 23:25:46 +000010098 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010099 }
10100 } else {
John McCallb268a282010-08-23 23:25:46 +000010101 if (!First->getType()->isOverloadableType() &&
10102 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010103 // Neither of the arguments is an overloadable type, so try to
10104 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010105 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010106 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010107 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010108 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010110
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010111 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010112 }
10113 }
Mike Stump11289f42009-09-09 15:08:12 +000010114
10115 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010116 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010117 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010118
John McCallb268a282010-08-23 23:25:46 +000010119 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010120 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010121 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010122 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010123 // If we've resolved this to a particular non-member function, just call
10124 // that function. If we resolved it to a member function,
10125 // CreateOverloaded* will find that function for us.
10126 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10127 if (!isa<CXXMethodDecl>(ND))
10128 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010129 }
Mike Stump11289f42009-09-09 15:08:12 +000010130
Douglas Gregora16548e2009-08-11 05:31:07 +000010131 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010132 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010133 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010134
Douglas Gregora16548e2009-08-11 05:31:07 +000010135 // Create the overloaded operator invocation for unary operators.
10136 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010137 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010138 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010139 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010140 }
Mike Stump11289f42009-09-09 15:08:12 +000010141
Douglas Gregore9d62932011-07-15 16:25:15 +000010142 if (Op == OO_Subscript) {
10143 SourceLocation LBrace;
10144 SourceLocation RBrace;
10145
10146 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10147 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10148 LBrace = SourceLocation::getFromRawEncoding(
10149 NameLoc.CXXOperatorName.BeginOpNameLoc);
10150 RBrace = SourceLocation::getFromRawEncoding(
10151 NameLoc.CXXOperatorName.EndOpNameLoc);
10152 } else {
10153 LBrace = Callee->getLocStart();
10154 RBrace = OpLoc;
10155 }
10156
10157 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10158 First, Second);
10159 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010160
Douglas Gregora16548e2009-08-11 05:31:07 +000010161 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010162 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010163 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010164 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10165 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010167
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010168 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010169}
Mike Stump11289f42009-09-09 15:08:12 +000010170
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010171template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010172ExprResult
John McCallb268a282010-08-23 23:25:46 +000010173TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010174 SourceLocation OperatorLoc,
10175 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010176 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010177 TypeSourceInfo *ScopeType,
10178 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010179 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010180 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010181 QualType BaseType = Base->getType();
10182 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010183 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010184 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010185 !BaseType->getAs<PointerType>()->getPointeeType()
10186 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010187 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010188 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010189 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010190 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010191 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010192 /*FIXME?*/true);
10193 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010194
Douglas Gregor678f90d2010-02-25 01:56:36 +000010195 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010196 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10197 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10198 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10199 NameInfo.setNamedTypeInfo(DestroyedType);
10200
Richard Smith8e4a3862012-05-15 06:15:11 +000010201 // The scope type is now known to be a valid nested name specifier
10202 // component. Tack it on to the end of the nested name specifier.
10203 if (ScopeType)
10204 SS.Extend(SemaRef.Context, SourceLocation(),
10205 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010206
Abramo Bagnara7945c982012-01-27 09:46:47 +000010207 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010208 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010209 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010210 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010211 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010212 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010213 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010214}
10215
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010216template<typename Derived>
10217StmtResult
10218TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010219 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010220 CapturedDecl *CD = S->getCapturedDecl();
10221 unsigned NumParams = CD->getNumParams();
10222 unsigned ContextParamPos = CD->getContextParamPosition();
10223 SmallVector<Sema::CapturedParamNameType, 4> Params;
10224 for (unsigned I = 0; I < NumParams; ++I) {
10225 if (I != ContextParamPos) {
10226 Params.push_back(
10227 std::make_pair(
10228 CD->getParam(I)->getName(),
10229 getDerived().TransformType(CD->getParam(I)->getType())));
10230 } else {
10231 Params.push_back(std::make_pair(StringRef(), QualType()));
10232 }
10233 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010234 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010235 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010236 StmtResult Body;
10237 {
10238 Sema::CompoundScopeRAII CompoundScope(getSema());
10239 Body = getDerived().TransformStmt(S->getCapturedStmt());
10240 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010241
10242 if (Body.isInvalid()) {
10243 getSema().ActOnCapturedRegionError();
10244 return StmtError();
10245 }
10246
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010247 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010248}
10249
Douglas Gregord6ff3322009-08-04 16:50:30 +000010250} // end namespace clang
10251
10252#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H