blob: 83ec591b85225b0cda09dcd02a3caa27ed724a31 [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.
Richard Smithc6abd962014-07-25 01:12:44 +0000347 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000348
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,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001301 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001302 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001303 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001304 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001305 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1306 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001307 }
1308
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309 /// \brief Build a new OpenMP 'if' clause.
1310 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001311 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1318 LParenLoc, EndLoc);
1319 }
1320
Alexey Bataev3778b602014-07-17 07:32:53 +00001321 /// \brief Build a new OpenMP 'final' clause.
1322 ///
1323 /// By default, performs semantic analysis to build the new OpenMP clause.
1324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1326 SourceLocation LParenLoc,
1327 SourceLocation EndLoc) {
1328 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1329 EndLoc);
1330 }
1331
Alexey Bataev568a8332014-03-06 06:15:19 +00001332 /// \brief Build a new OpenMP 'num_threads' clause.
1333 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001334 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001335 /// Subclasses may override this routine to provide different behavior.
1336 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1341 LParenLoc, EndLoc);
1342 }
1343
Alexey Bataev62c87d22014-03-21 04:51:18 +00001344 /// \brief Build a new OpenMP 'safelen' clause.
1345 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001346 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001347 /// Subclasses may override this routine to provide different behavior.
1348 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc) {
1351 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1352 }
1353
Alexander Musman8bd31e62014-05-27 15:12:19 +00001354 /// \brief Build a new OpenMP 'collapse' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1359 SourceLocation LParenLoc,
1360 SourceLocation EndLoc) {
1361 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1362 EndLoc);
1363 }
1364
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001365 /// \brief Build a new OpenMP 'default' clause.
1366 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001367 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001368 /// Subclasses may override this routine to provide different behavior.
1369 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1370 SourceLocation KindKwLoc,
1371 SourceLocation StartLoc,
1372 SourceLocation LParenLoc,
1373 SourceLocation EndLoc) {
1374 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1375 StartLoc, LParenLoc, EndLoc);
1376 }
1377
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001378 /// \brief Build a new OpenMP 'proc_bind' clause.
1379 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001380 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001381 /// Subclasses may override this routine to provide different behavior.
1382 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1383 SourceLocation KindKwLoc,
1384 SourceLocation StartLoc,
1385 SourceLocation LParenLoc,
1386 SourceLocation EndLoc) {
1387 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1388 StartLoc, LParenLoc, EndLoc);
1389 }
1390
Alexey Bataev56dafe82014-06-20 07:16:17 +00001391 /// \brief Build a new OpenMP 'schedule' clause.
1392 ///
1393 /// By default, performs semantic analysis to build the new OpenMP clause.
1394 /// Subclasses may override this routine to provide different behavior.
1395 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1396 Expr *ChunkSize,
1397 SourceLocation StartLoc,
1398 SourceLocation LParenLoc,
1399 SourceLocation KindLoc,
1400 SourceLocation CommaLoc,
1401 SourceLocation EndLoc) {
1402 return getSema().ActOnOpenMPScheduleClause(
1403 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1404 }
1405
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001406 /// \brief Build a new OpenMP 'private' clause.
1407 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001408 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1411 SourceLocation StartLoc,
1412 SourceLocation LParenLoc,
1413 SourceLocation EndLoc) {
1414 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1415 EndLoc);
1416 }
1417
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001418 /// \brief Build a new OpenMP 'firstprivate' clause.
1419 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001420 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1423 SourceLocation StartLoc,
1424 SourceLocation LParenLoc,
1425 SourceLocation EndLoc) {
1426 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1427 EndLoc);
1428 }
1429
Alexander Musman1bb328c2014-06-04 13:06:39 +00001430 /// \brief Build a new OpenMP 'lastprivate' clause.
1431 ///
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1435 SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 SourceLocation EndLoc) {
1438 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1439 EndLoc);
1440 }
1441
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001442 /// \brief Build a new OpenMP 'shared' clause.
1443 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001444 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001445 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001446 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1447 SourceLocation StartLoc,
1448 SourceLocation LParenLoc,
1449 SourceLocation EndLoc) {
1450 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1451 EndLoc);
1452 }
1453
Alexey Bataevc5e02582014-06-16 07:08:35 +00001454 /// \brief Build a new OpenMP 'reduction' clause.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1458 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation ColonLoc,
1462 SourceLocation EndLoc,
1463 CXXScopeSpec &ReductionIdScopeSpec,
1464 const DeclarationNameInfo &ReductionId) {
1465 return getSema().ActOnOpenMPReductionClause(
1466 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1467 ReductionId);
1468 }
1469
Alexander Musman8dba6642014-04-22 13:09:42 +00001470 /// \brief Build a new OpenMP 'linear' clause.
1471 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001472 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001473 /// Subclasses may override this routine to provide different behavior.
1474 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1475 SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation ColonLoc,
1478 SourceLocation EndLoc) {
1479 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1480 ColonLoc, EndLoc);
1481 }
1482
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001483 /// \brief Build a new OpenMP 'aligned' clause.
1484 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001485 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001486 /// Subclasses may override this routine to provide different behavior.
1487 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1488 SourceLocation StartLoc,
1489 SourceLocation LParenLoc,
1490 SourceLocation ColonLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1493 LParenLoc, ColonLoc, EndLoc);
1494 }
1495
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001496 /// \brief Build a new OpenMP 'copyin' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataevbae9a792014-06-27 10:37:06 +00001508 /// \brief Build a new OpenMP 'copyprivate' clause.
1509 ///
1510 /// By default, performs semantic analysis to build the new OpenMP clause.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1517 EndLoc);
1518 }
1519
Alexey Bataev6125da92014-07-21 11:26:11 +00001520 /// \brief Build a new OpenMP 'flush' pseudo clause.
1521 ///
1522 /// By default, performs semantic analysis to build the new OpenMP clause.
1523 /// Subclasses may override this routine to provide different behavior.
1524 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1525 SourceLocation StartLoc,
1526 SourceLocation LParenLoc,
1527 SourceLocation EndLoc) {
1528 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1529 EndLoc);
1530 }
1531
James Dennett2a4d13c2012-06-15 07:13:21 +00001532 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
1536 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1537 Expr *object) {
1538 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1539 }
1540
James Dennett2a4d13c2012-06-15 07:13:21 +00001541 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001542 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001543 /// By default, performs semantic analysis to build the new statement.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001546 Expr *Object, Stmt *Body) {
1547 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001548 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001549
James Dennett2a4d13c2012-06-15 07:13:21 +00001550 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001551 ///
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1554 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1555 Stmt *Body) {
1556 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1557 }
John McCall53848232011-07-27 01:07:15 +00001558
Douglas Gregorf68a5082010-04-22 23:10:45 +00001559 /// \brief Build a new Objective-C fast enumeration statement.
1560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001564 Stmt *Element,
1565 Expr *Collection,
1566 SourceLocation RParenLoc,
1567 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001568 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001569 Element,
John McCallb268a282010-08-23 23:25:46 +00001570 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001571 RParenLoc);
1572 if (ForEachStmt.isInvalid())
1573 return StmtError();
1574
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001575 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001577
Douglas Gregorebe10102009-08-20 07:17:43 +00001578 /// \brief Build a new C++ exception declaration.
1579 ///
1580 /// By default, performs semantic analysis to build the new decaration.
1581 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001582 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001583 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001584 SourceLocation StartLoc,
1585 SourceLocation IdLoc,
1586 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001587 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001588 StartLoc, IdLoc, Id);
1589 if (Var)
1590 getSema().CurContext->addDecl(Var);
1591 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001592 }
1593
1594 /// \brief Build a new C++ catch statement.
1595 ///
1596 /// By default, performs semantic analysis to build the new statement.
1597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001599 VarDecl *ExceptionDecl,
1600 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001601 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1602 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001603 }
Mike Stump11289f42009-09-09 15:08:12 +00001604
Douglas Gregorebe10102009-08-20 07:17:43 +00001605 /// \brief Build a new C++ try statement.
1606 ///
1607 /// By default, performs semantic analysis to build the new statement.
1608 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001609 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1610 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001611 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001612 }
Mike Stump11289f42009-09-09 15:08:12 +00001613
Richard Smith02e85f32011-04-14 22:09:26 +00001614 /// \brief Build a new C++0x range-based for statement.
1615 ///
1616 /// By default, performs semantic analysis to build the new statement.
1617 /// Subclasses may override this routine to provide different behavior.
1618 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1619 SourceLocation ColonLoc,
1620 Stmt *Range, Stmt *BeginEnd,
1621 Expr *Cond, Expr *Inc,
1622 Stmt *LoopVar,
1623 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001624 // If we've just learned that the range is actually an Objective-C
1625 // collection, treat this as an Objective-C fast enumeration loop.
1626 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1627 if (RangeStmt->isSingleDecl()) {
1628 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001629 if (RangeVar->isInvalidDecl())
1630 return StmtError();
1631
Douglas Gregorf7106af2013-04-08 18:40:13 +00001632 Expr *RangeExpr = RangeVar->getInit();
1633 if (!RangeExpr->isTypeDependent() &&
1634 RangeExpr->getType()->isObjCObjectPointerType())
1635 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1636 RParenLoc);
1637 }
1638 }
1639 }
1640
Richard Smith02e85f32011-04-14 22:09:26 +00001641 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001642 Cond, Inc, LoopVar, RParenLoc,
1643 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001644 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001645
1646 /// \brief Build a new C++0x range-based for statement.
1647 ///
1648 /// By default, performs semantic analysis to build the new statement.
1649 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001650 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001651 bool IsIfExists,
1652 NestedNameSpecifierLoc QualifierLoc,
1653 DeclarationNameInfo NameInfo,
1654 Stmt *Nested) {
1655 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1656 QualifierLoc, NameInfo, Nested);
1657 }
1658
Richard Smith02e85f32011-04-14 22:09:26 +00001659 /// \brief Attach body to a C++0x range-based for statement.
1660 ///
1661 /// By default, performs semantic analysis to finish the new statement.
1662 /// Subclasses may override this routine to provide different behavior.
1663 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1664 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001666
David Majnemerfad8f482013-10-15 09:33:02 +00001667 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001668 Stmt *TryBlock, Stmt *Handler) {
1669 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001670 }
1671
David Majnemerfad8f482013-10-15 09:33:02 +00001672 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001673 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001674 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001675 }
1676
David Majnemerfad8f482013-10-15 09:33:02 +00001677 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1678 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001679 }
1680
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 /// \brief Build a new expression that references a declaration.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001685 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001686 LookupResult &R,
1687 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001688 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1689 }
1690
1691
1692 /// \brief Build a new expression that references a declaration.
1693 ///
1694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001696 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001697 ValueDecl *VD,
1698 const DeclarationNameInfo &NameInfo,
1699 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001700 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001701 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001702
1703 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001704
1705 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001709 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001714 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 }
1716
Douglas Gregorad8a3362009-09-04 17:36:40 +00001717 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001718 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001719 /// 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 RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001722 SourceLocation OperatorLoc,
1723 bool isArrow,
1724 CXXScopeSpec &SS,
1725 TypeSourceInfo *ScopeType,
1726 SourceLocation CCLoc,
1727 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001728 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001731 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001735 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001736 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001737 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
Mike Stump11289f42009-09-09 15:08:12 +00001739
Douglas Gregor882211c2010-04-28 22:16:22 +00001740 /// \brief Build a new builtin offsetof expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001744 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001745 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001746 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001747 unsigned NumComponents,
1748 SourceLocation RParenLoc) {
1749 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1750 NumComponents, RParenLoc);
1751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001752
1753 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001754 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001755 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001758 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1759 SourceLocation OpLoc,
1760 UnaryExprOrTypeTrait ExprKind,
1761 SourceRange R) {
1762 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 }
1764
Peter Collingbournee190dee2011-03-11 19:24:49 +00001765 /// \brief Build a new sizeof, alignof or vec step expression with an
1766 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001767 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// By default, performs semantic analysis to build the new expression.
1769 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001770 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1771 UnaryExprOrTypeTrait ExprKind,
1772 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001774 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001777
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001778 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 }
Mike Stump11289f42009-09-09 15:08:12 +00001780
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001782 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001785 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001787 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001789 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001790 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 RBracketLoc);
1792 }
1793
1794 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001795 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001800 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001801 Expr *ExecConfig = nullptr) {
1802 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001803 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 }
1805
1806 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001807 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001810 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001811 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001812 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001813 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001814 const DeclarationNameInfo &MemberNameInfo,
1815 ValueDecl *Member,
1816 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001817 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001818 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001819 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1820 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001821 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001822 // We have a reference to an unnamed field. This is always the
1823 // base of an anonymous struct/union member access, i.e. the
1824 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001825 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001826 assert(Member->getType()->isRecordType() &&
1827 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001828
Richard Smithcab9a7d2011-10-26 19:06:56 +00001829 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001830 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001831 QualifierLoc.getNestedNameSpecifier(),
1832 FoundDecl, Member);
1833 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001834 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001835 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001836 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001837 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001838 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001839 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001840 cast<FieldDecl>(Member)->getType(),
1841 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001842 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001843 }
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001845 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001846 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001847
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001848 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001849 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001850
John McCall16df1e52010-03-30 21:47:33 +00001851 // FIXME: this involves duplicating earlier analysis in a lot of
1852 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001853 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001854 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001855 R.resolveKind();
1856
John McCallb268a282010-08-23 23:25:46 +00001857 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001858 SS, TemplateKWLoc,
1859 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001860 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 }
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// \brief Build a new binary operator 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 RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001868 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001869 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001870 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001874 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001877 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001878 SourceLocation QuestionLoc,
1879 Expr *LHS,
1880 SourceLocation ColonLoc,
1881 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001882 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1883 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 }
1885
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001887 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001891 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001893 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001894 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001895 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 }
Mike Stump11289f42009-09-09 15:08:12 +00001897
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001899 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001902 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001903 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001905 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001906 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001907 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 }
Mike Stump11289f42009-09-09 15:08:12 +00001909
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001911 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001914 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 SourceLocation OpLoc,
1916 SourceLocation AccessorLoc,
1917 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001918
John McCall10eae182009-11-30 22:42:35 +00001919 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001920 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001921 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001922 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001923 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001924 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001925 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001926 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 }
Mike Stump11289f42009-09-09 15:08:12 +00001928
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001930 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001933 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001934 MultiExprArg Inits,
1935 SourceLocation RBraceLoc,
1936 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001937 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001938 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001939 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001940 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001941
Douglas Gregord3d93062009-11-09 17:16:50 +00001942 // Patch in the result type we were given, which may have been computed
1943 // when the initial InitListExpr was built.
1944 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1945 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001946 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 }
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001950 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001953 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 MultiExprArg ArrayExprs,
1955 SourceLocation EqualOrColonLoc,
1956 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001957 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001958 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001960 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001963
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001964 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 }
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001968 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 /// By default, builds the implicit value initialization without performing
1970 /// any semantic analysis. Subclasses may override this routine to provide
1971 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001972 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001973 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001977 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001981 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001982 SourceLocation RParenLoc) {
1983 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001984 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001985 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 }
1987
1988 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001989 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001992 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001993 MultiExprArg SubExprs,
1994 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001995 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 }
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001999 ///
2000 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 /// rather than attempting to map the label statement itself.
2002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002003 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002004 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002005 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 }
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002009 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002012 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002015 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// \brief Build a new __builtin_choose_expr expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002023 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 SourceLocation RParenLoc) {
2025 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002026 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 RParenLoc);
2028 }
Mike Stump11289f42009-09-09 15:08:12 +00002029
Peter Collingbourne91147592011-04-15 00:35:48 +00002030 /// \brief Build a new generic selection expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
2034 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2035 SourceLocation DefaultLoc,
2036 SourceLocation RParenLoc,
2037 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002038 ArrayRef<TypeSourceInfo *> Types,
2039 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002040 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002041 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002042 }
2043
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// \brief Build a new overloaded operator call expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// The semantic analysis provides the behavior of template instantiation,
2048 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002049 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 /// argument-dependent lookup, etc. Subclasses may override this routine to
2051 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002054 Expr *Callee,
2055 Expr *First,
2056 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002057
2058 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 /// reinterpret_cast.
2060 ///
2061 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002062 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 Stmt::StmtClass Class,
2066 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002067 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 SourceLocation RAngleLoc,
2069 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002070 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 SourceLocation RParenLoc) {
2072 switch (Class) {
2073 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002074 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002075 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002076 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002077
2078 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002079 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002080 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002081 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002084 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002085 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002086 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002088
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002090 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002091 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002092 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002095 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 }
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 /// \brief Build a new C++ static_cast expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002105 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 SourceLocation RAngleLoc,
2107 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002108 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002110 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002111 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002112 SourceRange(LAngleLoc, RAngleLoc),
2113 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 }
2115
2116 /// \brief Build a new C++ dynamic_cast expression.
2117 ///
2118 /// By default, performs semantic analysis to build the new expression.
2119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002120 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002122 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 SourceLocation RAngleLoc,
2124 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002125 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002127 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002128 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002129 SourceRange(LAngleLoc, RAngleLoc),
2130 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 }
2132
2133 /// \brief Build a new C++ reinterpret_cast expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002139 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 SourceLocation RAngleLoc,
2141 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002144 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002145 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002146 SourceRange(LAngleLoc, RAngleLoc),
2147 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 }
2149
2150 /// \brief Build a new C++ const_cast expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002154 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002156 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 SourceLocation RAngleLoc,
2158 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002159 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002161 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002162 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002163 SourceRange(LAngleLoc, RAngleLoc),
2164 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 /// \brief Build a new C++ functional-style cast expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002171 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2172 SourceLocation LParenLoc,
2173 Expr *Sub,
2174 SourceLocation RParenLoc) {
2175 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002176 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 RParenLoc);
2178 }
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 /// \brief Build a new C++ typeid(type) expression.
2181 ///
2182 /// By default, performs semantic analysis to build the new expression.
2183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002185 SourceLocation TypeidLoc,
2186 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002188 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002189 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 }
Mike Stump11289f42009-09-09 15:08:12 +00002191
Francois Pichet9f4f2072010-09-08 12:20:18 +00002192
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 /// \brief Build a new C++ typeid(expr) expression.
2194 ///
2195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002197 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002198 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002199 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002201 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002202 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002203 }
2204
Francois Pichet9f4f2072010-09-08 12:20:18 +00002205 /// \brief Build a new C++ __uuidof(type) expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
2209 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2210 SourceLocation TypeidLoc,
2211 TypeSourceInfo *Operand,
2212 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002213 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002214 RParenLoc);
2215 }
2216
2217 /// \brief Build a new C++ __uuidof(expr) expression.
2218 ///
2219 /// By default, performs semantic analysis to build the new expression.
2220 /// Subclasses may override this routine to provide different behavior.
2221 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2222 SourceLocation TypeidLoc,
2223 Expr *Operand,
2224 SourceLocation RParenLoc) {
2225 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2226 RParenLoc);
2227 }
2228
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 /// \brief Build a new C++ "this" expression.
2230 ///
2231 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002232 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002234 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002235 QualType ThisType,
2236 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002237 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002238 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 }
2240
2241 /// \brief Build a new C++ throw expression.
2242 ///
2243 /// By default, performs semantic analysis to build the new expression.
2244 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002245 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2246 bool IsThrownVariableInScope) {
2247 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 }
2249
2250 /// \brief Build a new C++ default-argument expression.
2251 ///
2252 /// By default, builds a new default-argument expression, which does not
2253 /// require any semantic analysis. Subclasses may override this routine to
2254 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002255 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002256 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002257 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 }
2259
Richard Smith852c9db2013-04-20 22:23:05 +00002260 /// \brief Build a new C++11 default-initialization expression.
2261 ///
2262 /// By default, builds a new default field initialization expression, which
2263 /// does not require any semantic analysis. Subclasses may override this
2264 /// routine to provide different behavior.
2265 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2266 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002267 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002268 }
2269
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 /// \brief Build a new C++ zero-initialization expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002274 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2275 SourceLocation LParenLoc,
2276 SourceLocation RParenLoc) {
2277 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002278 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 }
Mike Stump11289f42009-09-09 15:08:12 +00002280
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 /// \brief Build a new C++ "new" expression.
2282 ///
2283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002285 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002286 bool UseGlobal,
2287 SourceLocation PlacementLParen,
2288 MultiExprArg PlacementArgs,
2289 SourceLocation PlacementRParen,
2290 SourceRange TypeIdParens,
2291 QualType AllocatedType,
2292 TypeSourceInfo *AllocatedTypeInfo,
2293 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002294 SourceRange DirectInitRange,
2295 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002296 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002298 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002300 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002301 AllocatedType,
2302 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002303 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002304 DirectInitRange,
2305 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 }
Mike Stump11289f42009-09-09 15:08:12 +00002307
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 /// \brief Build a new C++ "delete" expression.
2309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002312 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 bool IsGlobalDelete,
2314 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002315 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002317 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 }
Mike Stump11289f42009-09-09 15:08:12 +00002319
Douglas Gregor29c42f22012-02-24 07:38:34 +00002320 /// \brief Build a new type 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 RebuildTypeTrait(TypeTrait Trait,
2325 SourceLocation StartLoc,
2326 ArrayRef<TypeSourceInfo *> Args,
2327 SourceLocation RParenLoc) {
2328 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002330
John Wiegley6242b6a2011-04-28 00:16:57 +00002331 /// \brief Build a new array type trait expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2336 SourceLocation StartLoc,
2337 TypeSourceInfo *TSInfo,
2338 Expr *DimExpr,
2339 SourceLocation RParenLoc) {
2340 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2341 }
2342
John Wiegleyf9f65842011-04-25 06:54:41 +00002343 /// \brief Build a new expression trait expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
2347 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2348 SourceLocation StartLoc,
2349 Expr *Queried,
2350 SourceLocation RParenLoc) {
2351 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2352 }
2353
Mike Stump11289f42009-09-09 15:08:12 +00002354 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 /// expression.
2356 ///
2357 /// By default, performs semantic analysis to build the new expression.
2358 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002359 ExprResult RebuildDependentScopeDeclRefExpr(
2360 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002361 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002362 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002363 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002364 bool IsAddressOfOperand,
2365 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002367 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002368
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002369 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002370 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2371 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002372
Reid Kleckner32506ed2014-06-12 23:03:48 +00002373 return getSema().BuildQualifiedDeclarationNameExpr(
2374 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 }
2376
2377 /// \brief Build a new template-id expression.
2378 ///
2379 /// By default, performs semantic analysis to build the new expression.
2380 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002381 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002382 SourceLocation TemplateKWLoc,
2383 LookupResult &R,
2384 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002385 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002386 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2387 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 }
2389
2390 /// \brief Build a new object-construction expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002395 SourceLocation Loc,
2396 CXXConstructorDecl *Constructor,
2397 bool IsElidable,
2398 MultiExprArg Args,
2399 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002400 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002401 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002402 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002403 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002404 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002405 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002406 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002407 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002408 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002409
Douglas Gregordb121ba2009-12-14 16:27:04 +00002410 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002411 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002412 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002413 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002414 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002415 RequiresZeroInit, ConstructKind,
2416 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new object-construction expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002423 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2424 SourceLocation LParenLoc,
2425 MultiExprArg Args,
2426 SourceLocation RParenLoc) {
2427 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002429 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 RParenLoc);
2431 }
2432
2433 /// \brief Build a new object-construction expression.
2434 ///
2435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002437 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2438 SourceLocation LParenLoc,
2439 MultiExprArg Args,
2440 SourceLocation RParenLoc) {
2441 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002442 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002443 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 RParenLoc);
2445 }
Mike Stump11289f42009-09-09 15:08:12 +00002446
Douglas Gregora16548e2009-08-11 05:31:07 +00002447 /// \brief Build a new member reference expression.
2448 ///
2449 /// By default, performs semantic analysis to build the new expression.
2450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002451 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002452 QualType BaseType,
2453 bool IsArrow,
2454 SourceLocation OperatorLoc,
2455 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002456 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002457 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002458 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002459 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002461 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002462
John McCallb268a282010-08-23 23:25:46 +00002463 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002464 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002465 SS, TemplateKWLoc,
2466 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002467 MemberNameInfo,
2468 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002469 }
2470
John McCall10eae182009-11-30 22:42:35 +00002471 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002472 ///
2473 /// By default, performs semantic analysis to build the new expression.
2474 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002475 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2476 SourceLocation OperatorLoc,
2477 bool IsArrow,
2478 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002479 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002480 NamedDecl *FirstQualifierInScope,
2481 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002482 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002483 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002484 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002485
John McCallb268a282010-08-23 23:25:46 +00002486 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002487 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002488 SS, TemplateKWLoc,
2489 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002490 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002491 }
Mike Stump11289f42009-09-09 15:08:12 +00002492
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002493 /// \brief Build a new noexcept expression.
2494 ///
2495 /// By default, performs semantic analysis to build the new expression.
2496 /// Subclasses may override this routine to provide different behavior.
2497 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2498 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2499 }
2500
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002501 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002502 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2503 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002504 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002505 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002506 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002507 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2508 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002509 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002510
2511 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2512 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002513 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002514 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002515
Patrick Beard0caa3942012-04-19 00:25:12 +00002516 /// \brief Build a new Objective-C boxed expression.
2517 ///
2518 /// By default, performs semantic analysis to build the new expression.
2519 /// Subclasses may override this routine to provide different behavior.
2520 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2521 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002523
Ted Kremeneke65b0862012-03-06 20:05:56 +00002524 /// \brief Build a new Objective-C array literal.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
2528 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2529 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002530 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002531 MultiExprArg(Elements, NumElements));
2532 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002533
2534 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002535 Expr *Base, Expr *Key,
2536 ObjCMethodDecl *getterMethod,
2537 ObjCMethodDecl *setterMethod) {
2538 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2539 getterMethod, setterMethod);
2540 }
2541
2542 /// \brief Build a new Objective-C dictionary literal.
2543 ///
2544 /// By default, performs semantic analysis to build the new expression.
2545 /// Subclasses may override this routine to provide different behavior.
2546 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2547 ObjCDictionaryElement *Elements,
2548 unsigned NumElements) {
2549 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002551
James Dennett2a4d13c2012-06-15 07:13:21 +00002552 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 ///
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002556 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002557 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002559 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002560 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002561
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002562 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002563 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002564 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002565 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002566 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002567 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002568 MultiExprArg Args,
2569 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002570 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2571 ReceiverTypeInfo->getType(),
2572 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002573 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002574 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002575 }
2576
2577 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002578 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002579 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002580 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002581 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002582 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002583 MultiExprArg Args,
2584 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002585 return SemaRef.BuildInstanceMessage(Receiver,
2586 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002587 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002588 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002589 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002590 }
2591
Douglas Gregord51d90d2010-04-26 20:11:03 +00002592 /// \brief Build a new Objective-C ivar reference expression.
2593 ///
2594 /// By default, performs semantic analysis to build the new expression.
2595 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002596 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002597 SourceLocation IvarLoc,
2598 bool IsArrow, bool IsFreeIvar) {
2599 // FIXME: We lose track of the IsFreeIvar bit.
2600 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002601 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2602 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002603 /*FIXME:*/IvarLoc, IsArrow,
2604 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002605 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002606 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002607 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002608 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002609
2610 /// \brief Build a new Objective-C property reference expression.
2611 ///
2612 /// By default, performs semantic analysis to build the new expression.
2613 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002614 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002615 ObjCPropertyDecl *Property,
2616 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002617 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002618 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2619 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2620 /*FIXME:*/PropertyLoc,
2621 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002622 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002623 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002624 NameInfo,
2625 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002627
John McCallb7bd14f2010-12-02 01:19:52 +00002628 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002629 ///
2630 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002631 /// Subclasses may override this routine to provide different behavior.
2632 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2633 ObjCMethodDecl *Getter,
2634 ObjCMethodDecl *Setter,
2635 SourceLocation PropertyLoc) {
2636 // Since these expressions can only be value-dependent, we do not
2637 // need to perform semantic analysis again.
2638 return Owned(
2639 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2640 VK_LValue, OK_ObjCProperty,
2641 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002642 }
2643
Douglas Gregord51d90d2010-04-26 20:11:03 +00002644 /// \brief Build a new Objective-C "isa" expression.
2645 ///
2646 /// By default, performs semantic analysis to build the new expression.
2647 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002648 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002649 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002650 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002651 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2652 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002653 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002654 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002655 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002656 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002657 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002659
Douglas Gregora16548e2009-08-11 05:31:07 +00002660 /// \brief Build a new shuffle vector expression.
2661 ///
2662 /// By default, performs semantic analysis to build the new expression.
2663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002664 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002665 MultiExprArg SubExprs,
2666 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002667 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002668 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2670 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2671 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002672 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002673
Douglas Gregora16548e2009-08-11 05:31:07 +00002674 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002675 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002676 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2677 SemaRef.Context.BuiltinFnTy,
2678 VK_RValue, BuiltinLoc);
2679 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2680 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002681 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002682
2683 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002684 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002685 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002686 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002687
Douglas Gregora16548e2009-08-11 05:31:07 +00002688 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002689 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 }
John McCall31f82722010-11-12 08:19:04 +00002691
Hal Finkelc4d7c822013-09-18 03:29:45 +00002692 /// \brief Build a new convert vector expression.
2693 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2694 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2695 SourceLocation RParenLoc) {
2696 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2697 BuiltinLoc, RParenLoc);
2698 }
2699
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002700 /// \brief Build a new template argument pack expansion.
2701 ///
2702 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002703 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002704 /// different behavior.
2705 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002706 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002707 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002708 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002709 case TemplateArgument::Expression: {
2710 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002711 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2712 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002713 if (Result.isInvalid())
2714 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002715
Douglas Gregor98318c22011-01-03 21:37:45 +00002716 return TemplateArgumentLoc(Result.get(), Result.get());
2717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002718
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002719 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002720 return TemplateArgumentLoc(TemplateArgument(
2721 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002722 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002723 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002724 Pattern.getTemplateNameLoc(),
2725 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002726
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002727 case TemplateArgument::Null:
2728 case TemplateArgument::Integral:
2729 case TemplateArgument::Declaration:
2730 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002731 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002732 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002733 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002734
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002735 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002736 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002737 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002738 EllipsisLoc,
2739 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002740 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2741 Expansion);
2742 break;
2743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002744
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002745 return TemplateArgumentLoc();
2746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002747
Douglas Gregor968f23a2011-01-03 19:31:53 +00002748 /// \brief Build a new expression pack expansion.
2749 ///
2750 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002751 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002752 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002753 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002754 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002755 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002756 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002757
2758 /// \brief Build a new atomic operation expression.
2759 ///
2760 /// By default, performs semantic analysis to build the new expression.
2761 /// Subclasses may override this routine to provide different behavior.
2762 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2763 MultiExprArg SubExprs,
2764 QualType RetTy,
2765 AtomicExpr::AtomicOp Op,
2766 SourceLocation RParenLoc) {
2767 // Just create the expression; there is not any interesting semantic
2768 // analysis here because we can't actually build an AtomicExpr until
2769 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002770 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002771 RParenLoc);
2772 }
2773
John McCall31f82722010-11-12 08:19:04 +00002774private:
Douglas Gregor14454802011-02-25 02:25:35 +00002775 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2776 QualType ObjectType,
2777 NamedDecl *FirstQualifierInScope,
2778 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002779
2780 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2781 QualType ObjectType,
2782 NamedDecl *FirstQualifierInScope,
2783 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002784
2785 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2786 NamedDecl *FirstQualifierInScope,
2787 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002788};
Douglas Gregora16548e2009-08-11 05:31:07 +00002789
Douglas Gregorebe10102009-08-20 07:17:43 +00002790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002791StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002792 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002793 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002794
Douglas Gregorebe10102009-08-20 07:17:43 +00002795 switch (S->getStmtClass()) {
2796 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002797
Douglas Gregorebe10102009-08-20 07:17:43 +00002798 // Transform individual statement nodes
2799#define STMT(Node, Parent) \
2800 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002801#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002802#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002803#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002804
Douglas Gregorebe10102009-08-20 07:17:43 +00002805 // Transform expressions by calling TransformExpr.
2806#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002807#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002808#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002809#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002810 {
John McCalldadc5752010-08-24 06:29:42 +00002811 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002812 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002813 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002814
Richard Smith945f8d32013-01-14 22:39:08 +00002815 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002816 }
Mike Stump11289f42009-09-09 15:08:12 +00002817 }
2818
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002819 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002820}
Mike Stump11289f42009-09-09 15:08:12 +00002821
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002822template<typename Derived>
2823OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2824 if (!S)
2825 return S;
2826
2827 switch (S->getClauseKind()) {
2828 default: break;
2829 // Transform individual clause nodes
2830#define OPENMP_CLAUSE(Name, Class) \
2831 case OMPC_ ## Name : \
2832 return getDerived().Transform ## Class(cast<Class>(S));
2833#include "clang/Basic/OpenMPKinds.def"
2834 }
2835
2836 return S;
2837}
2838
Mike Stump11289f42009-09-09 15:08:12 +00002839
Douglas Gregore922c772009-08-04 22:27:00 +00002840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002841ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002842 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002843 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002844
2845 switch (E->getStmtClass()) {
2846 case Stmt::NoStmtClass: break;
2847#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002848#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002849#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002850 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002851#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002852 }
2853
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002854 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002855}
2856
2857template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002858ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002859 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002860 // Initializers are instantiated like expressions, except that various outer
2861 // layers are stripped.
2862 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002863 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002864
2865 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2866 Init = ExprTemp->getSubExpr();
2867
Richard Smithe6ca4752013-05-30 22:40:16 +00002868 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2869 Init = MTE->GetTemporaryExpr();
2870
Richard Smithd59b8322012-12-19 01:39:02 +00002871 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2872 Init = Binder->getSubExpr();
2873
2874 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2875 Init = ICE->getSubExprAsWritten();
2876
Richard Smithcc1b96d2013-06-12 22:31:48 +00002877 if (CXXStdInitializerListExpr *ILE =
2878 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002879 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002880
Richard Smithc6abd962014-07-25 01:12:44 +00002881 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002882 // InitListExprs. Other forms of copy-initialization will be a no-op if
2883 // the initializer is already the right type.
2884 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002885 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002886 return getDerived().TransformExpr(Init);
2887
2888 // Revert value-initialization back to empty parens.
2889 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2890 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002891 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002892 Parens.getEnd());
2893 }
2894
2895 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2896 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002897 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002898 SourceLocation());
2899
2900 // Revert initialization by constructor back to a parenthesized or braced list
2901 // of expressions. Any other form of initializer can just be reused directly.
2902 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002903 return getDerived().TransformExpr(Init);
2904
Richard Smithf8adcdc2014-07-17 05:12:35 +00002905 // If the initialization implicitly converted an initializer list to a
2906 // std::initializer_list object, unwrap the std::initializer_list too.
2907 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002908 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002909
Richard Smithd59b8322012-12-19 01:39:02 +00002910 SmallVector<Expr*, 8> NewArgs;
2911 bool ArgChanged = false;
2912 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002913 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002914 return ExprError();
2915
2916 // If this was list initialization, revert to list form.
2917 if (Construct->isListInitialization())
2918 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2919 Construct->getLocEnd(),
2920 Construct->getType());
2921
Richard Smithd59b8322012-12-19 01:39:02 +00002922 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002923 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002924 if (Parens.isInvalid()) {
2925 // This was a variable declaration's initialization for which no initializer
2926 // was specified.
2927 assert(NewArgs.empty() &&
2928 "no parens or braces but have direct init with arguments?");
2929 return ExprEmpty();
2930 }
Richard Smithd59b8322012-12-19 01:39:02 +00002931 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2932 Parens.getEnd());
2933}
2934
2935template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002936bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2937 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002938 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002939 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002940 bool *ArgChanged) {
2941 for (unsigned I = 0; I != NumInputs; ++I) {
2942 // If requested, drop call arguments that need to be dropped.
2943 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2944 if (ArgChanged)
2945 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregora3efea12011-01-03 19:04:46 +00002947 break;
2948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002949
Douglas Gregor968f23a2011-01-03 19:31:53 +00002950 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2951 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002952
Chris Lattner01cf8db2011-07-20 06:58:45 +00002953 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002954 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2955 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002956
Douglas Gregor968f23a2011-01-03 19:31:53 +00002957 // Determine whether the set of unexpanded parameter packs can and should
2958 // be expanded.
2959 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002960 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002961 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2962 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002963 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2964 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002965 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002966 Expand, RetainExpansion,
2967 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002968 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002969
Douglas Gregor968f23a2011-01-03 19:31:53 +00002970 if (!Expand) {
2971 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002972 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002973 // expansion.
2974 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2975 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2976 if (OutPattern.isInvalid())
2977 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002978
2979 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002980 Expansion->getEllipsisLoc(),
2981 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002982 if (Out.isInvalid())
2983 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Douglas Gregor968f23a2011-01-03 19:31:53 +00002985 if (ArgChanged)
2986 *ArgChanged = true;
2987 Outputs.push_back(Out.get());
2988 continue;
2989 }
John McCall542e7c62011-07-06 07:30:07 +00002990
2991 // Record right away that the argument was changed. This needs
2992 // to happen even if the array expands to nothing.
2993 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
Douglas Gregor968f23a2011-01-03 19:31:53 +00002995 // The transform has determined that we should perform an elementwise
2996 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002997 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002998 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2999 ExprResult Out = getDerived().TransformExpr(Pattern);
3000 if (Out.isInvalid())
3001 return true;
3002
Richard Smith9467be42014-06-06 17:33:35 +00003003 // FIXME: Can this happen? We should not try to expand the pack
3004 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003005 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003006 Out = getDerived().RebuildPackExpansion(
3007 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003008 if (Out.isInvalid())
3009 return true;
3010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003011
Douglas Gregor968f23a2011-01-03 19:31:53 +00003012 Outputs.push_back(Out.get());
3013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003014
Richard Smith9467be42014-06-06 17:33:35 +00003015 // If we're supposed to retain a pack expansion, do so by temporarily
3016 // forgetting the partially-substituted parameter pack.
3017 if (RetainExpansion) {
3018 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3019
3020 ExprResult Out = getDerived().TransformExpr(Pattern);
3021 if (Out.isInvalid())
3022 return true;
3023
3024 Out = getDerived().RebuildPackExpansion(
3025 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3026 if (Out.isInvalid())
3027 return true;
3028
3029 Outputs.push_back(Out.get());
3030 }
3031
Douglas Gregor968f23a2011-01-03 19:31:53 +00003032 continue;
3033 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003034
Richard Smithd59b8322012-12-19 01:39:02 +00003035 ExprResult Result =
3036 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3037 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003038 if (Result.isInvalid())
3039 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003040
Douglas Gregora3efea12011-01-03 19:04:46 +00003041 if (Result.get() != Inputs[I] && ArgChanged)
3042 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003043
3044 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003046
Douglas Gregora3efea12011-01-03 19:04:46 +00003047 return false;
3048}
3049
3050template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003051NestedNameSpecifierLoc
3052TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3053 NestedNameSpecifierLoc NNS,
3054 QualType ObjectType,
3055 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003056 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003057 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003058 Qualifier = Qualifier.getPrefix())
3059 Qualifiers.push_back(Qualifier);
3060
3061 CXXScopeSpec SS;
3062 while (!Qualifiers.empty()) {
3063 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3064 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor14454802011-02-25 02:25:35 +00003066 switch (QNNS->getKind()) {
3067 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003068 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003069 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003070 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003071 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003072 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003073 FirstQualifierInScope, false))
3074 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregor14454802011-02-25 02:25:35 +00003076 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor14454802011-02-25 02:25:35 +00003078 case NestedNameSpecifier::Namespace: {
3079 NamespaceDecl *NS
3080 = cast_or_null<NamespaceDecl>(
3081 getDerived().TransformDecl(
3082 Q.getLocalBeginLoc(),
3083 QNNS->getAsNamespace()));
3084 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3085 break;
3086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003087
Douglas Gregor14454802011-02-25 02:25:35 +00003088 case NestedNameSpecifier::NamespaceAlias: {
3089 NamespaceAliasDecl *Alias
3090 = cast_or_null<NamespaceAliasDecl>(
3091 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3092 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003093 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003094 Q.getLocalEndLoc());
3095 break;
3096 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003097
Douglas Gregor14454802011-02-25 02:25:35 +00003098 case NestedNameSpecifier::Global:
3099 // There is no meaningful transformation that one could perform on the
3100 // global scope.
3101 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3102 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
Douglas Gregor14454802011-02-25 02:25:35 +00003104 case NestedNameSpecifier::TypeSpecWithTemplate:
3105 case NestedNameSpecifier::TypeSpec: {
3106 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3107 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003108
Douglas Gregor14454802011-02-25 02:25:35 +00003109 if (!TL)
3110 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor14454802011-02-25 02:25:35 +00003112 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003113 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003114 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003115 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003116 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003117 if (TL.getType()->isEnumeralType())
3118 SemaRef.Diag(TL.getBeginLoc(),
3119 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003120 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3121 Q.getLocalEndLoc());
3122 break;
3123 }
Richard Trieude756fb2011-05-07 01:36:37 +00003124 // If the nested-name-specifier is an invalid type def, don't emit an
3125 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003126 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3127 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003128 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003129 << TL.getType() << SS.getRange();
3130 }
Douglas Gregor14454802011-02-25 02:25:35 +00003131 return NestedNameSpecifierLoc();
3132 }
Douglas Gregore16af532011-02-28 18:50:33 +00003133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregore16af532011-02-28 18:50:33 +00003135 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003136 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003137 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003138 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003139
Douglas Gregor14454802011-02-25 02:25:35 +00003140 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003141 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003142 !getDerived().AlwaysRebuild())
3143 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
3145 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003146 // nested-name-specifier, do so.
3147 if (SS.location_size() == NNS.getDataLength() &&
3148 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3149 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3150
3151 // Allocate new nested-name-specifier location information.
3152 return SS.getWithLocInContext(SemaRef.Context);
3153}
3154
3155template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003156DeclarationNameInfo
3157TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003158::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003159 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003160 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003161 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003162
3163 switch (Name.getNameKind()) {
3164 case DeclarationName::Identifier:
3165 case DeclarationName::ObjCZeroArgSelector:
3166 case DeclarationName::ObjCOneArgSelector:
3167 case DeclarationName::ObjCMultiArgSelector:
3168 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003169 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003170 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003171 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003172
Douglas Gregorf816bd72009-09-03 22:13:48 +00003173 case DeclarationName::CXXConstructorName:
3174 case DeclarationName::CXXDestructorName:
3175 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003176 TypeSourceInfo *NewTInfo;
3177 CanQualType NewCanTy;
3178 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003179 NewTInfo = getDerived().TransformType(OldTInfo);
3180 if (!NewTInfo)
3181 return DeclarationNameInfo();
3182 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003183 }
3184 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003185 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003186 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003187 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003188 if (NewT.isNull())
3189 return DeclarationNameInfo();
3190 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3191 }
Mike Stump11289f42009-09-09 15:08:12 +00003192
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003193 DeclarationName NewName
3194 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3195 NewCanTy);
3196 DeclarationNameInfo NewNameInfo(NameInfo);
3197 NewNameInfo.setName(NewName);
3198 NewNameInfo.setNamedTypeInfo(NewTInfo);
3199 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003200 }
Mike Stump11289f42009-09-09 15:08:12 +00003201 }
3202
David Blaikie83d382b2011-09-23 05:06:16 +00003203 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003204}
3205
3206template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003207TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003208TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3209 TemplateName Name,
3210 SourceLocation NameLoc,
3211 QualType ObjectType,
3212 NamedDecl *FirstQualifierInScope) {
3213 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3214 TemplateDecl *Template = QTN->getTemplateDecl();
3215 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003216
Douglas Gregor9db53502011-03-02 18:07:45 +00003217 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003218 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003219 Template));
3220 if (!TransTemplate)
3221 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Douglas Gregor9db53502011-03-02 18:07:45 +00003223 if (!getDerived().AlwaysRebuild() &&
3224 SS.getScopeRep() == QTN->getQualifier() &&
3225 TransTemplate == Template)
3226 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
Douglas Gregor9db53502011-03-02 18:07:45 +00003228 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3229 TransTemplate);
3230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
Douglas Gregor9db53502011-03-02 18:07:45 +00003232 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3233 if (SS.getScopeRep()) {
3234 // These apply to the scope specifier, not the template.
3235 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003236 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003237 }
3238
Douglas Gregor9db53502011-03-02 18:07:45 +00003239 if (!getDerived().AlwaysRebuild() &&
3240 SS.getScopeRep() == DTN->getQualifier() &&
3241 ObjectType.isNull())
3242 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003243
Douglas Gregor9db53502011-03-02 18:07:45 +00003244 if (DTN->isIdentifier()) {
3245 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003246 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003247 NameLoc,
3248 ObjectType,
3249 FirstQualifierInScope);
3250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003251
Douglas Gregor9db53502011-03-02 18:07:45 +00003252 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3253 ObjectType);
3254 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003255
Douglas Gregor9db53502011-03-02 18:07:45 +00003256 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3257 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003258 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003259 Template));
3260 if (!TransTemplate)
3261 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregor9db53502011-03-02 18:07:45 +00003263 if (!getDerived().AlwaysRebuild() &&
3264 TransTemplate == Template)
3265 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003266
Douglas Gregor9db53502011-03-02 18:07:45 +00003267 return TemplateName(TransTemplate);
3268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003269
Douglas Gregor9db53502011-03-02 18:07:45 +00003270 if (SubstTemplateTemplateParmPackStorage *SubstPack
3271 = Name.getAsSubstTemplateTemplateParmPack()) {
3272 TemplateTemplateParmDecl *TransParam
3273 = cast_or_null<TemplateTemplateParmDecl>(
3274 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3275 if (!TransParam)
3276 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003277
Douglas Gregor9db53502011-03-02 18:07:45 +00003278 if (!getDerived().AlwaysRebuild() &&
3279 TransParam == SubstPack->getParameterPack())
3280 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
3282 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003283 SubstPack->getArgumentPack());
3284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregor9db53502011-03-02 18:07:45 +00003286 // These should be getting filtered out before they reach the AST.
3287 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003288}
3289
3290template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003291void TreeTransform<Derived>::InventTemplateArgumentLoc(
3292 const TemplateArgument &Arg,
3293 TemplateArgumentLoc &Output) {
3294 SourceLocation Loc = getDerived().getBaseLocation();
3295 switch (Arg.getKind()) {
3296 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003297 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003298 break;
3299
3300 case TemplateArgument::Type:
3301 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003302 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
John McCall0ad16662009-10-29 08:12:44 +00003304 break;
3305
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003306 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003307 case TemplateArgument::TemplateExpansion: {
3308 NestedNameSpecifierLocBuilder Builder;
3309 TemplateName Template = Arg.getAsTemplate();
3310 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3311 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3312 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3313 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregor9d802122011-03-02 17:09:35 +00003315 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003316 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003317 Builder.getWithLocInContext(SemaRef.Context),
3318 Loc);
3319 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003320 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003321 Builder.getWithLocInContext(SemaRef.Context),
3322 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003324 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003325 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003326
John McCall0ad16662009-10-29 08:12:44 +00003327 case TemplateArgument::Expression:
3328 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3329 break;
3330
3331 case TemplateArgument::Declaration:
3332 case TemplateArgument::Integral:
3333 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003334 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003335 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003336 break;
3337 }
3338}
3339
3340template<typename Derived>
3341bool TreeTransform<Derived>::TransformTemplateArgument(
3342 const TemplateArgumentLoc &Input,
3343 TemplateArgumentLoc &Output) {
3344 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003345 switch (Arg.getKind()) {
3346 case TemplateArgument::Null:
3347 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003348 case TemplateArgument::Pack:
3349 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003350 case TemplateArgument::NullPtr:
3351 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregore922c772009-08-04 22:27:00 +00003353 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003354 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003355 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003356 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003357
3358 DI = getDerived().TransformType(DI);
3359 if (!DI) return true;
3360
3361 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3362 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003363 }
Mike Stump11289f42009-09-09 15:08:12 +00003364
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003365 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003366 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3367 if (QualifierLoc) {
3368 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3369 if (!QualifierLoc)
3370 return true;
3371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003372
Douglas Gregordf846d12011-03-02 18:46:51 +00003373 CXXScopeSpec SS;
3374 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003375 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003376 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3377 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003378 if (Template.isNull())
3379 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003380
Douglas Gregor9d802122011-03-02 17:09:35 +00003381 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003382 Input.getTemplateNameLoc());
3383 return false;
3384 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003385
3386 case TemplateArgument::TemplateExpansion:
3387 llvm_unreachable("Caller should expand pack expansions");
3388
Douglas Gregore922c772009-08-04 22:27:00 +00003389 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003390 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003391 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003392 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003393
John McCall0ad16662009-10-29 08:12:44 +00003394 Expr *InputExpr = Input.getSourceExpression();
3395 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3396
Chris Lattnercdb591a2011-04-25 20:37:58 +00003397 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003398 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003399 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003400 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003401 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003402 }
Douglas Gregore922c772009-08-04 22:27:00 +00003403 }
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregore922c772009-08-04 22:27:00 +00003405 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003406 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003407}
3408
Douglas Gregorfe921a72010-12-20 23:36:19 +00003409/// \brief Iterator adaptor that invents template argument location information
3410/// for each of the template arguments in its underlying iterator.
3411template<typename Derived, typename InputIterator>
3412class TemplateArgumentLocInventIterator {
3413 TreeTransform<Derived> &Self;
3414 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregorfe921a72010-12-20 23:36:19 +00003416public:
3417 typedef TemplateArgumentLoc value_type;
3418 typedef TemplateArgumentLoc reference;
3419 typedef typename std::iterator_traits<InputIterator>::difference_type
3420 difference_type;
3421 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregorfe921a72010-12-20 23:36:19 +00003423 class pointer {
3424 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregorfe921a72010-12-20 23:36:19 +00003426 public:
3427 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregorfe921a72010-12-20 23:36:19 +00003429 const TemplateArgumentLoc *operator->() const { return &Arg; }
3430 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
Douglas Gregorfe921a72010-12-20 23:36:19 +00003432 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregorfe921a72010-12-20 23:36:19 +00003434 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3435 InputIterator Iter)
3436 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregorfe921a72010-12-20 23:36:19 +00003438 TemplateArgumentLocInventIterator &operator++() {
3439 ++Iter;
3440 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Douglas Gregorfe921a72010-12-20 23:36:19 +00003443 TemplateArgumentLocInventIterator operator++(int) {
3444 TemplateArgumentLocInventIterator Old(*this);
3445 ++(*this);
3446 return Old;
3447 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003448
Douglas Gregorfe921a72010-12-20 23:36:19 +00003449 reference operator*() const {
3450 TemplateArgumentLoc Result;
3451 Self.InventTemplateArgumentLoc(*Iter, Result);
3452 return Result;
3453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003454
Douglas Gregorfe921a72010-12-20 23:36:19 +00003455 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Douglas Gregorfe921a72010-12-20 23:36:19 +00003457 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3458 const TemplateArgumentLocInventIterator &Y) {
3459 return X.Iter == Y.Iter;
3460 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003461
Douglas Gregorfe921a72010-12-20 23:36:19 +00003462 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3463 const TemplateArgumentLocInventIterator &Y) {
3464 return X.Iter != Y.Iter;
3465 }
3466};
Chad Rosier1dcde962012-08-08 18:46:20 +00003467
Douglas Gregor42cafa82010-12-20 17:42:22 +00003468template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003469template<typename InputIterator>
3470bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3471 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003472 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003473 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003474 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003475 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003476
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003477 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3478 // Unpack argument packs, which we translate them into separate
3479 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003480 // FIXME: We could do much better if we could guarantee that the
3481 // TemplateArgumentLocInfo for the pack expansion would be usable for
3482 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003483 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003484 TemplateArgument::pack_iterator>
3485 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003486 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003487 In.getArgument().pack_begin()),
3488 PackLocIterator(*this,
3489 In.getArgument().pack_end()),
3490 Outputs))
3491 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003493 continue;
3494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003495
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003496 if (In.getArgument().isPackExpansion()) {
3497 // We have a pack expansion, for which we will be substituting into
3498 // the pattern.
3499 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003500 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003501 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003502 = getSema().getTemplateArgumentPackExpansionPattern(
3503 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003504
Chris Lattner01cf8db2011-07-20 06:58:45 +00003505 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003506 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3507 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003509 // Determine whether the set of unexpanded parameter packs can and should
3510 // be expanded.
3511 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003512 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003513 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003514 if (getDerived().TryExpandParameterPacks(Ellipsis,
3515 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003516 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003517 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003518 RetainExpansion,
3519 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003520 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003522 if (!Expand) {
3523 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003524 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003525 // expansion.
3526 TemplateArgumentLoc OutPattern;
3527 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3528 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3529 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003530
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003531 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3532 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003533 if (Out.getArgument().isNull())
3534 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003536 Outputs.addArgument(Out);
3537 continue;
3538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003540 // The transform has determined that we should perform an elementwise
3541 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003542 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003543 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3544
3545 if (getDerived().TransformTemplateArgument(Pattern, Out))
3546 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003547
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003548 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003549 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3550 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003551 if (Out.getArgument().isNull())
3552 return true;
3553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003554
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003555 Outputs.addArgument(Out);
3556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003557
Douglas Gregor48d24112011-01-10 20:53:55 +00003558 // If we're supposed to retain a pack expansion, do so by temporarily
3559 // forgetting the partially-substituted parameter pack.
3560 if (RetainExpansion) {
3561 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Douglas Gregor48d24112011-01-10 20:53:55 +00003563 if (getDerived().TransformTemplateArgument(Pattern, Out))
3564 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003565
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003566 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3567 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003568 if (Out.getArgument().isNull())
3569 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003570
Douglas Gregor48d24112011-01-10 20:53:55 +00003571 Outputs.addArgument(Out);
3572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003574 continue;
3575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
3577 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003578 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003579 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor42cafa82010-12-20 17:42:22 +00003581 Outputs.addArgument(Out);
3582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003583
Douglas Gregor42cafa82010-12-20 17:42:22 +00003584 return false;
3585
3586}
3587
Douglas Gregord6ff3322009-08-04 16:50:30 +00003588//===----------------------------------------------------------------------===//
3589// Type transformation
3590//===----------------------------------------------------------------------===//
3591
3592template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003593QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003594 if (getDerived().AlreadyTransformed(T))
3595 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003596
John McCall550e0c22009-10-21 00:40:46 +00003597 // Temporary workaround. All of these transformations should
3598 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003599 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3600 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
John McCall31f82722010-11-12 08:19:04 +00003602 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003603
John McCall550e0c22009-10-21 00:40:46 +00003604 if (!NewDI)
3605 return QualType();
3606
3607 return NewDI->getType();
3608}
3609
3610template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003611TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003612 // Refine the base location to the type's location.
3613 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3614 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003615 if (getDerived().AlreadyTransformed(DI->getType()))
3616 return DI;
3617
3618 TypeLocBuilder TLB;
3619
3620 TypeLoc TL = DI->getTypeLoc();
3621 TLB.reserve(TL.getFullDataSize());
3622
John McCall31f82722010-11-12 08:19:04 +00003623 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003624 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003625 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003626
John McCallbcd03502009-12-07 02:54:59 +00003627 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003628}
3629
3630template<typename Derived>
3631QualType
John McCall31f82722010-11-12 08:19:04 +00003632TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003633 switch (T.getTypeLocClass()) {
3634#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003635#define TYPELOC(CLASS, PARENT) \
3636 case TypeLoc::CLASS: \
3637 return getDerived().Transform##CLASS##Type(TLB, \
3638 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003639#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003640 }
Mike Stump11289f42009-09-09 15:08:12 +00003641
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003642 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003643}
3644
3645/// FIXME: By default, this routine adds type qualifiers only to types
3646/// that can have qualifiers, and silently suppresses those qualifiers
3647/// that are not permitted (e.g., qualifiers on reference or function
3648/// types). This is the right thing for template instantiation, but
3649/// probably not for other clients.
3650template<typename Derived>
3651QualType
3652TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003653 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003654 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003655
John McCall31f82722010-11-12 08:19:04 +00003656 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003657 if (Result.isNull())
3658 return QualType();
3659
3660 // Silently suppress qualifiers if the result type can't be qualified.
3661 // FIXME: this is the right thing for template instantiation, but
3662 // probably not for other clients.
3663 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003664 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003665
John McCall31168b02011-06-15 23:02:42 +00003666 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003667 // resulting type.
3668 if (Quals.hasObjCLifetime()) {
3669 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3670 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003671 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003672 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003673 // A lifetime qualifier applied to a substituted template parameter
3674 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003675 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003676 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003677 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3678 QualType Replacement = SubstTypeParam->getReplacementType();
3679 Qualifiers Qs = Replacement.getQualifiers();
3680 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003681 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003682 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3683 Qs);
3684 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003685 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003686 Replacement);
3687 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003688 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3689 // 'auto' types behave the same way as template parameters.
3690 QualType Deduced = AutoTy->getDeducedType();
3691 Qualifiers Qs = Deduced.getQualifiers();
3692 Qs.removeObjCLifetime();
3693 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3694 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003695 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3696 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003697 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003698 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003699 // Otherwise, complain about the addition of a qualifier to an
3700 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003701 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003702 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003703 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003704
Douglas Gregore46db902011-06-17 22:11:49 +00003705 Quals.removeObjCLifetime();
3706 }
3707 }
3708 }
John McCallcb0f89a2010-06-05 06:41:15 +00003709 if (!Quals.empty()) {
3710 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003711 // BuildQualifiedType might not add qualifiers if they are invalid.
3712 if (Result.hasLocalQualifiers())
3713 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003714 // No location information to preserve.
3715 }
John McCall550e0c22009-10-21 00:40:46 +00003716
3717 return Result;
3718}
3719
Douglas Gregor14454802011-02-25 02:25:35 +00003720template<typename Derived>
3721TypeLoc
3722TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3723 QualType ObjectType,
3724 NamedDecl *UnqualLookup,
3725 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003726 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003727 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003729 TypeSourceInfo *TSI =
3730 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3731 if (TSI)
3732 return TSI->getTypeLoc();
3733 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003734}
3735
Douglas Gregor579c15f2011-03-02 18:32:08 +00003736template<typename Derived>
3737TypeSourceInfo *
3738TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3739 QualType ObjectType,
3740 NamedDecl *UnqualLookup,
3741 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003742 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003743 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003744
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003745 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3746 UnqualLookup, SS);
3747}
3748
3749template <typename Derived>
3750TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3751 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3752 CXXScopeSpec &SS) {
3753 QualType T = TL.getType();
3754 assert(!getDerived().AlreadyTransformed(T));
3755
Douglas Gregor579c15f2011-03-02 18:32:08 +00003756 TypeLocBuilder TLB;
3757 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003758
Douglas Gregor579c15f2011-03-02 18:32:08 +00003759 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003760 TemplateSpecializationTypeLoc SpecTL =
3761 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003762
Douglas Gregor579c15f2011-03-02 18:32:08 +00003763 TemplateName Template
3764 = getDerived().TransformTemplateName(SS,
3765 SpecTL.getTypePtr()->getTemplateName(),
3766 SpecTL.getTemplateNameLoc(),
3767 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003768 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003769 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003770
3771 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003772 Template);
3773 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003774 DependentTemplateSpecializationTypeLoc SpecTL =
3775 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003776
Douglas Gregor579c15f2011-03-02 18:32:08 +00003777 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003778 = getDerived().RebuildTemplateName(SS,
3779 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003780 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003781 ObjectType, UnqualLookup);
3782 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003783 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003784
3785 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003786 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003787 Template,
3788 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003789 } else {
3790 // Nothing special needs to be done for these.
3791 Result = getDerived().TransformType(TLB, TL);
3792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003793
3794 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003795 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003796
Douglas Gregor579c15f2011-03-02 18:32:08 +00003797 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3798}
3799
John McCall550e0c22009-10-21 00:40:46 +00003800template <class TyLoc> static inline
3801QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3802 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3803 NewT.setNameLoc(T.getNameLoc());
3804 return T.getType();
3805}
3806
John McCall550e0c22009-10-21 00:40:46 +00003807template<typename Derived>
3808QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003809 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003810 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3811 NewT.setBuiltinLoc(T.getBuiltinLoc());
3812 if (T.needsExtraLocalData())
3813 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3814 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003815}
Mike Stump11289f42009-09-09 15:08:12 +00003816
Douglas Gregord6ff3322009-08-04 16:50:30 +00003817template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003818QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003819 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003820 // FIXME: recurse?
3821 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003822}
Mike Stump11289f42009-09-09 15:08:12 +00003823
Reid Kleckner0503a872013-12-05 01:23:43 +00003824template <typename Derived>
3825QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3826 AdjustedTypeLoc TL) {
3827 // Adjustments applied during transformation are handled elsewhere.
3828 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3829}
3830
Douglas Gregord6ff3322009-08-04 16:50:30 +00003831template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003832QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3833 DecayedTypeLoc TL) {
3834 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3835 if (OriginalType.isNull())
3836 return QualType();
3837
3838 QualType Result = TL.getType();
3839 if (getDerived().AlwaysRebuild() ||
3840 OriginalType != TL.getOriginalLoc().getType())
3841 Result = SemaRef.Context.getDecayedType(OriginalType);
3842 TLB.push<DecayedTypeLoc>(Result);
3843 // Nothing to set for DecayedTypeLoc.
3844 return Result;
3845}
3846
3847template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003848QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003849 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003850 QualType PointeeType
3851 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003852 if (PointeeType.isNull())
3853 return QualType();
3854
3855 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003856 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003857 // A dependent pointer type 'T *' has is being transformed such
3858 // that an Objective-C class type is being replaced for 'T'. The
3859 // resulting pointer type is an ObjCObjectPointerType, not a
3860 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003861 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003862
John McCall8b07ec22010-05-15 11:32:37 +00003863 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3864 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003865 return Result;
3866 }
John McCall31f82722010-11-12 08:19:04 +00003867
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003868 if (getDerived().AlwaysRebuild() ||
3869 PointeeType != TL.getPointeeLoc().getType()) {
3870 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3871 if (Result.isNull())
3872 return QualType();
3873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003874
John McCall31168b02011-06-15 23:02:42 +00003875 // Objective-C ARC can add lifetime qualifiers to the type that we're
3876 // pointing to.
3877 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003878
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003879 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3880 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003881 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882}
Mike Stump11289f42009-09-09 15:08:12 +00003883
3884template<typename Derived>
3885QualType
John McCall550e0c22009-10-21 00:40:46 +00003886TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003887 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003888 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003889 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3890 if (PointeeType.isNull())
3891 return QualType();
3892
3893 QualType Result = TL.getType();
3894 if (getDerived().AlwaysRebuild() ||
3895 PointeeType != TL.getPointeeLoc().getType()) {
3896 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003897 TL.getSigilLoc());
3898 if (Result.isNull())
3899 return QualType();
3900 }
3901
Douglas Gregor049211a2010-04-22 16:50:51 +00003902 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003903 NewT.setSigilLoc(TL.getSigilLoc());
3904 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905}
3906
John McCall70dd5f62009-10-30 00:06:24 +00003907/// Transforms a reference type. Note that somewhat paradoxically we
3908/// don't care whether the type itself is an l-value type or an r-value
3909/// type; we only care if the type was *written* as an l-value type
3910/// or an r-value type.
3911template<typename Derived>
3912QualType
3913TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003914 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003915 const ReferenceType *T = TL.getTypePtr();
3916
3917 // Note that this works with the pointee-as-written.
3918 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3919 if (PointeeType.isNull())
3920 return QualType();
3921
3922 QualType Result = TL.getType();
3923 if (getDerived().AlwaysRebuild() ||
3924 PointeeType != T->getPointeeTypeAsWritten()) {
3925 Result = getDerived().RebuildReferenceType(PointeeType,
3926 T->isSpelledAsLValue(),
3927 TL.getSigilLoc());
3928 if (Result.isNull())
3929 return QualType();
3930 }
3931
John McCall31168b02011-06-15 23:02:42 +00003932 // Objective-C ARC can add lifetime qualifiers to the type that we're
3933 // referring to.
3934 TLB.TypeWasModifiedSafely(
3935 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3936
John McCall70dd5f62009-10-30 00:06:24 +00003937 // r-value references can be rebuilt as l-value references.
3938 ReferenceTypeLoc NewTL;
3939 if (isa<LValueReferenceType>(Result))
3940 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3941 else
3942 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3943 NewTL.setSigilLoc(TL.getSigilLoc());
3944
3945 return Result;
3946}
3947
Mike Stump11289f42009-09-09 15:08:12 +00003948template<typename Derived>
3949QualType
John McCall550e0c22009-10-21 00:40:46 +00003950TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003951 LValueReferenceTypeLoc TL) {
3952 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003953}
3954
Mike Stump11289f42009-09-09 15:08:12 +00003955template<typename Derived>
3956QualType
John McCall550e0c22009-10-21 00:40:46 +00003957TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003958 RValueReferenceTypeLoc TL) {
3959 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003960}
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregord6ff3322009-08-04 16:50:30 +00003962template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003963QualType
John McCall550e0c22009-10-21 00:40:46 +00003964TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003965 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003966 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003967 if (PointeeType.isNull())
3968 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003969
Abramo Bagnara509357842011-03-05 14:42:21 +00003970 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003971 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003972 if (OldClsTInfo) {
3973 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3974 if (!NewClsTInfo)
3975 return QualType();
3976 }
3977
3978 const MemberPointerType *T = TL.getTypePtr();
3979 QualType OldClsType = QualType(T->getClass(), 0);
3980 QualType NewClsType;
3981 if (NewClsTInfo)
3982 NewClsType = NewClsTInfo->getType();
3983 else {
3984 NewClsType = getDerived().TransformType(OldClsType);
3985 if (NewClsType.isNull())
3986 return QualType();
3987 }
Mike Stump11289f42009-09-09 15:08:12 +00003988
John McCall550e0c22009-10-21 00:40:46 +00003989 QualType Result = TL.getType();
3990 if (getDerived().AlwaysRebuild() ||
3991 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003992 NewClsType != OldClsType) {
3993 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003994 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003995 if (Result.isNull())
3996 return QualType();
3997 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003998
Reid Kleckner0503a872013-12-05 01:23:43 +00003999 // If we had to adjust the pointee type when building a member pointer, make
4000 // sure to push TypeLoc info for it.
4001 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4002 if (MPT && PointeeType != MPT->getPointeeType()) {
4003 assert(isa<AdjustedType>(MPT->getPointeeType()));
4004 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4005 }
4006
John McCall550e0c22009-10-21 00:40:46 +00004007 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4008 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004009 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004010
4011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012}
4013
Mike Stump11289f42009-09-09 15:08:12 +00004014template<typename Derived>
4015QualType
John McCall550e0c22009-10-21 00:40:46 +00004016TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004017 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004018 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004019 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004020 if (ElementType.isNull())
4021 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004022
John McCall550e0c22009-10-21 00:40:46 +00004023 QualType Result = TL.getType();
4024 if (getDerived().AlwaysRebuild() ||
4025 ElementType != T->getElementType()) {
4026 Result = getDerived().RebuildConstantArrayType(ElementType,
4027 T->getSizeModifier(),
4028 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004029 T->getIndexTypeCVRQualifiers(),
4030 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004031 if (Result.isNull())
4032 return QualType();
4033 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004034
4035 // We might have either a ConstantArrayType or a VariableArrayType now:
4036 // a ConstantArrayType is allowed to have an element type which is a
4037 // VariableArrayType if the type is dependent. Fortunately, all array
4038 // types have the same location layout.
4039 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004040 NewTL.setLBracketLoc(TL.getLBracketLoc());
4041 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004042
John McCall550e0c22009-10-21 00:40:46 +00004043 Expr *Size = TL.getSizeExpr();
4044 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004045 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4046 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004047 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4048 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004049 }
4050 NewTL.setSizeExpr(Size);
4051
4052 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004053}
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004057 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004058 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004059 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004060 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061 if (ElementType.isNull())
4062 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004063
John McCall550e0c22009-10-21 00:40:46 +00004064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 ElementType != T->getElementType()) {
4067 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004069 T->getIndexTypeCVRQualifiers(),
4070 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004071 if (Result.isNull())
4072 return QualType();
4073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
John McCall550e0c22009-10-21 00:40:46 +00004075 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4076 NewTL.setLBracketLoc(TL.getLBracketLoc());
4077 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004078 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004079
4080 return Result;
4081}
4082
4083template<typename Derived>
4084QualType
4085TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004086 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004087 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004088 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4089 if (ElementType.isNull())
4090 return QualType();
4091
John McCalldadc5752010-08-24 06:29:42 +00004092 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004093 = getDerived().TransformExpr(T->getSizeExpr());
4094 if (SizeResult.isInvalid())
4095 return QualType();
4096
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004097 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004098
4099 QualType Result = TL.getType();
4100 if (getDerived().AlwaysRebuild() ||
4101 ElementType != T->getElementType() ||
4102 Size != T->getSizeExpr()) {
4103 Result = getDerived().RebuildVariableArrayType(ElementType,
4104 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004105 Size,
John McCall550e0c22009-10-21 00:40:46 +00004106 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004107 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004108 if (Result.isNull())
4109 return QualType();
4110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
Serge Pavlov774c6d02014-02-06 03:49:11 +00004112 // We might have constant size array now, but fortunately it has the same
4113 // location layout.
4114 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004115 NewTL.setLBracketLoc(TL.getLBracketLoc());
4116 NewTL.setRBracketLoc(TL.getRBracketLoc());
4117 NewTL.setSizeExpr(Size);
4118
4119 return Result;
4120}
4121
4122template<typename Derived>
4123QualType
4124TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004125 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004126 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004127 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4128 if (ElementType.isNull())
4129 return QualType();
4130
Richard Smith764d2fe2011-12-20 02:08:33 +00004131 // Array bounds are constant expressions.
4132 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4133 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004134
John McCall33ddac02011-01-19 10:06:00 +00004135 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4136 Expr *origSize = TL.getSizeExpr();
4137 if (!origSize) origSize = T->getSizeExpr();
4138
4139 ExprResult sizeResult
4140 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004141 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004142 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004143 return QualType();
4144
John McCall33ddac02011-01-19 10:06:00 +00004145 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004146
4147 QualType Result = TL.getType();
4148 if (getDerived().AlwaysRebuild() ||
4149 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004150 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004151 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4152 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004153 size,
John McCall550e0c22009-10-21 00:40:46 +00004154 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004155 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004156 if (Result.isNull())
4157 return QualType();
4158 }
John McCall550e0c22009-10-21 00:40:46 +00004159
4160 // We might have any sort of array type now, but fortunately they
4161 // all have the same location layout.
4162 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4163 NewTL.setLBracketLoc(TL.getLBracketLoc());
4164 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004165 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004166
4167 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004168}
Mike Stump11289f42009-09-09 15:08:12 +00004169
4170template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004172 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004173 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004174 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004175
4176 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004177 QualType ElementType = getDerived().TransformType(T->getElementType());
4178 if (ElementType.isNull())
4179 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004180
Richard Smith764d2fe2011-12-20 02:08:33 +00004181 // Vector sizes are constant expressions.
4182 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4183 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004184
John McCalldadc5752010-08-24 06:29:42 +00004185 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004186 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004187 if (Size.isInvalid())
4188 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004189
John McCall550e0c22009-10-21 00:40:46 +00004190 QualType Result = TL.getType();
4191 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004192 ElementType != T->getElementType() ||
4193 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004194 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004195 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004196 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004197 if (Result.isNull())
4198 return QualType();
4199 }
John McCall550e0c22009-10-21 00:40:46 +00004200
4201 // Result might be dependent or not.
4202 if (isa<DependentSizedExtVectorType>(Result)) {
4203 DependentSizedExtVectorTypeLoc NewTL
4204 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4205 NewTL.setNameLoc(TL.getNameLoc());
4206 } else {
4207 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4208 NewTL.setNameLoc(TL.getNameLoc());
4209 }
4210
4211 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212}
Mike Stump11289f42009-09-09 15:08:12 +00004213
4214template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004215QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004216 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004217 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004218 QualType ElementType = getDerived().TransformType(T->getElementType());
4219 if (ElementType.isNull())
4220 return QualType();
4221
John McCall550e0c22009-10-21 00:40:46 +00004222 QualType Result = TL.getType();
4223 if (getDerived().AlwaysRebuild() ||
4224 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004225 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004226 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004227 if (Result.isNull())
4228 return QualType();
4229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004230
John McCall550e0c22009-10-21 00:40:46 +00004231 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4232 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004233
John McCall550e0c22009-10-21 00:40:46 +00004234 return Result;
4235}
4236
4237template<typename Derived>
4238QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004239 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004240 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004241 QualType ElementType = getDerived().TransformType(T->getElementType());
4242 if (ElementType.isNull())
4243 return QualType();
4244
4245 QualType Result = TL.getType();
4246 if (getDerived().AlwaysRebuild() ||
4247 ElementType != T->getElementType()) {
4248 Result = getDerived().RebuildExtVectorType(ElementType,
4249 T->getNumElements(),
4250 /*FIXME*/ SourceLocation());
4251 if (Result.isNull())
4252 return QualType();
4253 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004254
John McCall550e0c22009-10-21 00:40:46 +00004255 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4256 NewTL.setNameLoc(TL.getNameLoc());
4257
4258 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004259}
Mike Stump11289f42009-09-09 15:08:12 +00004260
David Blaikie05785d12013-02-20 22:23:23 +00004261template <typename Derived>
4262ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4263 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4264 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004265 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004266 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004267
Douglas Gregor715e4612011-01-14 22:40:04 +00004268 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004269 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004270 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004271 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004272 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004273
Douglas Gregor715e4612011-01-14 22:40:04 +00004274 TypeLocBuilder TLB;
4275 TypeLoc NewTL = OldDI->getTypeLoc();
4276 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004277
4278 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004279 OldExpansionTL.getPatternLoc());
4280 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004281 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004282
4283 Result = RebuildPackExpansionType(Result,
4284 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004285 OldExpansionTL.getEllipsisLoc(),
4286 NumExpansions);
4287 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004288 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004289
Douglas Gregor715e4612011-01-14 22:40:04 +00004290 PackExpansionTypeLoc NewExpansionTL
4291 = TLB.push<PackExpansionTypeLoc>(Result);
4292 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4293 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4294 } else
4295 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004296 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004297 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004298
John McCall8fb0d9d2011-05-01 22:35:37 +00004299 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004300 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004301
4302 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4303 OldParm->getDeclContext(),
4304 OldParm->getInnerLocStart(),
4305 OldParm->getLocation(),
4306 OldParm->getIdentifier(),
4307 NewDI->getType(),
4308 NewDI,
4309 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004310 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004311 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4312 OldParm->getFunctionScopeIndex() + indexAdjustment);
4313 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004314}
4315
4316template<typename Derived>
4317bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004318 TransformFunctionTypeParams(SourceLocation Loc,
4319 ParmVarDecl **Params, unsigned NumParams,
4320 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004321 SmallVectorImpl<QualType> &OutParamTypes,
4322 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004323 int indexAdjustment = 0;
4324
Douglas Gregordd472162011-01-07 00:20:55 +00004325 for (unsigned i = 0; i != NumParams; ++i) {
4326 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004327 assert(OldParm->getFunctionScopeIndex() == i);
4328
David Blaikie05785d12013-02-20 22:23:23 +00004329 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004330 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004331 if (OldParm->isParameterPack()) {
4332 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004333 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004334
Douglas Gregor5499af42011-01-05 23:12:31 +00004335 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004336 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004337 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004338 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4339 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004340 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4341
Douglas Gregor5499af42011-01-05 23:12:31 +00004342 // Determine whether we should expand the parameter packs.
4343 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004344 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004345 Optional<unsigned> OrigNumExpansions =
4346 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004347 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004348 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4349 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004350 Unexpanded,
4351 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004352 RetainExpansion,
4353 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004354 return true;
4355 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004356
Douglas Gregor5499af42011-01-05 23:12:31 +00004357 if (ShouldExpand) {
4358 // Expand the function parameter pack into multiple, separate
4359 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004360 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004361 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004362 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004363 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004364 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004365 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004366 OrigNumExpansions,
4367 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004368 if (!NewParm)
4369 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004370
Douglas Gregordd472162011-01-07 00:20:55 +00004371 OutParamTypes.push_back(NewParm->getType());
4372 if (PVars)
4373 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004374 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004375
4376 // If we're supposed to retain a pack expansion, do so by temporarily
4377 // forgetting the partially-substituted parameter pack.
4378 if (RetainExpansion) {
4379 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004380 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004381 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004382 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004383 OrigNumExpansions,
4384 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004385 if (!NewParm)
4386 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004387
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004388 OutParamTypes.push_back(NewParm->getType());
4389 if (PVars)
4390 PVars->push_back(NewParm);
4391 }
4392
John McCall8fb0d9d2011-05-01 22:35:37 +00004393 // The next parameter should have the same adjustment as the
4394 // last thing we pushed, but we post-incremented indexAdjustment
4395 // on every push. Also, if we push nothing, the adjustment should
4396 // go down by one.
4397 indexAdjustment--;
4398
Douglas Gregor5499af42011-01-05 23:12:31 +00004399 // We're done with the pack expansion.
4400 continue;
4401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004402
4403 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004404 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004405 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4406 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004407 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004408 NumExpansions,
4409 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004410 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004411 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004412 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004413 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004414
John McCall58f10c32010-03-11 09:03:00 +00004415 if (!NewParm)
4416 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004417
Douglas Gregordd472162011-01-07 00:20:55 +00004418 OutParamTypes.push_back(NewParm->getType());
4419 if (PVars)
4420 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004421 continue;
4422 }
John McCall58f10c32010-03-11 09:03:00 +00004423
4424 // Deal with the possibility that we don't have a parameter
4425 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004426 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004427 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004428 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004429 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004430 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004431 = dyn_cast<PackExpansionType>(OldType)) {
4432 // We have a function parameter pack that may need to be expanded.
4433 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004434 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004435 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004436
Douglas Gregor5499af42011-01-05 23:12:31 +00004437 // Determine whether we should expand the parameter packs.
4438 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004439 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004440 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004441 Unexpanded,
4442 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004443 RetainExpansion,
4444 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004445 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004447
Douglas Gregor5499af42011-01-05 23:12:31 +00004448 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004449 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004451 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004452 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4453 QualType NewType = getDerived().TransformType(Pattern);
4454 if (NewType.isNull())
4455 return true;
John McCall58f10c32010-03-11 09:03:00 +00004456
Douglas Gregordd472162011-01-07 00:20:55 +00004457 OutParamTypes.push_back(NewType);
4458 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004459 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004461
Douglas Gregor5499af42011-01-05 23:12:31 +00004462 // We're done with the pack expansion.
4463 continue;
4464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004465
Douglas Gregor48d24112011-01-10 20:53:55 +00004466 // If we're supposed to retain a pack expansion, do so by temporarily
4467 // forgetting the partially-substituted parameter pack.
4468 if (RetainExpansion) {
4469 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4470 QualType NewType = getDerived().TransformType(Pattern);
4471 if (NewType.isNull())
4472 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004473
Douglas Gregor48d24112011-01-10 20:53:55 +00004474 OutParamTypes.push_back(NewType);
4475 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004476 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004477 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004478
Chad Rosier1dcde962012-08-08 18:46:20 +00004479 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004480 // expansion.
4481 OldType = Expansion->getPattern();
4482 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4484 NewType = getDerived().TransformType(OldType);
4485 } else {
4486 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004488
Douglas Gregor5499af42011-01-05 23:12:31 +00004489 if (NewType.isNull())
4490 return true;
4491
4492 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004493 NewType = getSema().Context.getPackExpansionType(NewType,
4494 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004495
Douglas Gregordd472162011-01-07 00:20:55 +00004496 OutParamTypes.push_back(NewType);
4497 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004498 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004499 }
4500
John McCall8fb0d9d2011-05-01 22:35:37 +00004501#ifndef NDEBUG
4502 if (PVars) {
4503 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4504 if (ParmVarDecl *parm = (*PVars)[i])
4505 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004506 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004507#endif
4508
4509 return false;
4510}
John McCall58f10c32010-03-11 09:03:00 +00004511
4512template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004513QualType
John McCall550e0c22009-10-21 00:40:46 +00004514TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004515 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004516 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004517}
4518
4519template<typename Derived>
4520QualType
4521TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4522 FunctionProtoTypeLoc TL,
4523 CXXRecordDecl *ThisContext,
4524 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004525 // Transform the parameters and return type.
4526 //
Richard Smithf623c962012-04-17 00:58:00 +00004527 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004528 // When the function has a trailing return type, we instantiate the
4529 // parameters before the return type, since the return type can then refer
4530 // to the parameters themselves (via decltype, sizeof, etc.).
4531 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004532 SmallVector<QualType, 4> ParamTypes;
4533 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004534 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004535
Douglas Gregor7fb25412010-10-01 18:44:50 +00004536 QualType ResultType;
4537
Richard Smith1226c602012-08-14 22:51:13 +00004538 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004539 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004540 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004541 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004542 return QualType();
4543
Douglas Gregor3024f072012-04-16 07:05:22 +00004544 {
4545 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004546 // If a declaration declares a member function or member function
4547 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004548 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004549 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004550 // declarator.
4551 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004552
Alp Toker42a16a62014-01-25 23:51:36 +00004553 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004554 if (ResultType.isNull())
4555 return QualType();
4556 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004557 }
4558 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004559 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004560 if (ResultType.isNull())
4561 return QualType();
4562
Alp Toker9cacbab2014-01-20 20:26:09 +00004563 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004564 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004565 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004566 return QualType();
4567 }
4568
Richard Smithf623c962012-04-17 00:58:00 +00004569 // FIXME: Need to transform the exception-specification too.
4570
John McCall550e0c22009-10-21 00:40:46 +00004571 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004572 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004573 T->getNumParams() != ParamTypes.size() ||
4574 !std::equal(T->param_type_begin(), T->param_type_end(),
4575 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004576 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004577 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004578 if (Result.isNull())
4579 return QualType();
4580 }
Mike Stump11289f42009-09-09 15:08:12 +00004581
John McCall550e0c22009-10-21 00:40:46 +00004582 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004583 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004584 NewTL.setLParenLoc(TL.getLParenLoc());
4585 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004586 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004587 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4588 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004589
4590 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004591}
Mike Stump11289f42009-09-09 15:08:12 +00004592
Douglas Gregord6ff3322009-08-04 16:50:30 +00004593template<typename Derived>
4594QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004595 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004596 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004597 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004598 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004599 if (ResultType.isNull())
4600 return QualType();
4601
4602 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004603 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004604 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4605
4606 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004607 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004608 NewTL.setLParenLoc(TL.getLParenLoc());
4609 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004610 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004611
4612 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004613}
Mike Stump11289f42009-09-09 15:08:12 +00004614
John McCallb96ec562009-12-04 22:46:56 +00004615template<typename Derived> QualType
4616TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004617 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004618 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004619 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004620 if (!D)
4621 return QualType();
4622
4623 QualType Result = TL.getType();
4624 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4625 Result = getDerived().RebuildUnresolvedUsingType(D);
4626 if (Result.isNull())
4627 return QualType();
4628 }
4629
4630 // We might get an arbitrary type spec type back. We should at
4631 // least always get a type spec type, though.
4632 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4633 NewTL.setNameLoc(TL.getNameLoc());
4634
4635 return Result;
4636}
4637
Douglas Gregord6ff3322009-08-04 16:50:30 +00004638template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004639QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004640 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004641 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004642 TypedefNameDecl *Typedef
4643 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4644 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004645 if (!Typedef)
4646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004647
John McCall550e0c22009-10-21 00:40:46 +00004648 QualType Result = TL.getType();
4649 if (getDerived().AlwaysRebuild() ||
4650 Typedef != T->getDecl()) {
4651 Result = getDerived().RebuildTypedefType(Typedef);
4652 if (Result.isNull())
4653 return QualType();
4654 }
Mike Stump11289f42009-09-09 15:08:12 +00004655
John McCall550e0c22009-10-21 00:40:46 +00004656 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4657 NewTL.setNameLoc(TL.getNameLoc());
4658
4659 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004660}
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004663QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004664 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004665 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004666 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4667 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004668
John McCalldadc5752010-08-24 06:29:42 +00004669 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004670 if (E.isInvalid())
4671 return QualType();
4672
Eli Friedmane4f22df2012-02-29 04:03:55 +00004673 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4674 if (E.isInvalid())
4675 return QualType();
4676
John McCall550e0c22009-10-21 00:40:46 +00004677 QualType Result = TL.getType();
4678 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004679 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004680 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004681 if (Result.isNull())
4682 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004683 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004684 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004685
John McCall550e0c22009-10-21 00:40:46 +00004686 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004687 NewTL.setTypeofLoc(TL.getTypeofLoc());
4688 NewTL.setLParenLoc(TL.getLParenLoc());
4689 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004690
4691 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692}
Mike Stump11289f42009-09-09 15:08:12 +00004693
4694template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004695QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004696 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004697 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4698 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4699 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004700 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004701
John McCall550e0c22009-10-21 00:40:46 +00004702 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004703 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4704 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004705 if (Result.isNull())
4706 return QualType();
4707 }
Mike Stump11289f42009-09-09 15:08:12 +00004708
John McCall550e0c22009-10-21 00:40:46 +00004709 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004710 NewTL.setTypeofLoc(TL.getTypeofLoc());
4711 NewTL.setLParenLoc(TL.getLParenLoc());
4712 NewTL.setRParenLoc(TL.getRParenLoc());
4713 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004714
4715 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004716}
Mike Stump11289f42009-09-09 15:08:12 +00004717
4718template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004719QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004720 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004721 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004722
Douglas Gregore922c772009-08-04 22:27:00 +00004723 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004724 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4725 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004726
John McCalldadc5752010-08-24 06:29:42 +00004727 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004728 if (E.isInvalid())
4729 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004730
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004731 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004732 if (E.isInvalid())
4733 return QualType();
4734
John McCall550e0c22009-10-21 00:40:46 +00004735 QualType Result = TL.getType();
4736 if (getDerived().AlwaysRebuild() ||
4737 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004738 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004739 if (Result.isNull())
4740 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004742 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004743
John McCall550e0c22009-10-21 00:40:46 +00004744 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4745 NewTL.setNameLoc(TL.getNameLoc());
4746
4747 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004748}
4749
4750template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004751QualType TreeTransform<Derived>::TransformUnaryTransformType(
4752 TypeLocBuilder &TLB,
4753 UnaryTransformTypeLoc TL) {
4754 QualType Result = TL.getType();
4755 if (Result->isDependentType()) {
4756 const UnaryTransformType *T = TL.getTypePtr();
4757 QualType NewBase =
4758 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4759 Result = getDerived().RebuildUnaryTransformType(NewBase,
4760 T->getUTTKind(),
4761 TL.getKWLoc());
4762 if (Result.isNull())
4763 return QualType();
4764 }
4765
4766 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4767 NewTL.setKWLoc(TL.getKWLoc());
4768 NewTL.setParensRange(TL.getParensRange());
4769 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4770 return Result;
4771}
4772
4773template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004774QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4775 AutoTypeLoc TL) {
4776 const AutoType *T = TL.getTypePtr();
4777 QualType OldDeduced = T->getDeducedType();
4778 QualType NewDeduced;
4779 if (!OldDeduced.isNull()) {
4780 NewDeduced = getDerived().TransformType(OldDeduced);
4781 if (NewDeduced.isNull())
4782 return QualType();
4783 }
4784
4785 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004786 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4787 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004788 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004789 if (Result.isNull())
4790 return QualType();
4791 }
4792
4793 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4794 NewTL.setNameLoc(TL.getNameLoc());
4795
4796 return Result;
4797}
4798
4799template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004800QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004801 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004802 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004803 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004804 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4805 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004806 if (!Record)
4807 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004808
John McCall550e0c22009-10-21 00:40:46 +00004809 QualType Result = TL.getType();
4810 if (getDerived().AlwaysRebuild() ||
4811 Record != T->getDecl()) {
4812 Result = getDerived().RebuildRecordType(Record);
4813 if (Result.isNull())
4814 return QualType();
4815 }
Mike Stump11289f42009-09-09 15:08:12 +00004816
John McCall550e0c22009-10-21 00:40:46 +00004817 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4818 NewTL.setNameLoc(TL.getNameLoc());
4819
4820 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004821}
Mike Stump11289f42009-09-09 15:08:12 +00004822
4823template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004824QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004825 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004826 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004827 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004828 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4829 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004830 if (!Enum)
4831 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004832
John McCall550e0c22009-10-21 00:40:46 +00004833 QualType Result = TL.getType();
4834 if (getDerived().AlwaysRebuild() ||
4835 Enum != T->getDecl()) {
4836 Result = getDerived().RebuildEnumType(Enum);
4837 if (Result.isNull())
4838 return QualType();
4839 }
Mike Stump11289f42009-09-09 15:08:12 +00004840
John McCall550e0c22009-10-21 00:40:46 +00004841 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4842 NewTL.setNameLoc(TL.getNameLoc());
4843
4844 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004845}
John McCallfcc33b02009-09-05 00:15:47 +00004846
John McCalle78aac42010-03-10 03:28:59 +00004847template<typename Derived>
4848QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4849 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004850 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004851 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4852 TL.getTypePtr()->getDecl());
4853 if (!D) return QualType();
4854
4855 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4856 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4857 return T;
4858}
4859
Douglas Gregord6ff3322009-08-04 16:50:30 +00004860template<typename Derived>
4861QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004862 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004863 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004864 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004865}
4866
Mike Stump11289f42009-09-09 15:08:12 +00004867template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004868QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004869 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004870 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004871 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004872
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004873 // Substitute into the replacement type, which itself might involve something
4874 // that needs to be transformed. This only tends to occur with default
4875 // template arguments of template template parameters.
4876 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4877 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4878 if (Replacement.isNull())
4879 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004880
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004881 // Always canonicalize the replacement type.
4882 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4883 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004884 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004885 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004886
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004887 // Propagate type-source information.
4888 SubstTemplateTypeParmTypeLoc NewTL
4889 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4890 NewTL.setNameLoc(TL.getNameLoc());
4891 return Result;
4892
John McCallcebee162009-10-18 09:09:24 +00004893}
4894
4895template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004896QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4897 TypeLocBuilder &TLB,
4898 SubstTemplateTypeParmPackTypeLoc TL) {
4899 return TransformTypeSpecType(TLB, TL);
4900}
4901
4902template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004903QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004904 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004905 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004906 const TemplateSpecializationType *T = TL.getTypePtr();
4907
Douglas Gregordf846d12011-03-02 18:46:51 +00004908 // The nested-name-specifier never matters in a TemplateSpecializationType,
4909 // because we can't have a dependent nested-name-specifier anyway.
4910 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004911 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004912 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4913 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004914 if (Template.isNull())
4915 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004916
John McCall31f82722010-11-12 08:19:04 +00004917 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4918}
4919
Eli Friedman0dfb8892011-10-06 23:00:33 +00004920template<typename Derived>
4921QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4922 AtomicTypeLoc TL) {
4923 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4924 if (ValueType.isNull())
4925 return QualType();
4926
4927 QualType Result = TL.getType();
4928 if (getDerived().AlwaysRebuild() ||
4929 ValueType != TL.getValueLoc().getType()) {
4930 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4931 if (Result.isNull())
4932 return QualType();
4933 }
4934
4935 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4936 NewTL.setKWLoc(TL.getKWLoc());
4937 NewTL.setLParenLoc(TL.getLParenLoc());
4938 NewTL.setRParenLoc(TL.getRParenLoc());
4939
4940 return Result;
4941}
4942
Chad Rosier1dcde962012-08-08 18:46:20 +00004943 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004944 /// container that provides a \c getArgLoc() member function.
4945 ///
4946 /// This iterator is intended to be used with the iterator form of
4947 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4948 template<typename ArgLocContainer>
4949 class TemplateArgumentLocContainerIterator {
4950 ArgLocContainer *Container;
4951 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004952
Douglas Gregorfe921a72010-12-20 23:36:19 +00004953 public:
4954 typedef TemplateArgumentLoc value_type;
4955 typedef TemplateArgumentLoc reference;
4956 typedef int difference_type;
4957 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004958
Douglas Gregorfe921a72010-12-20 23:36:19 +00004959 class pointer {
4960 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004961
Douglas Gregorfe921a72010-12-20 23:36:19 +00004962 public:
4963 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004964
Douglas Gregorfe921a72010-12-20 23:36:19 +00004965 const TemplateArgumentLoc *operator->() const {
4966 return &Arg;
4967 }
4968 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004969
4970
Douglas Gregorfe921a72010-12-20 23:36:19 +00004971 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004972
Douglas Gregorfe921a72010-12-20 23:36:19 +00004973 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4974 unsigned Index)
4975 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004976
Douglas Gregorfe921a72010-12-20 23:36:19 +00004977 TemplateArgumentLocContainerIterator &operator++() {
4978 ++Index;
4979 return *this;
4980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004981
Douglas Gregorfe921a72010-12-20 23:36:19 +00004982 TemplateArgumentLocContainerIterator operator++(int) {
4983 TemplateArgumentLocContainerIterator Old(*this);
4984 ++(*this);
4985 return Old;
4986 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004987
Douglas Gregorfe921a72010-12-20 23:36:19 +00004988 TemplateArgumentLoc operator*() const {
4989 return Container->getArgLoc(Index);
4990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004991
Douglas Gregorfe921a72010-12-20 23:36:19 +00004992 pointer operator->() const {
4993 return pointer(Container->getArgLoc(Index));
4994 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004995
Douglas Gregorfe921a72010-12-20 23:36:19 +00004996 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004997 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004998 return X.Container == Y.Container && X.Index == Y.Index;
4999 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005000
Douglas Gregorfe921a72010-12-20 23:36:19 +00005001 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005002 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005003 return !(X == Y);
5004 }
5005 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005006
5007
John McCall31f82722010-11-12 08:19:04 +00005008template <typename Derived>
5009QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5010 TypeLocBuilder &TLB,
5011 TemplateSpecializationTypeLoc TL,
5012 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005013 TemplateArgumentListInfo NewTemplateArgs;
5014 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5015 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005016 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5017 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005018 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005019 ArgIterator(TL, TL.getNumArgs()),
5020 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005021 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005022
John McCall0ad16662009-10-29 08:12:44 +00005023 // FIXME: maybe don't rebuild if all the template arguments are the same.
5024
5025 QualType Result =
5026 getDerived().RebuildTemplateSpecializationType(Template,
5027 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005028 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005029
5030 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005031 // Specializations of template template parameters are represented as
5032 // TemplateSpecializationTypes, and substitution of type alias templates
5033 // within a dependent context can transform them into
5034 // DependentTemplateSpecializationTypes.
5035 if (isa<DependentTemplateSpecializationType>(Result)) {
5036 DependentTemplateSpecializationTypeLoc NewTL
5037 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005038 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005039 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005040 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005041 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005042 NewTL.setLAngleLoc(TL.getLAngleLoc());
5043 NewTL.setRAngleLoc(TL.getRAngleLoc());
5044 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5045 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5046 return Result;
5047 }
5048
John McCall0ad16662009-10-29 08:12:44 +00005049 TemplateSpecializationTypeLoc NewTL
5050 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005051 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005052 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5053 NewTL.setLAngleLoc(TL.getLAngleLoc());
5054 NewTL.setRAngleLoc(TL.getRAngleLoc());
5055 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5056 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005057 }
Mike Stump11289f42009-09-09 15:08:12 +00005058
John McCall0ad16662009-10-29 08:12:44 +00005059 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060}
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregor5a064722011-02-28 17:23:35 +00005062template <typename Derived>
5063QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5064 TypeLocBuilder &TLB,
5065 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005066 TemplateName Template,
5067 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005068 TemplateArgumentListInfo NewTemplateArgs;
5069 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5070 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5071 typedef TemplateArgumentLocContainerIterator<
5072 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005073 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005074 ArgIterator(TL, TL.getNumArgs()),
5075 NewTemplateArgs))
5076 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005077
Douglas Gregor5a064722011-02-28 17:23:35 +00005078 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005079
Douglas Gregor5a064722011-02-28 17:23:35 +00005080 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5081 QualType Result
5082 = getSema().Context.getDependentTemplateSpecializationType(
5083 TL.getTypePtr()->getKeyword(),
5084 DTN->getQualifier(),
5085 DTN->getIdentifier(),
5086 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005087
Douglas Gregor5a064722011-02-28 17:23:35 +00005088 DependentTemplateSpecializationTypeLoc NewTL
5089 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005090 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005091 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005092 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005093 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005094 NewTL.setLAngleLoc(TL.getLAngleLoc());
5095 NewTL.setRAngleLoc(TL.getRAngleLoc());
5096 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5097 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5098 return Result;
5099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005100
5101 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005102 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005103 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005104 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005105
Douglas Gregor5a064722011-02-28 17:23:35 +00005106 if (!Result.isNull()) {
5107 /// FIXME: Wrap this in an elaborated-type-specifier?
5108 TemplateSpecializationTypeLoc NewTL
5109 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005110 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005111 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005112 NewTL.setLAngleLoc(TL.getLAngleLoc());
5113 NewTL.setRAngleLoc(TL.getRAngleLoc());
5114 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5115 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5116 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005117
Douglas Gregor5a064722011-02-28 17:23:35 +00005118 return Result;
5119}
5120
Mike Stump11289f42009-09-09 15:08:12 +00005121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005122QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005123TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005124 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005125 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005126
Douglas Gregor844cb502011-03-01 18:12:44 +00005127 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005128 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005129 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005130 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005131 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5132 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005133 return QualType();
5134 }
Mike Stump11289f42009-09-09 15:08:12 +00005135
John McCall31f82722010-11-12 08:19:04 +00005136 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5137 if (NamedT.isNull())
5138 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005139
Richard Smith3f1b5d02011-05-05 21:57:07 +00005140 // C++0x [dcl.type.elab]p2:
5141 // If the identifier resolves to a typedef-name or the simple-template-id
5142 // resolves to an alias template specialization, the
5143 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005144 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5145 if (const TemplateSpecializationType *TST =
5146 NamedT->getAs<TemplateSpecializationType>()) {
5147 TemplateName Template = TST->getTemplateName();
5148 if (TypeAliasTemplateDecl *TAT =
5149 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5150 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5151 diag::err_tag_reference_non_tag) << 4;
5152 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5153 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005154 }
5155 }
5156
John McCall550e0c22009-10-21 00:40:46 +00005157 QualType Result = TL.getType();
5158 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005159 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005160 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005161 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005162 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005163 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005164 if (Result.isNull())
5165 return QualType();
5166 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005167
Abramo Bagnara6150c882010-05-11 21:36:43 +00005168 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005169 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005170 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005171 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005172}
Mike Stump11289f42009-09-09 15:08:12 +00005173
5174template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005175QualType TreeTransform<Derived>::TransformAttributedType(
5176 TypeLocBuilder &TLB,
5177 AttributedTypeLoc TL) {
5178 const AttributedType *oldType = TL.getTypePtr();
5179 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5180 if (modifiedType.isNull())
5181 return QualType();
5182
5183 QualType result = TL.getType();
5184
5185 // FIXME: dependent operand expressions?
5186 if (getDerived().AlwaysRebuild() ||
5187 modifiedType != oldType->getModifiedType()) {
5188 // TODO: this is really lame; we should really be rebuilding the
5189 // equivalent type from first principles.
5190 QualType equivalentType
5191 = getDerived().TransformType(oldType->getEquivalentType());
5192 if (equivalentType.isNull())
5193 return QualType();
5194 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5195 modifiedType,
5196 equivalentType);
5197 }
5198
5199 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5200 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5201 if (TL.hasAttrOperand())
5202 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5203 if (TL.hasAttrExprOperand())
5204 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5205 else if (TL.hasAttrEnumOperand())
5206 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5207
5208 return result;
5209}
5210
5211template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005212QualType
5213TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5214 ParenTypeLoc TL) {
5215 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5216 if (Inner.isNull())
5217 return QualType();
5218
5219 QualType Result = TL.getType();
5220 if (getDerived().AlwaysRebuild() ||
5221 Inner != TL.getInnerLoc().getType()) {
5222 Result = getDerived().RebuildParenType(Inner);
5223 if (Result.isNull())
5224 return QualType();
5225 }
5226
5227 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5228 NewTL.setLParenLoc(TL.getLParenLoc());
5229 NewTL.setRParenLoc(TL.getRParenLoc());
5230 return Result;
5231}
5232
5233template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005234QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005235 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005236 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005237
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005238 NestedNameSpecifierLoc QualifierLoc
5239 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5240 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005242
John McCallc392f372010-06-11 00:33:02 +00005243 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005244 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005245 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005246 QualifierLoc,
5247 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005248 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005249 if (Result.isNull())
5250 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005251
Abramo Bagnarad7548482010-05-19 21:37:53 +00005252 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5253 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005254 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5255
Abramo Bagnarad7548482010-05-19 21:37:53 +00005256 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005257 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005258 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005259 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005260 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005261 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005262 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005263 NewTL.setNameLoc(TL.getNameLoc());
5264 }
John McCall550e0c22009-10-21 00:40:46 +00005265 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005266}
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005269QualType TreeTransform<Derived>::
5270 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005271 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005272 NestedNameSpecifierLoc QualifierLoc;
5273 if (TL.getQualifierLoc()) {
5274 QualifierLoc
5275 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5276 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005277 return QualType();
5278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005279
John McCall31f82722010-11-12 08:19:04 +00005280 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005281 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005282}
5283
5284template<typename Derived>
5285QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005286TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5287 DependentTemplateSpecializationTypeLoc TL,
5288 NestedNameSpecifierLoc QualifierLoc) {
5289 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005290
Douglas Gregora7a795b2011-03-01 20:11:18 +00005291 TemplateArgumentListInfo NewTemplateArgs;
5292 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5293 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005294
Douglas Gregora7a795b2011-03-01 20:11:18 +00005295 typedef TemplateArgumentLocContainerIterator<
5296 DependentTemplateSpecializationTypeLoc> ArgIterator;
5297 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5298 ArgIterator(TL, TL.getNumArgs()),
5299 NewTemplateArgs))
5300 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005301
Douglas Gregora7a795b2011-03-01 20:11:18 +00005302 QualType Result
5303 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5304 QualifierLoc,
5305 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005306 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005307 NewTemplateArgs);
5308 if (Result.isNull())
5309 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005310
Douglas Gregora7a795b2011-03-01 20:11:18 +00005311 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5312 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005313
Douglas Gregora7a795b2011-03-01 20:11:18 +00005314 // Copy information relevant to the template specialization.
5315 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005316 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005317 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005318 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005319 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5320 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005321 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005322 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005323
Douglas Gregora7a795b2011-03-01 20:11:18 +00005324 // Copy information relevant to the elaborated type.
5325 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005326 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005327 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005328 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5329 DependentTemplateSpecializationTypeLoc SpecTL
5330 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005331 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005332 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005333 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005334 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005335 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5336 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005337 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005338 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005339 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005340 TemplateSpecializationTypeLoc SpecTL
5341 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005342 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005343 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005344 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5345 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005346 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005347 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005348 }
5349 return Result;
5350}
5351
5352template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005353QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5354 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005355 QualType Pattern
5356 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005357 if (Pattern.isNull())
5358 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005359
5360 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005361 if (getDerived().AlwaysRebuild() ||
5362 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005363 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005364 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005365 TL.getEllipsisLoc(),
5366 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005367 if (Result.isNull())
5368 return QualType();
5369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005370
Douglas Gregor822d0302011-01-12 17:07:58 +00005371 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5372 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5373 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005374}
5375
5376template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005377QualType
5378TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005379 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005380 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005381 TLB.pushFullCopy(TL);
5382 return TL.getType();
5383}
5384
5385template<typename Derived>
5386QualType
5387TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005388 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005389 // ObjCObjectType is never dependent.
5390 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005391 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392}
Mike Stump11289f42009-09-09 15:08:12 +00005393
5394template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005395QualType
5396TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005397 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005398 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005399 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005400 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005401}
5402
Douglas Gregord6ff3322009-08-04 16:50:30 +00005403//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005404// Statement transformation
5405//===----------------------------------------------------------------------===//
5406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005407StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005408TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005409 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005410}
5411
5412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005413StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005414TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5415 return getDerived().TransformCompoundStmt(S, false);
5416}
5417
5418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005419StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005420TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005421 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005422 Sema::CompoundScopeRAII CompoundScope(getSema());
5423
John McCall1ababa62010-08-27 19:56:05 +00005424 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005425 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005426 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005427 for (auto *B : S->body()) {
5428 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005429 if (Result.isInvalid()) {
5430 // Immediately fail if this was a DeclStmt, since it's very
5431 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005432 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005433 return StmtError();
5434
5435 // Otherwise, just keep processing substatements and fail later.
5436 SubStmtInvalid = true;
5437 continue;
5438 }
Mike Stump11289f42009-09-09 15:08:12 +00005439
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005440 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005441 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005442 }
Mike Stump11289f42009-09-09 15:08:12 +00005443
John McCall1ababa62010-08-27 19:56:05 +00005444 if (SubStmtInvalid)
5445 return StmtError();
5446
Douglas Gregorebe10102009-08-20 07:17:43 +00005447 if (!getDerived().AlwaysRebuild() &&
5448 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005449 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005450
5451 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005452 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005453 S->getRBracLoc(),
5454 IsStmtExpr);
5455}
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005458StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005459TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005460 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005461 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005462 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5463 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005464
Eli Friedman06577382009-11-19 03:14:00 +00005465 // Transform the left-hand case value.
5466 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005467 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005468 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005470
Eli Friedman06577382009-11-19 03:14:00 +00005471 // Transform the right-hand case value (for the GNU case-range extension).
5472 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005473 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005474 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005475 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005476 }
Mike Stump11289f42009-09-09 15:08:12 +00005477
Douglas Gregorebe10102009-08-20 07:17:43 +00005478 // Build the case statement.
5479 // Case statements are always rebuilt so that they will attached to their
5480 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005481 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005482 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005484 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 S->getColonLoc());
5486 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005487 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005488
Douglas Gregorebe10102009-08-20 07:17:43 +00005489 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005490 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005491 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005495 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005496}
5497
5498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005499StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005500TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005502 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregorebe10102009-08-20 07:17:43 +00005506 // Default statements are always rebuilt
5507 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005508 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005509}
Mike Stump11289f42009-09-09 15:08:12 +00005510
Douglas Gregorebe10102009-08-20 07:17:43 +00005511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005512StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005513TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005514 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005516 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005517
Chris Lattnercab02a62011-02-17 20:34:02 +00005518 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5519 S->getDecl());
5520 if (!LD)
5521 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005522
5523
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005525 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005526 cast<LabelDecl>(LD), SourceLocation(),
5527 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005528}
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregorebe10102009-08-20 07:17:43 +00005530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005531StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005532TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5533 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5534 if (SubStmt.isInvalid())
5535 return StmtError();
5536
5537 // TODO: transform attributes
5538 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5539 return S;
5540
5541 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5542 S->getAttrs(),
5543 SubStmt.get());
5544}
5545
5546template<typename Derived>
5547StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005548TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005549 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005550 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005551 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005552 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005553 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005554 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005555 getDerived().TransformDefinition(
5556 S->getConditionVariable()->getLocation(),
5557 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005558 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005559 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005560 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005561 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005562
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005563 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005564 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005565
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005566 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005567 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005568 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005569 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005570 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005571 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005572
John McCallb268a282010-08-23 23:25:46 +00005573 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005574 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005576
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005577 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005578 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005580
Douglas Gregorebe10102009-08-20 07:17:43 +00005581 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005582 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005584 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregorebe10102009-08-20 07:17:43 +00005586 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005587 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005589 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005590
Douglas Gregorebe10102009-08-20 07:17:43 +00005591 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005592 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005593 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005594 Then.get() == S->getThen() &&
5595 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005596 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005598 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005599 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005600 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005601}
5602
5603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005604StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005605TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005607 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005608 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005609 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005610 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005611 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005612 getDerived().TransformDefinition(
5613 S->getConditionVariable()->getLocation(),
5614 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005615 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005616 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005617 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005618 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005619
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005620 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005621 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005622 }
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005625 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005626 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005627 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005628 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005629 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005630
Douglas Gregorebe10102009-08-20 07:17:43 +00005631 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005632 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005633 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005634 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregorebe10102009-08-20 07:17:43 +00005636 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005637 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5638 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005639}
Mike Stump11289f42009-09-09 15:08:12 +00005640
Douglas Gregorebe10102009-08-20 07:17:43 +00005641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005642StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005643TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005644 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005646 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005647 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005648 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005649 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005650 getDerived().TransformDefinition(
5651 S->getConditionVariable()->getLocation(),
5652 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005653 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005654 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005655 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005656 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005657
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005658 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005659 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005660
5661 if (S->getCond()) {
5662 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005663 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5664 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005665 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005666 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005667 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005668 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005669 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005670 }
Mike Stump11289f42009-09-09 15:08:12 +00005671
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005672 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005673 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005675
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005677 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregorebe10102009-08-20 07:17:43 +00005681 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005682 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005683 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005685 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005687 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005688 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005689}
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005693TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005695 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005697 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005698
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005699 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005700 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005701 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005702 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005703
Douglas Gregorebe10102009-08-20 07:17:43 +00005704 if (!getDerived().AlwaysRebuild() &&
5705 Cond.get() == S->getCond() &&
5706 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005707 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005708
John McCallb268a282010-08-23 23:25:46 +00005709 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5710 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005711 S->getRParenLoc());
5712}
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregorebe10102009-08-20 07:17:43 +00005714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005715StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005716TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005717 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005718 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005719 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregorebe10102009-08-20 07:17:43 +00005722 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005723 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005724 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005725 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005726 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005727 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005728 getDerived().TransformDefinition(
5729 S->getConditionVariable()->getLocation(),
5730 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005731 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005732 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005733 } else {
5734 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005735
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005736 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005737 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005738
5739 if (S->getCond()) {
5740 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005741 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5742 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005743 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005744 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005745 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005746
John McCallb268a282010-08-23 23:25:46 +00005747 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005748 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005749 }
Mike Stump11289f42009-09-09 15:08:12 +00005750
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005751 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005752 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005753 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005754
Douglas Gregorebe10102009-08-20 07:17:43 +00005755 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005756 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005758 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005759
Richard Smith945f8d32013-01-14 22:39:08 +00005760 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005761 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005762 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005763
Douglas Gregorebe10102009-08-20 07:17:43 +00005764 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005765 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005766 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005767 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregorebe10102009-08-20 07:17:43 +00005769 if (!getDerived().AlwaysRebuild() &&
5770 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005771 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005772 Inc.get() == S->getInc() &&
5773 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005774 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregorebe10102009-08-20 07:17:43 +00005776 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005777 Init.get(), FullCond, ConditionVar,
5778 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005779}
5780
5781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005782StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005783TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005784 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5785 S->getLabel());
5786 if (!LD)
5787 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005788
Douglas Gregorebe10102009-08-20 07:17:43 +00005789 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005790 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005791 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005792}
5793
5794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005795StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005796TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005797 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005798 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005799 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005800 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregorebe10102009-08-20 07:17:43 +00005802 if (!getDerived().AlwaysRebuild() &&
5803 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005804 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005805
5806 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005807 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005808}
5809
5810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005811StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005812TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005813 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005814}
Mike Stump11289f42009-09-09 15:08:12 +00005815
Douglas Gregorebe10102009-08-20 07:17:43 +00005816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005817StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005818TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005819 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005820}
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregorebe10102009-08-20 07:17:43 +00005822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005824TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005825 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005826 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005827 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005828
Mike Stump11289f42009-09-09 15:08:12 +00005829 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005830 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005831 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005832}
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregorebe10102009-08-20 07:17:43 +00005834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005836TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005838 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005839 for (auto *D : S->decls()) {
5840 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005841 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005842 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005843
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005844 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005845 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005846
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 Decls.push_back(Transformed);
5848 }
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005851 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005852
Rafael Espindolaab417692013-07-09 12:05:01 +00005853 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005854}
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregorebe10102009-08-20 07:17:43 +00005856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005857StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005858TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005859
Benjamin Kramerf0623432012-08-23 22:51:59 +00005860 SmallVector<Expr*, 8> Constraints;
5861 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005862 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005863
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005865 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005866
5867 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Anders Carlssonaaeef072010-01-24 05:50:09 +00005869 // Go through the outputs.
5870 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005871 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005872
Anders Carlssonaaeef072010-01-24 05:50:09 +00005873 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005874 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005875
Anders Carlssonaaeef072010-01-24 05:50:09 +00005876 // Transform the output expr.
5877 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005878 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005879 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
Anders Carlssonaaeef072010-01-24 05:50:09 +00005882 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005883
John McCallb268a282010-08-23 23:25:46 +00005884 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
Anders Carlssonaaeef072010-01-24 05:50:09 +00005887 // Go through the inputs.
5888 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005889 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005890
Anders Carlssonaaeef072010-01-24 05:50:09 +00005891 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005892 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005893
Anders Carlssonaaeef072010-01-24 05:50:09 +00005894 // Transform the input expr.
5895 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005896 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005897 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005899
Anders Carlssonaaeef072010-01-24 05:50:09 +00005900 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
John McCallb268a282010-08-23 23:25:46 +00005902 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005903 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
Anders Carlssonaaeef072010-01-24 05:50:09 +00005905 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005906 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005907
5908 // Go through the clobbers.
5909 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005910 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005911
5912 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005913 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005914 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5915 S->isVolatile(), S->getNumOutputs(),
5916 S->getNumInputs(), Names.data(),
5917 Constraints, Exprs, AsmString.get(),
5918 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005919}
5920
Chad Rosier32503022012-06-11 20:47:18 +00005921template<typename Derived>
5922StmtResult
5923TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005924 ArrayRef<Token> AsmToks =
5925 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005926
John McCallf413f5e2013-05-03 00:10:13 +00005927 bool HadError = false, HadChange = false;
5928
5929 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5930 SmallVector<Expr*, 8> TransformedExprs;
5931 TransformedExprs.reserve(SrcExprs.size());
5932 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5933 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5934 if (!Result.isUsable()) {
5935 HadError = true;
5936 } else {
5937 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005938 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005939 }
5940 }
5941
5942 if (HadError) return StmtError();
5943 if (!HadChange && !getDerived().AlwaysRebuild())
5944 return Owned(S);
5945
Chad Rosierb6f46c12012-08-15 16:53:30 +00005946 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005947 AsmToks, S->getAsmString(),
5948 S->getNumOutputs(), S->getNumInputs(),
5949 S->getAllConstraints(), S->getClobbers(),
5950 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005951}
Douglas Gregorebe10102009-08-20 07:17:43 +00005952
5953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005954StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005955TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005956 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005957 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005958 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005960
Douglas Gregor96c79492010-04-23 22:50:49 +00005961 // Transform the @catch statements (if present).
5962 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005963 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005964 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005965 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005966 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005968 if (Catch.get() != S->getCatchStmt(I))
5969 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005970 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005972
Douglas Gregor306de2f2010-04-22 23:59:56 +00005973 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005974 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005975 if (S->getFinallyStmt()) {
5976 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5977 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005979 }
5980
5981 // If nothing changed, just retain this statement.
5982 if (!getDerived().AlwaysRebuild() &&
5983 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005984 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005985 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005986 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005987
Douglas Gregor306de2f2010-04-22 23:59:56 +00005988 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005989 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005990 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005991}
Mike Stump11289f42009-09-09 15:08:12 +00005992
Douglas Gregorebe10102009-08-20 07:17:43 +00005993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005994StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005995TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005996 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005997 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005998 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005999 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006000 if (FromVar->getTypeSourceInfo()) {
6001 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6002 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006004 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006005
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006006 QualType T;
6007 if (TSInfo)
6008 T = TSInfo->getType();
6009 else {
6010 T = getDerived().TransformType(FromVar->getType());
6011 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006012 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006014
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006015 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6016 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
John McCalldadc5752010-08-24 06:29:42 +00006020 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006021 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006023
6024 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006025 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006026 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006027}
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregorebe10102009-08-20 07:17:43 +00006029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006030StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006031TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006032 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006033 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006034 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006036
Douglas Gregor306de2f2010-04-22 23:59:56 +00006037 // If nothing changed, just retain this statement.
6038 if (!getDerived().AlwaysRebuild() &&
6039 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006040 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006041
6042 // Build a new statement.
6043 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006044 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006045}
Mike Stump11289f42009-09-09 15:08:12 +00006046
Douglas Gregorebe10102009-08-20 07:17:43 +00006047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006048StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006049TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006050 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006051 if (S->getThrowExpr()) {
6052 Operand = getDerived().TransformExpr(S->getThrowExpr());
6053 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006056
Douglas Gregor2900c162010-04-22 21:44:01 +00006057 if (!getDerived().AlwaysRebuild() &&
6058 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006059 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006060
John McCallb268a282010-08-23 23:25:46 +00006061 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006062}
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregorebe10102009-08-20 07:17:43 +00006064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006065StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006066TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006067 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006068 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006069 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006070 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006072 Object =
6073 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6074 Object.get());
6075 if (Object.isInvalid())
6076 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
Douglas Gregor6148de72010-04-22 22:01:21 +00006078 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006079 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006080 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006081 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006082
Douglas Gregor6148de72010-04-22 22:01:21 +00006083 // If nothing change, just retain the current statement.
6084 if (!getDerived().AlwaysRebuild() &&
6085 Object.get() == S->getSynchExpr() &&
6086 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006087 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006088
6089 // Build a new statement.
6090 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006091 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006092}
6093
6094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006095StmtResult
John McCall31168b02011-06-15 23:02:42 +00006096TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6097 ObjCAutoreleasePoolStmt *S) {
6098 // Transform the body.
6099 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6100 if (Body.isInvalid())
6101 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006102
John McCall31168b02011-06-15 23:02:42 +00006103 // If nothing changed, just retain this statement.
6104 if (!getDerived().AlwaysRebuild() &&
6105 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006106 return S;
John McCall31168b02011-06-15 23:02:42 +00006107
6108 // Build a new statement.
6109 return getDerived().RebuildObjCAutoreleasePoolStmt(
6110 S->getAtLoc(), Body.get());
6111}
6112
6113template<typename Derived>
6114StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006115TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006116 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006117 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006118 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006119 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
Douglas Gregorf68a5082010-04-22 23:10:45 +00006122 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006123 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006124 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
Douglas Gregorf68a5082010-04-22 23:10:45 +00006127 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006128 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006129 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006131
Douglas Gregorf68a5082010-04-22 23:10:45 +00006132 // If nothing changed, just retain this statement.
6133 if (!getDerived().AlwaysRebuild() &&
6134 Element.get() == S->getElement() &&
6135 Collection.get() == S->getCollection() &&
6136 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006137 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006138
Douglas Gregorf68a5082010-04-22 23:10:45 +00006139 // Build a new statement.
6140 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006141 Element.get(),
6142 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006143 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006144 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006145}
6146
David Majnemer5f7efef2013-10-15 09:50:08 +00006147template <typename Derived>
6148StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006149 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006150 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006151 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6152 TypeSourceInfo *T =
6153 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006154 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006156
David Majnemer5f7efef2013-10-15 09:50:08 +00006157 Var = getDerived().RebuildExceptionDecl(
6158 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6159 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006160 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006161 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006162 }
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregorebe10102009-08-20 07:17:43 +00006164 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006165 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006166 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006167 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006168
David Majnemer5f7efef2013-10-15 09:50:08 +00006169 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006171 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006172
David Majnemer5f7efef2013-10-15 09:50:08 +00006173 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006174}
Mike Stump11289f42009-09-09 15:08:12 +00006175
David Majnemer5f7efef2013-10-15 09:50:08 +00006176template <typename Derived>
6177StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006179 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006180 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006181 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 // Transform the handlers.
6184 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006185 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006186 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006187 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006188 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006189 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregorebe10102009-08-20 07:17:43 +00006191 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006192 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006193 }
Mike Stump11289f42009-09-09 15:08:12 +00006194
David Majnemer5f7efef2013-10-15 09:50:08 +00006195 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006197 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006198
John McCallb268a282010-08-23 23:25:46 +00006199 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006200 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006201}
Mike Stump11289f42009-09-09 15:08:12 +00006202
Richard Smith02e85f32011-04-14 22:09:26 +00006203template<typename Derived>
6204StmtResult
6205TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6206 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6207 if (Range.isInvalid())
6208 return StmtError();
6209
6210 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6211 if (BeginEnd.isInvalid())
6212 return StmtError();
6213
6214 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6215 if (Cond.isInvalid())
6216 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006217 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006218 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006219 if (Cond.isInvalid())
6220 return StmtError();
6221 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006222 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006223
6224 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6225 if (Inc.isInvalid())
6226 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006227 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006228 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006229
6230 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6231 if (LoopVar.isInvalid())
6232 return StmtError();
6233
6234 StmtResult NewStmt = S;
6235 if (getDerived().AlwaysRebuild() ||
6236 Range.get() != S->getRangeStmt() ||
6237 BeginEnd.get() != S->getBeginEndStmt() ||
6238 Cond.get() != S->getCond() ||
6239 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006240 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006241 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6242 S->getColonLoc(), Range.get(),
6243 BeginEnd.get(), Cond.get(),
6244 Inc.get(), LoopVar.get(),
6245 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006246 if (NewStmt.isInvalid())
6247 return StmtError();
6248 }
Richard Smith02e85f32011-04-14 22:09:26 +00006249
6250 StmtResult Body = getDerived().TransformStmt(S->getBody());
6251 if (Body.isInvalid())
6252 return StmtError();
6253
6254 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6255 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006256 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006257 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6258 S->getColonLoc(), Range.get(),
6259 BeginEnd.get(), Cond.get(),
6260 Inc.get(), LoopVar.get(),
6261 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006262 if (NewStmt.isInvalid())
6263 return StmtError();
6264 }
Richard Smith02e85f32011-04-14 22:09:26 +00006265
6266 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006267 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006268
6269 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6270}
6271
John Wiegley1c0675e2011-04-28 01:08:34 +00006272template<typename Derived>
6273StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006274TreeTransform<Derived>::TransformMSDependentExistsStmt(
6275 MSDependentExistsStmt *S) {
6276 // Transform the nested-name-specifier, if any.
6277 NestedNameSpecifierLoc QualifierLoc;
6278 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006279 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006280 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6281 if (!QualifierLoc)
6282 return StmtError();
6283 }
6284
6285 // Transform the declaration name.
6286 DeclarationNameInfo NameInfo = S->getNameInfo();
6287 if (NameInfo.getName()) {
6288 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6289 if (!NameInfo.getName())
6290 return StmtError();
6291 }
6292
6293 // Check whether anything changed.
6294 if (!getDerived().AlwaysRebuild() &&
6295 QualifierLoc == S->getQualifierLoc() &&
6296 NameInfo.getName() == S->getNameInfo().getName())
6297 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006298
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006299 // Determine whether this name exists, if we can.
6300 CXXScopeSpec SS;
6301 SS.Adopt(QualifierLoc);
6302 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006303 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006304 case Sema::IER_Exists:
6305 if (S->isIfExists())
6306 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006307
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006308 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6309
6310 case Sema::IER_DoesNotExist:
6311 if (S->isIfNotExists())
6312 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006313
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006314 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006315
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006316 case Sema::IER_Dependent:
6317 Dependent = true;
6318 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006319
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006320 case Sema::IER_Error:
6321 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006323
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006324 // We need to continue with the instantiation, so do so now.
6325 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6326 if (SubStmt.isInvalid())
6327 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006328
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006329 // If we have resolved the name, just transform to the substatement.
6330 if (!Dependent)
6331 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006333 // The name is still dependent, so build a dependent expression again.
6334 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6335 S->isIfExists(),
6336 QualifierLoc,
6337 NameInfo,
6338 SubStmt.get());
6339}
6340
6341template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006342ExprResult
6343TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6344 NestedNameSpecifierLoc QualifierLoc;
6345 if (E->getQualifierLoc()) {
6346 QualifierLoc
6347 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6348 if (!QualifierLoc)
6349 return ExprError();
6350 }
6351
6352 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6353 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6354 if (!PD)
6355 return ExprError();
6356
6357 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6358 if (Base.isInvalid())
6359 return ExprError();
6360
6361 return new (SemaRef.getASTContext())
6362 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6363 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6364 QualifierLoc, E->getMemberLoc());
6365}
6366
David Majnemerfad8f482013-10-15 09:33:02 +00006367template <typename Derived>
6368StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006369 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006370 if (TryBlock.isInvalid())
6371 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006372
6373 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006374 if (Handler.isInvalid())
6375 return StmtError();
6376
David Majnemerfad8f482013-10-15 09:33:02 +00006377 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6378 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006379 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006380
Warren Huntf6be4cb2014-07-25 20:52:51 +00006381 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6382 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006383}
6384
David Majnemerfad8f482013-10-15 09:33:02 +00006385template <typename Derived>
6386StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006387 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006388 if (Block.isInvalid())
6389 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006390
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006391 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006392}
6393
David Majnemerfad8f482013-10-15 09:33:02 +00006394template <typename Derived>
6395StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006396 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006397 if (FilterExpr.isInvalid())
6398 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006399
David Majnemer7e755502013-10-15 09:30:14 +00006400 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006401 if (Block.isInvalid())
6402 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006403
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006404 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6405 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006406}
6407
David Majnemerfad8f482013-10-15 09:33:02 +00006408template <typename Derived>
6409StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6410 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006411 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6412 else
6413 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6414}
6415
Nico Weber9b982072014-07-07 00:12:30 +00006416template<typename Derived>
6417StmtResult
6418TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6419 return S;
6420}
6421
Alexander Musman64d33f12014-06-04 07:53:32 +00006422//===----------------------------------------------------------------------===//
6423// OpenMP directive transformation
6424//===----------------------------------------------------------------------===//
6425template <typename Derived>
6426StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6427 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006428
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006429 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006430 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006431 ArrayRef<OMPClause *> Clauses = D->clauses();
6432 TClauses.reserve(Clauses.size());
6433 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6434 I != E; ++I) {
6435 if (*I) {
6436 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006437 if (Clause)
6438 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006439 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006440 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006441 }
6442 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006443 StmtResult AssociatedStmt;
6444 if (D->hasAssociatedStmt()) {
6445 if (!D->getAssociatedStmt()) {
6446 return StmtError();
6447 }
6448 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6449 if (AssociatedStmt.isInvalid()) {
6450 return StmtError();
6451 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006452 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006453 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006454 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006455 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006456
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006457 // Transform directive name for 'omp critical' directive.
6458 DeclarationNameInfo DirName;
6459 if (D->getDirectiveKind() == OMPD_critical) {
6460 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6461 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6462 }
6463
Alexander Musman64d33f12014-06-04 07:53:32 +00006464 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006465 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6466 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006467}
6468
Alexander Musman64d33f12014-06-04 07:53:32 +00006469template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006470StmtResult
6471TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6472 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006473 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6474 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006475 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6476 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6477 return Res;
6478}
6479
Alexander Musman64d33f12014-06-04 07:53:32 +00006480template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006481StmtResult
6482TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6483 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006484 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6485 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006486 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6487 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006488 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006489}
6490
Alexey Bataevf29276e2014-06-18 04:14:57 +00006491template <typename Derived>
6492StmtResult
6493TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6494 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006495 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6496 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6498 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6499 return Res;
6500}
6501
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006502template <typename Derived>
6503StmtResult
6504TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6505 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006506 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6507 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6509 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6510 return Res;
6511}
6512
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006513template <typename Derived>
6514StmtResult
6515TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6516 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006517 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6518 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006519 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6520 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6521 return Res;
6522}
6523
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006524template <typename Derived>
6525StmtResult
6526TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6527 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006528 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6529 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006530 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6531 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6532 return Res;
6533}
6534
Alexey Bataev4acb8592014-07-07 13:01:15 +00006535template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006536StmtResult
6537TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6538 DeclarationNameInfo DirName;
6539 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6540 D->getLocStart());
6541 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6542 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6543 return Res;
6544}
6545
6546template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006547StmtResult
6548TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6549 getDerived().getSema().StartOpenMPDSABlock(
6550 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6551 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6552 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6553 return Res;
6554}
6555
6556template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006557StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6558 OMPParallelForDirective *D) {
6559 DeclarationNameInfo DirName;
6560 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6561 nullptr, D->getLocStart());
6562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6563 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6564 return Res;
6565}
6566
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006567template <typename Derived>
6568StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6569 OMPParallelSectionsDirective *D) {
6570 DeclarationNameInfo DirName;
6571 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6572 nullptr, D->getLocStart());
6573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6574 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6575 return Res;
6576}
6577
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006578template <typename Derived>
6579StmtResult
6580TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6581 DeclarationNameInfo DirName;
6582 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6583 D->getLocStart());
6584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6585 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6586 return Res;
6587}
6588
Alexey Bataev68446b72014-07-18 07:47:19 +00006589template <typename Derived>
6590StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6591 OMPTaskyieldDirective *D) {
6592 DeclarationNameInfo DirName;
6593 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6594 D->getLocStart());
6595 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6596 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6597 return Res;
6598}
6599
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006600template <typename Derived>
6601StmtResult
6602TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6603 DeclarationNameInfo DirName;
6604 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6605 D->getLocStart());
6606 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6607 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6608 return Res;
6609}
6610
Alexey Bataev2df347a2014-07-18 10:17:07 +00006611template <typename Derived>
6612StmtResult
6613TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6614 DeclarationNameInfo DirName;
6615 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6616 D->getLocStart());
6617 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6618 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6619 return Res;
6620}
6621
Alexey Bataev6125da92014-07-21 11:26:11 +00006622template <typename Derived>
6623StmtResult
6624TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6625 DeclarationNameInfo DirName;
6626 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6627 D->getLocStart());
6628 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6629 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6630 return Res;
6631}
6632
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006633template <typename Derived>
6634StmtResult
6635TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6636 DeclarationNameInfo DirName;
6637 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6638 D->getLocStart());
6639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6640 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6641 return Res;
6642}
6643
Alexey Bataev0162e452014-07-22 10:10:35 +00006644template <typename Derived>
6645StmtResult
6646TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6647 DeclarationNameInfo DirName;
6648 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6649 D->getLocStart());
6650 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6651 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6652 return Res;
6653}
6654
Alexander Musman64d33f12014-06-04 07:53:32 +00006655//===----------------------------------------------------------------------===//
6656// OpenMP clause transformation
6657//===----------------------------------------------------------------------===//
6658template <typename Derived>
6659OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006660 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6661 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006662 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006663 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006664 C->getLParenLoc(), C->getLocEnd());
6665}
6666
Alexander Musman64d33f12014-06-04 07:53:32 +00006667template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006668OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6669 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6670 if (Cond.isInvalid())
6671 return nullptr;
6672 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6673 C->getLParenLoc(), C->getLocEnd());
6674}
6675
6676template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006677OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006678TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6679 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6680 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006681 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006682 return getDerived().RebuildOMPNumThreadsClause(
6683 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006684}
6685
Alexey Bataev62c87d22014-03-21 04:51:18 +00006686template <typename Derived>
6687OMPClause *
6688TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6689 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6690 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006691 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006692 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006693 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006694}
6695
Alexander Musman8bd31e62014-05-27 15:12:19 +00006696template <typename Derived>
6697OMPClause *
6698TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6699 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6700 if (E.isInvalid())
6701 return 0;
6702 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006703 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006704}
6705
Alexander Musman64d33f12014-06-04 07:53:32 +00006706template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006707OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006708TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006709 return getDerived().RebuildOMPDefaultClause(
6710 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6711 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006712}
6713
Alexander Musman64d33f12014-06-04 07:53:32 +00006714template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006715OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006716TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006717 return getDerived().RebuildOMPProcBindClause(
6718 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6719 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006720}
6721
Alexander Musman64d33f12014-06-04 07:53:32 +00006722template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006723OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006724TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6725 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6726 if (E.isInvalid())
6727 return nullptr;
6728 return getDerived().RebuildOMPScheduleClause(
6729 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6730 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6731}
6732
6733template <typename Derived>
6734OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006735TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6736 // No need to rebuild this clause, no template-dependent parameters.
6737 return C;
6738}
6739
6740template <typename Derived>
6741OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006742TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6743 // No need to rebuild this clause, no template-dependent parameters.
6744 return C;
6745}
6746
6747template <typename Derived>
6748OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006749TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6750 // No need to rebuild this clause, no template-dependent parameters.
6751 return C;
6752}
6753
6754template <typename Derived>
6755OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006756TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6757 // No need to rebuild this clause, no template-dependent parameters.
6758 return C;
6759}
6760
6761template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006762OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6763 // No need to rebuild this clause, no template-dependent parameters.
6764 return C;
6765}
6766
6767template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006768OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6769 // No need to rebuild this clause, no template-dependent parameters.
6770 return C;
6771}
6772
6773template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006774OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006775TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6776 // No need to rebuild this clause, no template-dependent parameters.
6777 return C;
6778}
6779
6780template <typename Derived>
6781OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006782TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6783 // No need to rebuild this clause, no template-dependent parameters.
6784 return C;
6785}
6786
6787template <typename Derived>
6788OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006789TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6790 // No need to rebuild this clause, no template-dependent parameters.
6791 return C;
6792}
6793
6794template <typename Derived>
6795OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006796TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006797 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006798 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006799 for (auto *VE : C->varlists()) {
6800 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006801 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006802 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006803 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006804 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006805 return getDerived().RebuildOMPPrivateClause(
6806 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006807}
6808
Alexander Musman64d33f12014-06-04 07:53:32 +00006809template <typename Derived>
6810OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6811 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006812 llvm::SmallVector<Expr *, 16> Vars;
6813 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006814 for (auto *VE : C->varlists()) {
6815 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006816 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006817 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006818 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006819 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006820 return getDerived().RebuildOMPFirstprivateClause(
6821 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006822}
6823
Alexander Musman64d33f12014-06-04 07:53:32 +00006824template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006825OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006826TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6827 llvm::SmallVector<Expr *, 16> Vars;
6828 Vars.reserve(C->varlist_size());
6829 for (auto *VE : C->varlists()) {
6830 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6831 if (EVar.isInvalid())
6832 return nullptr;
6833 Vars.push_back(EVar.get());
6834 }
6835 return getDerived().RebuildOMPLastprivateClause(
6836 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6837}
6838
6839template <typename Derived>
6840OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006841TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6842 llvm::SmallVector<Expr *, 16> Vars;
6843 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006844 for (auto *VE : C->varlists()) {
6845 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006846 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006847 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006848 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006849 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006850 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6851 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006852}
6853
Alexander Musman64d33f12014-06-04 07:53:32 +00006854template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006855OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006856TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6857 llvm::SmallVector<Expr *, 16> Vars;
6858 Vars.reserve(C->varlist_size());
6859 for (auto *VE : C->varlists()) {
6860 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6861 if (EVar.isInvalid())
6862 return nullptr;
6863 Vars.push_back(EVar.get());
6864 }
6865 CXXScopeSpec ReductionIdScopeSpec;
6866 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6867
6868 DeclarationNameInfo NameInfo = C->getNameInfo();
6869 if (NameInfo.getName()) {
6870 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6871 if (!NameInfo.getName())
6872 return nullptr;
6873 }
6874 return getDerived().RebuildOMPReductionClause(
6875 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6876 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6877}
6878
6879template <typename Derived>
6880OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006881TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6882 llvm::SmallVector<Expr *, 16> Vars;
6883 Vars.reserve(C->varlist_size());
6884 for (auto *VE : C->varlists()) {
6885 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6886 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006887 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006888 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006889 }
6890 ExprResult Step = getDerived().TransformExpr(C->getStep());
6891 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006892 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006893 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6894 C->getLParenLoc(),
6895 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006896}
6897
Alexander Musman64d33f12014-06-04 07:53:32 +00006898template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006899OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006900TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6901 llvm::SmallVector<Expr *, 16> Vars;
6902 Vars.reserve(C->varlist_size());
6903 for (auto *VE : C->varlists()) {
6904 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6905 if (EVar.isInvalid())
6906 return nullptr;
6907 Vars.push_back(EVar.get());
6908 }
6909 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6910 if (Alignment.isInvalid())
6911 return nullptr;
6912 return getDerived().RebuildOMPAlignedClause(
6913 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6914 C->getColonLoc(), C->getLocEnd());
6915}
6916
Alexander Musman64d33f12014-06-04 07:53:32 +00006917template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006918OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006919TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6920 llvm::SmallVector<Expr *, 16> Vars;
6921 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006922 for (auto *VE : C->varlists()) {
6923 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006924 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006925 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006926 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006927 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006928 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6929 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006930}
6931
Alexey Bataevbae9a792014-06-27 10:37:06 +00006932template <typename Derived>
6933OMPClause *
6934TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6935 llvm::SmallVector<Expr *, 16> Vars;
6936 Vars.reserve(C->varlist_size());
6937 for (auto *VE : C->varlists()) {
6938 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6939 if (EVar.isInvalid())
6940 return nullptr;
6941 Vars.push_back(EVar.get());
6942 }
6943 return getDerived().RebuildOMPCopyprivateClause(
6944 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6945}
6946
Alexey Bataev6125da92014-07-21 11:26:11 +00006947template <typename Derived>
6948OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6949 llvm::SmallVector<Expr *, 16> Vars;
6950 Vars.reserve(C->varlist_size());
6951 for (auto *VE : C->varlists()) {
6952 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6953 if (EVar.isInvalid())
6954 return nullptr;
6955 Vars.push_back(EVar.get());
6956 }
6957 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6958 C->getLParenLoc(), C->getLocEnd());
6959}
6960
Douglas Gregorebe10102009-08-20 07:17:43 +00006961//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006962// Expression transformation
6963//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006966TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006967 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006968}
Mike Stump11289f42009-09-09 15:08:12 +00006969
6970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006972TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006973 NestedNameSpecifierLoc QualifierLoc;
6974 if (E->getQualifierLoc()) {
6975 QualifierLoc
6976 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6977 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006978 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006979 }
John McCallce546572009-12-08 09:08:17 +00006980
6981 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006982 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6983 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006984 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006986
John McCall815039a2010-08-17 21:27:17 +00006987 DeclarationNameInfo NameInfo = E->getNameInfo();
6988 if (NameInfo.getName()) {
6989 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6990 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006991 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006992 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006993
6994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006995 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006996 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006997 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006998 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006999
7000 // Mark it referenced in the new context regardless.
7001 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007002 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007003
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007004 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007005 }
John McCallce546572009-12-08 09:08:17 +00007006
Craig Topperc3ec1492014-05-26 06:22:03 +00007007 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007008 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007009 TemplateArgs = &TransArgs;
7010 TransArgs.setLAngleLoc(E->getLAngleLoc());
7011 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007012 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7013 E->getNumTemplateArgs(),
7014 TransArgs))
7015 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007016 }
7017
Chad Rosier1dcde962012-08-08 18:46:20 +00007018 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007019 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007020}
Mike Stump11289f42009-09-09 15:08:12 +00007021
Douglas Gregora16548e2009-08-11 05:31:07 +00007022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007024TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007025 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007026}
Mike Stump11289f42009-09-09 15:08:12 +00007027
Douglas Gregora16548e2009-08-11 05:31:07 +00007028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007030TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007031 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007032}
Mike Stump11289f42009-09-09 15:08:12 +00007033
Douglas Gregora16548e2009-08-11 05:31:07 +00007034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007036TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007037 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007038}
Mike Stump11289f42009-09-09 15:08:12 +00007039
Douglas Gregora16548e2009-08-11 05:31:07 +00007040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007042TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007043 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007044}
Mike Stump11289f42009-09-09 15:08:12 +00007045
Douglas Gregora16548e2009-08-11 05:31:07 +00007046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007048TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007049 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007050}
7051
7052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007053ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007054TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007055 if (FunctionDecl *FD = E->getDirectCallee())
7056 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007057 return SemaRef.MaybeBindToTemporary(E);
7058}
7059
7060template<typename Derived>
7061ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007062TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7063 ExprResult ControllingExpr =
7064 getDerived().TransformExpr(E->getControllingExpr());
7065 if (ControllingExpr.isInvalid())
7066 return ExprError();
7067
Chris Lattner01cf8db2011-07-20 06:58:45 +00007068 SmallVector<Expr *, 4> AssocExprs;
7069 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007070 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7071 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7072 if (TS) {
7073 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7074 if (!AssocType)
7075 return ExprError();
7076 AssocTypes.push_back(AssocType);
7077 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007078 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007079 }
7080
7081 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7082 if (AssocExpr.isInvalid())
7083 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007084 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007085 }
7086
7087 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7088 E->getDefaultLoc(),
7089 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007090 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007091 AssocTypes,
7092 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007093}
7094
7095template<typename Derived>
7096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007097TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007098 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007099 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007101
Douglas Gregora16548e2009-08-11 05:31:07 +00007102 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007103 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007104
John McCallb268a282010-08-23 23:25:46 +00007105 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007106 E->getRParen());
7107}
7108
Richard Smithdb2630f2012-10-21 03:28:35 +00007109/// \brief The operand of a unary address-of operator has special rules: it's
7110/// allowed to refer to a non-static member of a class even if there's no 'this'
7111/// object available.
7112template<typename Derived>
7113ExprResult
7114TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7115 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007116 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007117 else
7118 return getDerived().TransformExpr(E);
7119}
7120
Mike Stump11289f42009-09-09 15:08:12 +00007121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007124 ExprResult SubExpr;
7125 if (E->getOpcode() == UO_AddrOf)
7126 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7127 else
7128 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007129 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007133 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007134
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7136 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007137 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007138}
Mike Stump11289f42009-09-09 15:08:12 +00007139
Douglas Gregora16548e2009-08-11 05:31:07 +00007140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007141ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007142TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7143 // Transform the type.
7144 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7145 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007146 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007147
Douglas Gregor882211c2010-04-28 22:16:22 +00007148 // Transform all of the components into components similar to what the
7149 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007150 // FIXME: It would be slightly more efficient in the non-dependent case to
7151 // just map FieldDecls, rather than requiring the rebuilder to look for
7152 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007153 // template code that we don't care.
7154 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007155 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007156 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007157 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007158 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7159 const Node &ON = E->getComponent(I);
7160 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007161 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007162 Comp.LocStart = ON.getSourceRange().getBegin();
7163 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007164 switch (ON.getKind()) {
7165 case Node::Array: {
7166 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007167 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007168 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007169 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007170
Douglas Gregor882211c2010-04-28 22:16:22 +00007171 ExprChanged = ExprChanged || Index.get() != FromIndex;
7172 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007173 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007174 break;
7175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007176
Douglas Gregor882211c2010-04-28 22:16:22 +00007177 case Node::Field:
7178 case Node::Identifier:
7179 Comp.isBrackets = false;
7180 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007181 if (!Comp.U.IdentInfo)
7182 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007183
Douglas Gregor882211c2010-04-28 22:16:22 +00007184 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007185
Douglas Gregord1702062010-04-29 00:18:15 +00007186 case Node::Base:
7187 // Will be recomputed during the rebuild.
7188 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007190
Douglas Gregor882211c2010-04-28 22:16:22 +00007191 Components.push_back(Comp);
7192 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007193
Douglas Gregor882211c2010-04-28 22:16:22 +00007194 // If nothing changed, retain the existing expression.
7195 if (!getDerived().AlwaysRebuild() &&
7196 Type == E->getTypeSourceInfo() &&
7197 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007198 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007199
Douglas Gregor882211c2010-04-28 22:16:22 +00007200 // Build a new offsetof expression.
7201 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7202 Components.data(), Components.size(),
7203 E->getRParenLoc());
7204}
7205
7206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007207ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007208TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7209 assert(getDerived().AlreadyTransformed(E->getType()) &&
7210 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007211 return E;
John McCall8d69a212010-11-15 23:31:06 +00007212}
7213
7214template<typename Derived>
7215ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007216TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007217 // Rebuild the syntactic form. The original syntactic form has
7218 // opaque-value expressions in it, so strip those away and rebuild
7219 // the result. This is a really awful way of doing this, but the
7220 // better solution (rebuilding the semantic expressions and
7221 // rebinding OVEs as necessary) doesn't work; we'd need
7222 // TreeTransform to not strip away implicit conversions.
7223 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7224 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007225 if (result.isInvalid()) return ExprError();
7226
7227 // If that gives us a pseudo-object result back, the pseudo-object
7228 // expression must have been an lvalue-to-rvalue conversion which we
7229 // should reapply.
7230 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007231 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007232
7233 return result;
7234}
7235
7236template<typename Derived>
7237ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007238TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7239 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007241 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007242
John McCallbcd03502009-12-07 02:54:59 +00007243 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007244 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007246
John McCall4c98fd82009-11-04 07:28:41 +00007247 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007248 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007249
Peter Collingbournee190dee2011-03-11 19:24:49 +00007250 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7251 E->getKind(),
7252 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007253 }
Mike Stump11289f42009-09-09 15:08:12 +00007254
Eli Friedmane4f22df2012-02-29 04:03:55 +00007255 // C++0x [expr.sizeof]p1:
7256 // The operand is either an expression, which is an unevaluated operand
7257 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007258 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7259 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007260
Reid Kleckner32506ed2014-06-12 23:03:48 +00007261 // Try to recover if we have something like sizeof(T::X) where X is a type.
7262 // Notably, there must be *exactly* one set of parens if X is a type.
7263 TypeSourceInfo *RecoveryTSI = nullptr;
7264 ExprResult SubExpr;
7265 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7266 if (auto *DRE =
7267 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7268 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7269 PE, DRE, false, &RecoveryTSI);
7270 else
7271 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7272
7273 if (RecoveryTSI) {
7274 return getDerived().RebuildUnaryExprOrTypeTrait(
7275 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7276 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007278
Eli Friedmane4f22df2012-02-29 04:03:55 +00007279 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007280 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007281
Peter Collingbournee190dee2011-03-11 19:24:49 +00007282 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7283 E->getOperatorLoc(),
7284 E->getKind(),
7285 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007286}
Mike Stump11289f42009-09-09 15:08:12 +00007287
Douglas Gregora16548e2009-08-11 05:31:07 +00007288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007290TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007291 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007294
John McCalldadc5752010-08-24 06:29:42 +00007295 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007296 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007298
7299
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 if (!getDerived().AlwaysRebuild() &&
7301 LHS.get() == E->getLHS() &&
7302 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007303 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007304
John McCallb268a282010-08-23 23:25:46 +00007305 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007306 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007307 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007308 E->getRBracketLoc());
7309}
Mike Stump11289f42009-09-09 15:08:12 +00007310
7311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007313TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007315 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007316 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007317 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007318
7319 // Transform arguments.
7320 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007321 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007322 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007323 &ArgChanged))
7324 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007325
Douglas Gregora16548e2009-08-11 05:31:07 +00007326 if (!getDerived().AlwaysRebuild() &&
7327 Callee.get() == E->getCallee() &&
7328 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007329 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007330
Douglas Gregora16548e2009-08-11 05:31:07 +00007331 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007332 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007333 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007334 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007335 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 E->getRParenLoc());
7337}
Mike Stump11289f42009-09-09 15:08:12 +00007338
7339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007341TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007342 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007343 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007345
Douglas Gregorea972d32011-02-28 21:54:11 +00007346 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007347 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007348 QualifierLoc
7349 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007350
Douglas Gregorea972d32011-02-28 21:54:11 +00007351 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007352 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007353 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007354 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007355
Eli Friedman2cfcef62009-12-04 06:40:45 +00007356 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007357 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7358 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007359 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007361
John McCall16df1e52010-03-30 21:47:33 +00007362 NamedDecl *FoundDecl = E->getFoundDecl();
7363 if (FoundDecl == E->getMemberDecl()) {
7364 FoundDecl = Member;
7365 } else {
7366 FoundDecl = cast_or_null<NamedDecl>(
7367 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7368 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007369 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007370 }
7371
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 if (!getDerived().AlwaysRebuild() &&
7373 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007374 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007375 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007376 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007377 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007378
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007379 // Mark it referenced in the new context regardless.
7380 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007381 SemaRef.MarkMemberReferenced(E);
7382
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007383 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007384 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007385
John McCall6b51f282009-11-23 01:53:49 +00007386 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007387 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007388 TransArgs.setLAngleLoc(E->getLAngleLoc());
7389 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007390 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7391 E->getNumTemplateArgs(),
7392 TransArgs))
7393 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007397 SourceLocation FakeOperatorLoc =
7398 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007399
John McCall38836f02010-01-15 08:34:02 +00007400 // FIXME: to do this check properly, we will need to preserve the
7401 // first-qualifier-in-scope here, just in case we had a dependent
7402 // base (and therefore couldn't do the check) and a
7403 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007404 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007405
John McCallb268a282010-08-23 23:25:46 +00007406 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007407 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007408 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007409 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007410 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007411 Member,
John McCall16df1e52010-03-30 21:47:33 +00007412 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007413 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007414 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007415 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007416}
Mike Stump11289f42009-09-09 15:08:12 +00007417
Douglas Gregora16548e2009-08-11 05:31:07 +00007418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007420TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007421 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007424
John McCalldadc5752010-08-24 06:29:42 +00007425 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007426 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 if (!getDerived().AlwaysRebuild() &&
7430 LHS.get() == E->getLHS() &&
7431 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007433
Lang Hames5de91cc2012-10-02 04:45:10 +00007434 Sema::FPContractStateRAII FPContractState(getSema());
7435 getSema().FPFeatures.fp_contract = E->isFPContractable();
7436
Douglas Gregora16548e2009-08-11 05:31:07 +00007437 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007438 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007439}
7440
Mike Stump11289f42009-09-09 15:08:12 +00007441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007442ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007443TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007444 CompoundAssignOperator *E) {
7445 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007446}
Mike Stump11289f42009-09-09 15:08:12 +00007447
Douglas Gregora16548e2009-08-11 05:31:07 +00007448template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007449ExprResult TreeTransform<Derived>::
7450TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7451 // Just rebuild the common and RHS expressions and see whether we
7452 // get any changes.
7453
7454 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7455 if (commonExpr.isInvalid())
7456 return ExprError();
7457
7458 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7459 if (rhs.isInvalid())
7460 return ExprError();
7461
7462 if (!getDerived().AlwaysRebuild() &&
7463 commonExpr.get() == e->getCommon() &&
7464 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007465 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007466
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007467 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007468 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007469 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007470 e->getColonLoc(),
7471 rhs.get());
7472}
7473
7474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007476TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007477 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007478 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007479 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007480
John McCalldadc5752010-08-24 06:29:42 +00007481 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007482 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007484
John McCalldadc5752010-08-24 06:29:42 +00007485 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007486 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007488
Douglas Gregora16548e2009-08-11 05:31:07 +00007489 if (!getDerived().AlwaysRebuild() &&
7490 Cond.get() == E->getCond() &&
7491 LHS.get() == E->getLHS() &&
7492 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007493 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007494
John McCallb268a282010-08-23 23:25:46 +00007495 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007496 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007497 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007498 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007499 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007500}
Mike Stump11289f42009-09-09 15:08:12 +00007501
7502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007504TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007505 // Implicit casts are eliminated during transformation, since they
7506 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007507 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007508}
Mike Stump11289f42009-09-09 15:08:12 +00007509
Douglas Gregora16548e2009-08-11 05:31:07 +00007510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007512TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007513 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7514 if (!Type)
7515 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007516
John McCalldadc5752010-08-24 06:29:42 +00007517 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007518 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007519 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007521
Douglas Gregora16548e2009-08-11 05:31:07 +00007522 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007523 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007524 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007525 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007526
John McCall97513962010-01-15 18:39:57 +00007527 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007528 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007529 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007530 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007531}
Mike Stump11289f42009-09-09 15:08:12 +00007532
Douglas Gregora16548e2009-08-11 05:31:07 +00007533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007534ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007535TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007536 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7537 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7538 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007540
John McCalldadc5752010-08-24 06:29:42 +00007541 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007543 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007544
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007546 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007548 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007549
John McCall5d7aa7f2010-01-19 22:33:45 +00007550 // Note: the expression type doesn't necessarily match the
7551 // type-as-written, but that's okay, because it should always be
7552 // derivable from the initializer.
7553
John McCalle15bbff2010-01-18 19:35:47 +00007554 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007556 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007557}
Mike Stump11289f42009-09-09 15:08:12 +00007558
Douglas Gregora16548e2009-08-11 05:31:07 +00007559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007561TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007562 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 if (!getDerived().AlwaysRebuild() &&
7567 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007568 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007569
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007571 SourceLocation FakeOperatorLoc =
7572 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007573 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007574 E->getAccessorLoc(),
7575 E->getAccessor());
7576}
Mike Stump11289f42009-09-09 15:08:12 +00007577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007579ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007580TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007581 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007582
Benjamin Kramerf0623432012-08-23 22:51:59 +00007583 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007584 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007585 Inits, &InitChanged))
7586 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007587
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007589 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007590
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007591 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007592 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007593}
Mike Stump11289f42009-09-09 15:08:12 +00007594
Douglas Gregora16548e2009-08-11 05:31:07 +00007595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007597TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007598 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregorebe10102009-08-20 07:17:43 +00007600 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007601 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007602 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007604
Douglas Gregorebe10102009-08-20 07:17:43 +00007605 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007606 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 bool ExprChanged = false;
7608 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7609 DEnd = E->designators_end();
7610 D != DEnd; ++D) {
7611 if (D->isFieldDesignator()) {
7612 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7613 D->getDotLoc(),
7614 D->getFieldLoc()));
7615 continue;
7616 }
Mike Stump11289f42009-09-09 15:08:12 +00007617
Douglas Gregora16548e2009-08-11 05:31:07 +00007618 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007619 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007620 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007622
7623 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007624 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007625
Douglas Gregora16548e2009-08-11 05:31:07 +00007626 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007627 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 continue;
7629 }
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007632 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007633 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7634 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007635 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007636
John McCalldadc5752010-08-24 06:29:42 +00007637 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007638 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007639 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007640
7641 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007642 End.get(),
7643 D->getLBracketLoc(),
7644 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007645
Douglas Gregora16548e2009-08-11 05:31:07 +00007646 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7647 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007648
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007649 ArrayExprs.push_back(Start.get());
7650 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007651 }
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 if (!getDerived().AlwaysRebuild() &&
7654 Init.get() == E->getInit() &&
7655 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007656 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007657
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007658 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007660 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007661}
Mike Stump11289f42009-09-09 15:08:12 +00007662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007665TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007666 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007667 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007668
Douglas Gregor3da3c062009-10-28 00:29:27 +00007669 // FIXME: Will we ever have proper type location here? Will we actually
7670 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 QualType T = getDerived().TransformType(E->getType());
7672 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007674
Douglas Gregora16548e2009-08-11 05:31:07 +00007675 if (!getDerived().AlwaysRebuild() &&
7676 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007677 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007678
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 return getDerived().RebuildImplicitValueInitExpr(T);
7680}
Mike Stump11289f42009-09-09 15:08:12 +00007681
Douglas Gregora16548e2009-08-11 05:31:07 +00007682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007684TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007685 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7686 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007687 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007688
John McCalldadc5752010-08-24 06:29:42 +00007689 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007694 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007696 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007697
John McCallb268a282010-08-23 23:25:46 +00007698 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007699 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007700}
7701
7702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007704TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007705 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007706 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007707 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7708 &ArgumentChanged))
7709 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007710
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007712 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007713 E->getRParenLoc());
7714}
Mike Stump11289f42009-09-09 15:08:12 +00007715
Douglas Gregora16548e2009-08-11 05:31:07 +00007716/// \brief Transform an address-of-label expression.
7717///
7718/// By default, the transformation of an address-of-label expression always
7719/// rebuilds the expression, so that the label identifier can be resolved to
7720/// the corresponding label statement by semantic analysis.
7721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007723TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007724 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7725 E->getLabel());
7726 if (!LD)
7727 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007728
Douglas Gregora16548e2009-08-11 05:31:07 +00007729 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007730 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007731}
Mike Stump11289f42009-09-09 15:08:12 +00007732
7733template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007735TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007736 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007737 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007738 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007739 if (SubStmt.isInvalid()) {
7740 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007741 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007742 }
Mike Stump11289f42009-09-09 15:08:12 +00007743
Douglas Gregora16548e2009-08-11 05:31:07 +00007744 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007745 SubStmt.get() == E->getSubStmt()) {
7746 // Calling this an 'error' is unintuitive, but it does the right thing.
7747 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007748 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007749 }
Mike Stump11289f42009-09-09 15:08:12 +00007750
7751 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007752 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007753 E->getRParenLoc());
7754}
Mike Stump11289f42009-09-09 15:08:12 +00007755
Douglas Gregora16548e2009-08-11 05:31:07 +00007756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007758TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007759 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007760 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007762
John McCalldadc5752010-08-24 06:29:42 +00007763 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007764 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007766
John McCalldadc5752010-08-24 06:29:42 +00007767 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007768 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007770
Douglas Gregora16548e2009-08-11 05:31:07 +00007771 if (!getDerived().AlwaysRebuild() &&
7772 Cond.get() == E->getCond() &&
7773 LHS.get() == E->getLHS() &&
7774 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007775 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007776
Douglas Gregora16548e2009-08-11 05:31:07 +00007777 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007778 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007779 E->getRParenLoc());
7780}
Mike Stump11289f42009-09-09 15:08:12 +00007781
Douglas Gregora16548e2009-08-11 05:31:07 +00007782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007784TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007785 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007786}
7787
7788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007790TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007791 switch (E->getOperator()) {
7792 case OO_New:
7793 case OO_Delete:
7794 case OO_Array_New:
7795 case OO_Array_Delete:
7796 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007797
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007798 case OO_Call: {
7799 // This is a call to an object's operator().
7800 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7801
7802 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007803 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007804 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007805 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007806
7807 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007808 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7809 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007810
7811 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007812 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007813 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007814 Args))
7815 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007816
John McCallb268a282010-08-23 23:25:46 +00007817 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007818 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007819 E->getLocEnd());
7820 }
7821
7822#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7823 case OO_##Name:
7824#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7825#include "clang/Basic/OperatorKinds.def"
7826 case OO_Subscript:
7827 // Handled below.
7828 break;
7829
7830 case OO_Conditional:
7831 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007832
7833 case OO_None:
7834 case NUM_OVERLOADED_OPERATORS:
7835 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007836 }
7837
John McCalldadc5752010-08-24 06:29:42 +00007838 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007839 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007841
Richard Smithdb2630f2012-10-21 03:28:35 +00007842 ExprResult First;
7843 if (E->getOperator() == OO_Amp)
7844 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7845 else
7846 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007847 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007848 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007849
John McCalldadc5752010-08-24 06:29:42 +00007850 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007851 if (E->getNumArgs() == 2) {
7852 Second = getDerived().TransformExpr(E->getArg(1));
7853 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007854 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007855 }
Mike Stump11289f42009-09-09 15:08:12 +00007856
Douglas Gregora16548e2009-08-11 05:31:07 +00007857 if (!getDerived().AlwaysRebuild() &&
7858 Callee.get() == E->getCallee() &&
7859 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007860 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007861 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007862
Lang Hames5de91cc2012-10-02 04:45:10 +00007863 Sema::FPContractStateRAII FPContractState(getSema());
7864 getSema().FPFeatures.fp_contract = E->isFPContractable();
7865
Douglas Gregora16548e2009-08-11 05:31:07 +00007866 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7867 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007868 Callee.get(),
7869 First.get(),
7870 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007871}
Mike Stump11289f42009-09-09 15:08:12 +00007872
Douglas Gregora16548e2009-08-11 05:31:07 +00007873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007874ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007875TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7876 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007877}
Mike Stump11289f42009-09-09 15:08:12 +00007878
Douglas Gregora16548e2009-08-11 05:31:07 +00007879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007880ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007881TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7882 // Transform the callee.
7883 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7884 if (Callee.isInvalid())
7885 return ExprError();
7886
7887 // Transform exec config.
7888 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7889 if (EC.isInvalid())
7890 return ExprError();
7891
7892 // Transform arguments.
7893 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007894 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007895 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007896 &ArgChanged))
7897 return ExprError();
7898
7899 if (!getDerived().AlwaysRebuild() &&
7900 Callee.get() == E->getCallee() &&
7901 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007902 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007903
7904 // FIXME: Wrong source location information for the '('.
7905 SourceLocation FakeLParenLoc
7906 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7907 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007908 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007909 E->getRParenLoc(), EC.get());
7910}
7911
7912template<typename Derived>
7913ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007914TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007915 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7916 if (!Type)
7917 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007918
John McCalldadc5752010-08-24 06:29:42 +00007919 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007920 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007923
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007925 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007926 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007927 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007929 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007930 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007931 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007932 E->getAngleBrackets().getEnd(),
7933 // FIXME. this should be '(' location
7934 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007935 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007936 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007937}
Mike Stump11289f42009-09-09 15:08:12 +00007938
Douglas Gregora16548e2009-08-11 05:31:07 +00007939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007941TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7942 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007943}
Mike Stump11289f42009-09-09 15:08:12 +00007944
7945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007947TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7948 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007949}
7950
Douglas Gregora16548e2009-08-11 05:31:07 +00007951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007952ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007953TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007954 CXXReinterpretCastExpr *E) {
7955 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007956}
Mike Stump11289f42009-09-09 15:08:12 +00007957
Douglas Gregora16548e2009-08-11 05:31:07 +00007958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007959ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007960TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7961 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007962}
Mike Stump11289f42009-09-09 15:08:12 +00007963
Douglas Gregora16548e2009-08-11 05:31:07 +00007964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007965ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007966TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007967 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007968 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7969 if (!Type)
7970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007971
John McCalldadc5752010-08-24 06:29:42 +00007972 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007973 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregora16548e2009-08-11 05:31:07 +00007977 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007978 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007979 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007980 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007981
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007982 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007983 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007984 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007985 E->getRParenLoc());
7986}
Mike Stump11289f42009-09-09 15:08:12 +00007987
Douglas Gregora16548e2009-08-11 05:31:07 +00007988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007989ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007990TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007992 TypeSourceInfo *TInfo
7993 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7994 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007996
Douglas Gregora16548e2009-08-11 05:31:07 +00007997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007998 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007999 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008000
Douglas Gregor9da64192010-04-26 22:37:10 +00008001 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8002 E->getLocStart(),
8003 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008004 E->getLocEnd());
8005 }
Mike Stump11289f42009-09-09 15:08:12 +00008006
Eli Friedman456f0182012-01-20 01:26:23 +00008007 // We don't know whether the subexpression is potentially evaluated until
8008 // after we perform semantic analysis. We speculatively assume it is
8009 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008011 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8012 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008013
John McCalldadc5752010-08-24 06:29:42 +00008014 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008015 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008016 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008017
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 if (!getDerived().AlwaysRebuild() &&
8019 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008020 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008021
Douglas Gregor9da64192010-04-26 22:37:10 +00008022 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8023 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008024 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008025 E->getLocEnd());
8026}
8027
8028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008029ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008030TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8031 if (E->isTypeOperand()) {
8032 TypeSourceInfo *TInfo
8033 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8034 if (!TInfo)
8035 return ExprError();
8036
8037 if (!getDerived().AlwaysRebuild() &&
8038 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008039 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008040
Douglas Gregor69735112011-03-06 17:40:41 +00008041 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008042 E->getLocStart(),
8043 TInfo,
8044 E->getLocEnd());
8045 }
8046
Francois Pichet9f4f2072010-09-08 12:20:18 +00008047 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8048
8049 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8050 if (SubExpr.isInvalid())
8051 return ExprError();
8052
8053 if (!getDerived().AlwaysRebuild() &&
8054 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008055 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008056
8057 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8058 E->getLocStart(),
8059 SubExpr.get(),
8060 E->getLocEnd());
8061}
8062
8063template<typename Derived>
8064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008065TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008066 return E;
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
Douglas Gregora16548e2009-08-11 05:31:07 +00008071TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008072 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008073 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008074}
Mike Stump11289f42009-09-09 15:08:12 +00008075
Douglas Gregora16548e2009-08-11 05:31:07 +00008076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008078TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008079 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008080
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008081 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8082 // Make sure that we capture 'this'.
8083 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008084 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008086
Douglas Gregorb15af892010-01-07 23:12:05 +00008087 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008088}
Mike Stump11289f42009-09-09 15:08:12 +00008089
Douglas Gregora16548e2009-08-11 05:31:07 +00008090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008091ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008092TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008093 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008094 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008096
Douglas Gregora16548e2009-08-11 05:31:07 +00008097 if (!getDerived().AlwaysRebuild() &&
8098 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008099 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008100
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008101 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8102 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008103}
Mike Stump11289f42009-09-09 15:08:12 +00008104
Douglas Gregora16548e2009-08-11 05:31:07 +00008105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008107TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008108 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008109 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8110 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008111 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008112 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008113
Chandler Carruth794da4c2010-02-08 06:42:49 +00008114 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008116 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008117
Douglas Gregor033f6752009-12-23 23:03:06 +00008118 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008119}
Mike Stump11289f42009-09-09 15:08:12 +00008120
Douglas Gregora16548e2009-08-11 05:31:07 +00008121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008122ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008123TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8124 FieldDecl *Field
8125 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8126 E->getField()));
8127 if (!Field)
8128 return ExprError();
8129
8130 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008131 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008132
8133 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8134}
8135
8136template<typename Derived>
8137ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008138TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8139 CXXScalarValueInitExpr *E) {
8140 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8141 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008143
Douglas Gregora16548e2009-08-11 05:31:07 +00008144 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008145 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008146 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008147
Chad Rosier1dcde962012-08-08 18:46:20 +00008148 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008149 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008150 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008151}
Mike Stump11289f42009-09-09 15:08:12 +00008152
Douglas Gregora16548e2009-08-11 05:31:07 +00008153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008155TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008156 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008157 TypeSourceInfo *AllocTypeInfo
8158 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8159 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008163 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008164 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008165 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008166
Douglas Gregora16548e2009-08-11 05:31:07 +00008167 // Transform the placement arguments (if any).
8168 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008169 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008170 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008171 E->getNumPlacementArgs(), true,
8172 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008174
Sebastian Redl6047f072012-02-16 12:22:20 +00008175 // Transform the initializer (if any).
8176 Expr *OldInit = E->getInitializer();
8177 ExprResult NewInit;
8178 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008179 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008180 if (NewInit.isInvalid())
8181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008182
Sebastian Redl6047f072012-02-16 12:22:20 +00008183 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008184 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008185 if (E->getOperatorNew()) {
8186 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008187 getDerived().TransformDecl(E->getLocStart(),
8188 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008189 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008190 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008191 }
8192
Craig Topperc3ec1492014-05-26 06:22:03 +00008193 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008194 if (E->getOperatorDelete()) {
8195 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008196 getDerived().TransformDecl(E->getLocStart(),
8197 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008198 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008199 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008200 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008201
Douglas Gregora16548e2009-08-11 05:31:07 +00008202 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008203 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008204 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008205 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008206 OperatorNew == E->getOperatorNew() &&
8207 OperatorDelete == E->getOperatorDelete() &&
8208 !ArgumentChanged) {
8209 // Mark any declarations we need as referenced.
8210 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008211 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008212 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008213 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008214 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008215
Sebastian Redl6047f072012-02-16 12:22:20 +00008216 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008217 QualType ElementType
8218 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8219 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8220 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8221 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008222 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008223 }
8224 }
8225 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008226
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008227 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008228 }
Mike Stump11289f42009-09-09 15:08:12 +00008229
Douglas Gregor0744ef62010-09-07 21:49:58 +00008230 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008231 if (!ArraySize.get()) {
8232 // If no array size was specified, but the new expression was
8233 // instantiated with an array type (e.g., "new T" where T is
8234 // instantiated with "int[4]"), extract the outer bound from the
8235 // array type as our array size. We do this with constant and
8236 // dependently-sized array types.
8237 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8238 if (!ArrayT) {
8239 // Do nothing
8240 } else if (const ConstantArrayType *ConsArrayT
8241 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008242 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8243 SemaRef.Context.getSizeType(),
8244 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008245 AllocType = ConsArrayT->getElementType();
8246 } else if (const DependentSizedArrayType *DepArrayT
8247 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8248 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008249 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008250 AllocType = DepArrayT->getElementType();
8251 }
8252 }
8253 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8256 E->isGlobalNew(),
8257 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008258 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008260 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008261 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008262 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008263 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008264 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008265 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008266}
Mike Stump11289f42009-09-09 15:08:12 +00008267
Douglas Gregora16548e2009-08-11 05:31:07 +00008268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008269ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008270TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008271 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008272 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008273 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008274
Douglas Gregord2d9da02010-02-26 00:38:10 +00008275 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008276 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008277 if (E->getOperatorDelete()) {
8278 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008279 getDerived().TransformDecl(E->getLocStart(),
8280 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008281 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008282 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008284
Douglas Gregora16548e2009-08-11 05:31:07 +00008285 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008286 Operand.get() == E->getArgument() &&
8287 OperatorDelete == E->getOperatorDelete()) {
8288 // Mark any declarations we need as referenced.
8289 // FIXME: instantiation-specific.
8290 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008291 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008292
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008293 if (!E->getArgument()->isTypeDependent()) {
8294 QualType Destroyed = SemaRef.Context.getBaseElementType(
8295 E->getDestroyedType());
8296 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8297 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008298 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008299 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008300 }
8301 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008302
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008303 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008304 }
Mike Stump11289f42009-09-09 15:08:12 +00008305
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8307 E->isGlobalDelete(),
8308 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008309 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008310}
Mike Stump11289f42009-09-09 15:08:12 +00008311
Douglas Gregora16548e2009-08-11 05:31:07 +00008312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008313ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008314TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008315 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008316 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008317 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008318 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008319
John McCallba7bf592010-08-24 05:47:05 +00008320 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008321 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008322 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008323 E->getOperatorLoc(),
8324 E->isArrow()? tok::arrow : tok::period,
8325 ObjectTypePtr,
8326 MayBePseudoDestructor);
8327 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008328 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008329
John McCallba7bf592010-08-24 05:47:05 +00008330 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008331 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8332 if (QualifierLoc) {
8333 QualifierLoc
8334 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8335 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008336 return ExprError();
8337 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008338 CXXScopeSpec SS;
8339 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008340
Douglas Gregor678f90d2010-02-25 01:56:36 +00008341 PseudoDestructorTypeStorage Destroyed;
8342 if (E->getDestroyedTypeInfo()) {
8343 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008344 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008345 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008346 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008347 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008348 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008349 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008350 // We aren't likely to be able to resolve the identifier down to a type
8351 // now anyway, so just retain the identifier.
8352 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8353 E->getDestroyedTypeLoc());
8354 } else {
8355 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008356 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008357 *E->getDestroyedTypeIdentifier(),
8358 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008359 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008360 SS, ObjectTypePtr,
8361 false);
8362 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008363 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008364
Douglas Gregor678f90d2010-02-25 01:56:36 +00008365 Destroyed
8366 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8367 E->getDestroyedTypeLoc());
8368 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008369
Craig Topperc3ec1492014-05-26 06:22:03 +00008370 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008371 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008372 CXXScopeSpec EmptySS;
8373 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008374 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008375 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008376 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008378
John McCallb268a282010-08-23 23:25:46 +00008379 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008380 E->getOperatorLoc(),
8381 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008382 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008383 ScopeTypeInfo,
8384 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008385 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008386 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008387}
Mike Stump11289f42009-09-09 15:08:12 +00008388
Douglas Gregorad8a3362009-09-04 17:36:40 +00008389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008390ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008391TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008392 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008393 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8394 Sema::LookupOrdinaryName);
8395
8396 // Transform all the decls.
8397 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8398 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008399 NamedDecl *InstD = static_cast<NamedDecl*>(
8400 getDerived().TransformDecl(Old->getNameLoc(),
8401 *I));
John McCall84d87672009-12-10 09:41:52 +00008402 if (!InstD) {
8403 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8404 // This can happen because of dependent hiding.
8405 if (isa<UsingShadowDecl>(*I))
8406 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008407 else {
8408 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008409 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008410 }
John McCall84d87672009-12-10 09:41:52 +00008411 }
John McCalle66edc12009-11-24 19:00:30 +00008412
8413 // Expand using declarations.
8414 if (isa<UsingDecl>(InstD)) {
8415 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008416 for (auto *I : UD->shadows())
8417 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008418 continue;
8419 }
8420
8421 R.addDecl(InstD);
8422 }
8423
8424 // Resolve a kind, but don't do any further analysis. If it's
8425 // ambiguous, the callee needs to deal with it.
8426 R.resolveKind();
8427
8428 // Rebuild the nested-name qualifier, if present.
8429 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008430 if (Old->getQualifierLoc()) {
8431 NestedNameSpecifierLoc QualifierLoc
8432 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8433 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008434 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008435
Douglas Gregor0da1d432011-02-28 20:01:57 +00008436 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008437 }
8438
Douglas Gregor9262f472010-04-27 18:19:34 +00008439 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008440 CXXRecordDecl *NamingClass
8441 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8442 Old->getNameLoc(),
8443 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008444 if (!NamingClass) {
8445 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008446 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008447 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008448
Douglas Gregorda7be082010-04-27 16:10:10 +00008449 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008450 }
8451
Abramo Bagnara7945c982012-01-27 09:46:47 +00008452 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8453
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008454 // If we have neither explicit template arguments, nor the template keyword,
8455 // it's a normal declaration name.
8456 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008457 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8458
8459 // If we have template arguments, rebuild them, then rebuild the
8460 // templateid expression.
8461 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008462 if (Old->hasExplicitTemplateArgs() &&
8463 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008464 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008465 TransArgs)) {
8466 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008467 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008468 }
John McCalle66edc12009-11-24 19:00:30 +00008469
Abramo Bagnara7945c982012-01-27 09:46:47 +00008470 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008471 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008472}
Mike Stump11289f42009-09-09 15:08:12 +00008473
Douglas Gregora16548e2009-08-11 05:31:07 +00008474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008475ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008476TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8477 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008478 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008479 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8480 TypeSourceInfo *From = E->getArg(I);
8481 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008482 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008483 TypeLocBuilder TLB;
8484 TLB.reserve(FromTL.getFullDataSize());
8485 QualType To = getDerived().TransformType(TLB, FromTL);
8486 if (To.isNull())
8487 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008488
Douglas Gregor29c42f22012-02-24 07:38:34 +00008489 if (To == From->getType())
8490 Args.push_back(From);
8491 else {
8492 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8493 ArgChanged = true;
8494 }
8495 continue;
8496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008497
Douglas Gregor29c42f22012-02-24 07:38:34 +00008498 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008499
Douglas Gregor29c42f22012-02-24 07:38:34 +00008500 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008501 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008502 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8503 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8504 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008505
Douglas Gregor29c42f22012-02-24 07:38:34 +00008506 // Determine whether the set of unexpanded parameter packs can and should
8507 // be expanded.
8508 bool Expand = true;
8509 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008510 Optional<unsigned> OrigNumExpansions =
8511 ExpansionTL.getTypePtr()->getNumExpansions();
8512 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008513 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8514 PatternTL.getSourceRange(),
8515 Unexpanded,
8516 Expand, RetainExpansion,
8517 NumExpansions))
8518 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008519
Douglas Gregor29c42f22012-02-24 07:38:34 +00008520 if (!Expand) {
8521 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008522 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008523 // expansion.
8524 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008525
Douglas Gregor29c42f22012-02-24 07:38:34 +00008526 TypeLocBuilder TLB;
8527 TLB.reserve(From->getTypeLoc().getFullDataSize());
8528
8529 QualType To = getDerived().TransformType(TLB, PatternTL);
8530 if (To.isNull())
8531 return ExprError();
8532
Chad Rosier1dcde962012-08-08 18:46:20 +00008533 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008534 PatternTL.getSourceRange(),
8535 ExpansionTL.getEllipsisLoc(),
8536 NumExpansions);
8537 if (To.isNull())
8538 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008539
Douglas Gregor29c42f22012-02-24 07:38:34 +00008540 PackExpansionTypeLoc ToExpansionTL
8541 = TLB.push<PackExpansionTypeLoc>(To);
8542 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8543 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8544 continue;
8545 }
8546
8547 // Expand the pack expansion by substituting for each argument in the
8548 // pack(s).
8549 for (unsigned I = 0; I != *NumExpansions; ++I) {
8550 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8551 TypeLocBuilder TLB;
8552 TLB.reserve(PatternTL.getFullDataSize());
8553 QualType To = getDerived().TransformType(TLB, PatternTL);
8554 if (To.isNull())
8555 return ExprError();
8556
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008557 if (To->containsUnexpandedParameterPack()) {
8558 To = getDerived().RebuildPackExpansionType(To,
8559 PatternTL.getSourceRange(),
8560 ExpansionTL.getEllipsisLoc(),
8561 NumExpansions);
8562 if (To.isNull())
8563 return ExprError();
8564
8565 PackExpansionTypeLoc ToExpansionTL
8566 = TLB.push<PackExpansionTypeLoc>(To);
8567 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8568 }
8569
Douglas Gregor29c42f22012-02-24 07:38:34 +00008570 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008572
Douglas Gregor29c42f22012-02-24 07:38:34 +00008573 if (!RetainExpansion)
8574 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregor29c42f22012-02-24 07:38:34 +00008576 // If we're supposed to retain a pack expansion, do so by temporarily
8577 // forgetting the partially-substituted parameter pack.
8578 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8579
8580 TypeLocBuilder TLB;
8581 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008582
Douglas Gregor29c42f22012-02-24 07:38:34 +00008583 QualType To = getDerived().TransformType(TLB, PatternTL);
8584 if (To.isNull())
8585 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008586
8587 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008588 PatternTL.getSourceRange(),
8589 ExpansionTL.getEllipsisLoc(),
8590 NumExpansions);
8591 if (To.isNull())
8592 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008593
Douglas Gregor29c42f22012-02-24 07:38:34 +00008594 PackExpansionTypeLoc ToExpansionTL
8595 = TLB.push<PackExpansionTypeLoc>(To);
8596 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8597 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008599
Douglas Gregor29c42f22012-02-24 07:38:34 +00008600 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008601 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008602
8603 return getDerived().RebuildTypeTrait(E->getTrait(),
8604 E->getLocStart(),
8605 Args,
8606 E->getLocEnd());
8607}
8608
8609template<typename Derived>
8610ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008611TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8612 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8613 if (!T)
8614 return ExprError();
8615
8616 if (!getDerived().AlwaysRebuild() &&
8617 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008618 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008619
8620 ExprResult SubExpr;
8621 {
8622 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8623 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8624 if (SubExpr.isInvalid())
8625 return ExprError();
8626
8627 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008628 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008629 }
8630
8631 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8632 E->getLocStart(),
8633 T,
8634 SubExpr.get(),
8635 E->getLocEnd());
8636}
8637
8638template<typename Derived>
8639ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008640TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8641 ExprResult SubExpr;
8642 {
8643 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8644 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8645 if (SubExpr.isInvalid())
8646 return ExprError();
8647
8648 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008649 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008650 }
8651
8652 return getDerived().RebuildExpressionTrait(
8653 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8654}
8655
Reid Kleckner32506ed2014-06-12 23:03:48 +00008656template <typename Derived>
8657ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8658 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8659 TypeSourceInfo **RecoveryTSI) {
8660 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8661 DRE, AddrTaken, RecoveryTSI);
8662
8663 // Propagate both errors and recovered types, which return ExprEmpty.
8664 if (!NewDRE.isUsable())
8665 return NewDRE;
8666
8667 // We got an expr, wrap it up in parens.
8668 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8669 return PE;
8670 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8671 PE->getRParen());
8672}
8673
8674template <typename Derived>
8675ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8676 DependentScopeDeclRefExpr *E) {
8677 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8678 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008679}
8680
8681template<typename Derived>
8682ExprResult
8683TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8684 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008685 bool IsAddressOfOperand,
8686 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008687 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008688 NestedNameSpecifierLoc QualifierLoc
8689 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8690 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008691 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008692 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008693
John McCall31f82722010-11-12 08:19:04 +00008694 // TODO: If this is a conversion-function-id, verify that the
8695 // destination type name (if present) resolves the same way after
8696 // instantiation as it did in the local scope.
8697
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008698 DeclarationNameInfo NameInfo
8699 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8700 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008702
John McCalle66edc12009-11-24 19:00:30 +00008703 if (!E->hasExplicitTemplateArgs()) {
8704 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008705 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008706 // Note: it is sufficient to compare the Name component of NameInfo:
8707 // if name has not changed, DNLoc has not changed either.
8708 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008709 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008710
Reid Kleckner32506ed2014-06-12 23:03:48 +00008711 return getDerived().RebuildDependentScopeDeclRefExpr(
8712 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8713 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008714 }
John McCall6b51f282009-11-23 01:53:49 +00008715
8716 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008717 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8718 E->getNumTemplateArgs(),
8719 TransArgs))
8720 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008721
Reid Kleckner32506ed2014-06-12 23:03:48 +00008722 return getDerived().RebuildDependentScopeDeclRefExpr(
8723 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8724 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008725}
8726
8727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008729TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008730 // CXXConstructExprs other than for list-initialization and
8731 // CXXTemporaryObjectExpr are always implicit, so when we have
8732 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008733 if ((E->getNumArgs() == 1 ||
8734 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008735 (!getDerived().DropCallArgument(E->getArg(0))) &&
8736 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008737 return getDerived().TransformExpr(E->getArg(0));
8738
Douglas Gregora16548e2009-08-11 05:31:07 +00008739 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8740
8741 QualType T = getDerived().TransformType(E->getType());
8742 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008743 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008744
8745 CXXConstructorDecl *Constructor
8746 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008747 getDerived().TransformDecl(E->getLocStart(),
8748 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008749 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008753 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008754 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008755 &ArgumentChanged))
8756 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008757
Douglas Gregora16548e2009-08-11 05:31:07 +00008758 if (!getDerived().AlwaysRebuild() &&
8759 T == E->getType() &&
8760 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008761 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008762 // Mark the constructor as referenced.
8763 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008764 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008765 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008766 }
Mike Stump11289f42009-09-09 15:08:12 +00008767
Douglas Gregordb121ba2009-12-14 16:27:04 +00008768 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8769 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008770 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008771 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008772 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008773 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008774 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008775 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008776 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008777}
Mike Stump11289f42009-09-09 15:08:12 +00008778
Douglas Gregora16548e2009-08-11 05:31:07 +00008779/// \brief Transform a C++ temporary-binding expression.
8780///
Douglas Gregor363b1512009-12-24 18:51:59 +00008781/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8782/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008785TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008786 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008787}
Mike Stump11289f42009-09-09 15:08:12 +00008788
John McCall5d413782010-12-06 08:20:24 +00008789/// \brief Transform a C++ expression that contains cleanups that should
8790/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008791///
John McCall5d413782010-12-06 08:20:24 +00008792/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008793/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008795ExprResult
John McCall5d413782010-12-06 08:20:24 +00008796TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008797 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008798}
Mike Stump11289f42009-09-09 15:08:12 +00008799
Douglas Gregora16548e2009-08-11 05:31:07 +00008800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008801ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008802TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008803 CXXTemporaryObjectExpr *E) {
8804 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8805 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008807
Douglas Gregora16548e2009-08-11 05:31:07 +00008808 CXXConstructorDecl *Constructor
8809 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008810 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008811 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008812 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008814
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008816 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008818 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008819 &ArgumentChanged))
8820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008821
Douglas Gregora16548e2009-08-11 05:31:07 +00008822 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008823 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008824 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008825 !ArgumentChanged) {
8826 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008827 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008828 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008830
Richard Smithd59b8322012-12-19 01:39:02 +00008831 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008832 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8833 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008834 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008835 E->getLocEnd());
8836}
Mike Stump11289f42009-09-09 15:08:12 +00008837
Douglas Gregora16548e2009-08-11 05:31:07 +00008838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008839ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008840TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008841
8842 // Transform any init-capture expressions before entering the scope of the
8843 // lambda body, because they are not semantically within that scope.
8844 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8845 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8846 E->explicit_capture_begin());
8847
8848 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8849 CEnd = E->capture_end();
8850 C != CEnd; ++C) {
8851 if (!C->isInitCapture())
8852 continue;
8853 EnterExpressionEvaluationContext EEEC(getSema(),
8854 Sema::PotentiallyEvaluated);
8855 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8856 C->getCapturedVar()->getInit(),
8857 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8858
8859 if (NewExprInitResult.isInvalid())
8860 return ExprError();
8861 Expr *NewExprInit = NewExprInitResult.get();
8862
8863 VarDecl *OldVD = C->getCapturedVar();
8864 QualType NewInitCaptureType =
8865 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8866 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8867 NewExprInit);
8868 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008869 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8870 std::make_pair(NewExprInitResult, NewInitCaptureType);
8871
8872 }
8873
Faisal Vali524ca282013-11-12 01:40:44 +00008874 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008875 // Transform the template parameters, and add them to the current
8876 // instantiation scope. The null case is handled correctly.
8877 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8878 E->getTemplateParameterList());
8879
8880 // Check to see if the TypeSourceInfo of the call operator needs to
8881 // be transformed, and if so do the transformation in the
8882 // CurrentInstantiationScope.
8883
8884 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8885 FunctionProtoTypeLoc OldCallOpFPTL =
8886 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008887 TypeSourceInfo *NewCallOpTSI = nullptr;
8888
Faisal Vali2cba1332013-10-23 06:44:28 +00008889 const bool CallOpWasAlreadyTransformed =
8890 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8891
8892 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8893 if (CallOpWasAlreadyTransformed)
8894 NewCallOpTSI = OldCallOpTSI;
8895 else {
8896 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8897 // The transformation MUST be done in the CurrentInstantiationScope since
8898 // it introduces a mapping of the original to the newly created
8899 // transformed parameters.
8900
8901 TypeLocBuilder NewCallOpTLBuilder;
8902 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8903 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008904 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008905 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8906 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008907 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008908 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8909 // the vector below - this will be used to synthesize the
8910 // NewCallOperator. Additionally, add the parameters of the untransformed
8911 // lambda call operator to the CurrentInstantiationScope.
8912 SmallVector<ParmVarDecl *, 4> Params;
8913 {
8914 FunctionProtoTypeLoc NewCallOpFPTL =
8915 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8916 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008917 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008918
8919 for (unsigned I = 0; I < NewNumArgs; ++I) {
8920 // If this call operator's type does not require transformation,
8921 // the parameters do not get added to the current instantiation scope,
8922 // - so ADD them! This allows the following to compile when the enclosing
8923 // template is specialized and the entire lambda expression has to be
8924 // transformed.
8925 // template<class T> void foo(T t) {
8926 // auto L = [](auto a) {
8927 // auto M = [](char b) { <-- note: non-generic lambda
8928 // auto N = [](auto c) {
8929 // int x = sizeof(a);
8930 // x = sizeof(b); <-- specifically this line
8931 // x = sizeof(c);
8932 // };
8933 // };
8934 // };
8935 // }
8936 // foo('a')
8937 if (CallOpWasAlreadyTransformed)
8938 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8939 NewParamDeclArray[I]);
8940 // Add to Params array, so these parameters can be used to create
8941 // the newly transformed call operator.
8942 Params.push_back(NewParamDeclArray[I]);
8943 }
8944 }
8945
8946 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008947 return ExprError();
8948
Eli Friedmand564afb2012-09-19 01:18:11 +00008949 // Create the local class that will describe the lambda.
8950 CXXRecordDecl *Class
8951 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008952 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008953 /*KnownDependent=*/false,
8954 E->getCaptureDefault());
8955
Eli Friedmand564afb2012-09-19 01:18:11 +00008956 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8957
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008958 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008959 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008960 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008961 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008962 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008963 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008964 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008965
Faisal Vali2cba1332013-10-23 06:44:28 +00008966 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8967
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008968 return getDerived().TransformLambdaScope(E, NewCallOperator,
8969 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008970}
8971
8972template<typename Derived>
8973ExprResult
8974TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008975 CXXMethodDecl *CallOperator,
8976 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008977 bool Invalid = false;
8978
Douglas Gregorb4328232012-02-14 00:00:48 +00008979 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008980 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8981 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008982
Faisal Vali2b391ab2013-09-26 19:54:12 +00008983 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008984 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008985 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008986 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008987 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008988 E->hasExplicitParameters(),
8989 E->hasExplicitResultType(),
8990 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008991
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008992 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008993 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008994 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008995 CEnd = E->capture_end();
8996 C != CEnd; ++C) {
8997 // When we hit the first implicit capture, tell Sema that we've finished
8998 // the list of explicit captures.
8999 if (!FinishedExplicitCaptures && C->isImplicit()) {
9000 getSema().finishLambdaExplicitCaptures(LSI);
9001 FinishedExplicitCaptures = true;
9002 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009003
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009004 // Capturing 'this' is trivial.
9005 if (C->capturesThis()) {
9006 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9007 continue;
9008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009009
Richard Smithba71c082013-05-16 06:20:58 +00009010 // Rebuild init-captures, including the implied field declaration.
9011 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009012
9013 InitCaptureInfoTy InitExprTypePair =
9014 InitCaptureExprsAndTypes[C - E->capture_begin()];
9015 ExprResult Init = InitExprTypePair.first;
9016 QualType InitQualType = InitExprTypePair.second;
9017 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009018 Invalid = true;
9019 continue;
9020 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009021 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009022 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9023 OldVD->getLocation(), InitExprTypePair.second,
9024 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009025 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009026 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009027 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009028 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009029 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009030 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009031 continue;
9032 }
9033
9034 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9035
Douglas Gregor3e308b12012-02-14 19:27:52 +00009036 // Determine the capture kind for Sema.
9037 Sema::TryCaptureKind Kind
9038 = C->isImplicit()? Sema::TryCapture_Implicit
9039 : C->getCaptureKind() == LCK_ByCopy
9040 ? Sema::TryCapture_ExplicitByVal
9041 : Sema::TryCapture_ExplicitByRef;
9042 SourceLocation EllipsisLoc;
9043 if (C->isPackExpansion()) {
9044 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9045 bool ShouldExpand = false;
9046 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009047 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009048 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9049 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009050 Unexpanded,
9051 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009052 NumExpansions)) {
9053 Invalid = true;
9054 continue;
9055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009056
Douglas Gregor3e308b12012-02-14 19:27:52 +00009057 if (ShouldExpand) {
9058 // The transform has determined that we should perform an expansion;
9059 // transform and capture each of the arguments.
9060 // expansion of the pattern. Do so.
9061 VarDecl *Pack = C->getCapturedVar();
9062 for (unsigned I = 0; I != *NumExpansions; ++I) {
9063 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9064 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009065 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009066 Pack));
9067 if (!CapturedVar) {
9068 Invalid = true;
9069 continue;
9070 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009071
Douglas Gregor3e308b12012-02-14 19:27:52 +00009072 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009073 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9074 }
Richard Smith9467be42014-06-06 17:33:35 +00009075
9076 // FIXME: Retain a pack expansion if RetainExpansion is true.
9077
Douglas Gregor3e308b12012-02-14 19:27:52 +00009078 continue;
9079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009080
Douglas Gregor3e308b12012-02-14 19:27:52 +00009081 EllipsisLoc = C->getEllipsisLoc();
9082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009083
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009084 // Transform the captured variable.
9085 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009086 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009087 C->getCapturedVar()));
9088 if (!CapturedVar) {
9089 Invalid = true;
9090 continue;
9091 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009092
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009093 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009094 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009095 }
9096 if (!FinishedExplicitCaptures)
9097 getSema().finishLambdaExplicitCaptures(LSI);
9098
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009099
9100 // Enter a new evaluation context to insulate the lambda from any
9101 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009102 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009103
9104 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009105 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009106 /*IsInstantiation=*/true);
9107 return ExprError();
9108 }
9109
9110 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009111 StmtResult Body = getDerived().TransformStmt(E->getBody());
9112 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009113 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009114 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009115 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009116 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009117
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009118 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009119 /*CurScope=*/nullptr,
9120 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009121}
9122
9123template<typename Derived>
9124ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009125TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009126 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009127 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9128 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009130
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009132 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009133 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009134 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009135 &ArgumentChanged))
9136 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009137
Douglas Gregora16548e2009-08-11 05:31:07 +00009138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009139 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009140 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009141 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009142
Douglas Gregora16548e2009-08-11 05:31:07 +00009143 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009144 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009145 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009146 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009147 E->getRParenLoc());
9148}
Mike Stump11289f42009-09-09 15:08:12 +00009149
Douglas Gregora16548e2009-08-11 05:31:07 +00009150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009151ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009152TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009153 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009154 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009155 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009156 Expr *OldBase;
9157 QualType BaseType;
9158 QualType ObjectType;
9159 if (!E->isImplicitAccess()) {
9160 OldBase = E->getBase();
9161 Base = getDerived().TransformExpr(OldBase);
9162 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009164
John McCall2d74de92009-12-01 22:10:20 +00009165 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009166 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009167 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009168 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009169 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009170 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009171 ObjectTy,
9172 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009173 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009174 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009175
John McCallba7bf592010-08-24 05:47:05 +00009176 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009177 BaseType = ((Expr*) Base.get())->getType();
9178 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009179 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009180 BaseType = getDerived().TransformType(E->getBaseType());
9181 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9182 }
Mike Stump11289f42009-09-09 15:08:12 +00009183
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009184 // Transform the first part of the nested-name-specifier that qualifies
9185 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009186 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009187 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009188 E->getFirstQualifierFoundInScope(),
9189 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009190
Douglas Gregore16af532011-02-28 18:50:33 +00009191 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009192 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009193 QualifierLoc
9194 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9195 ObjectType,
9196 FirstQualifierInScope);
9197 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009198 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009199 }
Mike Stump11289f42009-09-09 15:08:12 +00009200
Abramo Bagnara7945c982012-01-27 09:46:47 +00009201 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9202
John McCall31f82722010-11-12 08:19:04 +00009203 // TODO: If this is a conversion-function-id, verify that the
9204 // destination type name (if present) resolves the same way after
9205 // instantiation as it did in the local scope.
9206
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009207 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009208 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009209 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009211
John McCall2d74de92009-12-01 22:10:20 +00009212 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009213 // This is a reference to a member without an explicitly-specified
9214 // template argument list. Optimize for this common case.
9215 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009216 Base.get() == OldBase &&
9217 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009218 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009219 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009220 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009221 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009222
John McCallb268a282010-08-23 23:25:46 +00009223 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009224 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009225 E->isArrow(),
9226 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009227 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009228 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009229 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009230 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009231 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009232 }
9233
John McCall6b51f282009-11-23 01:53:49 +00009234 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009235 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9236 E->getNumTemplateArgs(),
9237 TransArgs))
9238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009239
John McCallb268a282010-08-23 23:25:46 +00009240 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009241 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009242 E->isArrow(),
9243 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009244 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009245 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009246 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009247 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009248 &TransArgs);
9249}
9250
9251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009253TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009254 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009255 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009256 QualType BaseType;
9257 if (!Old->isImplicitAccess()) {
9258 Base = getDerived().TransformExpr(Old->getBase());
9259 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009260 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009261 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009262 Old->isArrow());
9263 if (Base.isInvalid())
9264 return ExprError();
9265 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009266 } else {
9267 BaseType = getDerived().TransformType(Old->getBaseType());
9268 }
John McCall10eae182009-11-30 22:42:35 +00009269
Douglas Gregor0da1d432011-02-28 20:01:57 +00009270 NestedNameSpecifierLoc QualifierLoc;
9271 if (Old->getQualifierLoc()) {
9272 QualifierLoc
9273 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9274 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009275 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009276 }
9277
Abramo Bagnara7945c982012-01-27 09:46:47 +00009278 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9279
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009280 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009281 Sema::LookupOrdinaryName);
9282
9283 // Transform all the decls.
9284 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9285 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009286 NamedDecl *InstD = static_cast<NamedDecl*>(
9287 getDerived().TransformDecl(Old->getMemberLoc(),
9288 *I));
John McCall84d87672009-12-10 09:41:52 +00009289 if (!InstD) {
9290 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9291 // This can happen because of dependent hiding.
9292 if (isa<UsingShadowDecl>(*I))
9293 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009294 else {
9295 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009296 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009297 }
John McCall84d87672009-12-10 09:41:52 +00009298 }
John McCall10eae182009-11-30 22:42:35 +00009299
9300 // Expand using declarations.
9301 if (isa<UsingDecl>(InstD)) {
9302 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009303 for (auto *I : UD->shadows())
9304 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009305 continue;
9306 }
9307
9308 R.addDecl(InstD);
9309 }
9310
9311 R.resolveKind();
9312
Douglas Gregor9262f472010-04-27 18:19:34 +00009313 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009314 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009315 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009316 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009317 Old->getMemberLoc(),
9318 Old->getNamingClass()));
9319 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009320 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009321
Douglas Gregorda7be082010-04-27 16:10:10 +00009322 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009324
John McCall10eae182009-11-30 22:42:35 +00009325 TemplateArgumentListInfo TransArgs;
9326 if (Old->hasExplicitTemplateArgs()) {
9327 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9328 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009329 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9330 Old->getNumTemplateArgs(),
9331 TransArgs))
9332 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009333 }
John McCall38836f02010-01-15 08:34:02 +00009334
9335 // FIXME: to do this check properly, we will need to preserve the
9336 // first-qualifier-in-scope here, just in case we had a dependent
9337 // base (and therefore couldn't do the check) and a
9338 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009339 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009340
John McCallb268a282010-08-23 23:25:46 +00009341 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009342 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009343 Old->getOperatorLoc(),
9344 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009345 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009346 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009347 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009348 R,
9349 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009350 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009351}
9352
9353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009354ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009355TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009356 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009357 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9358 if (SubExpr.isInvalid())
9359 return ExprError();
9360
9361 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009362 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009363
9364 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9365}
9366
9367template<typename Derived>
9368ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009369TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009370 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9371 if (Pattern.isInvalid())
9372 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009373
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009374 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009375 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009376
Douglas Gregorb8840002011-01-14 21:20:45 +00009377 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9378 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009379}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009380
9381template<typename Derived>
9382ExprResult
9383TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9384 // If E is not value-dependent, then nothing will change when we transform it.
9385 // Note: This is an instantiation-centric view.
9386 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009387 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009388
9389 // Note: None of the implementations of TryExpandParameterPacks can ever
9390 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009391 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009392 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9393 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009394 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009395 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009396 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009397 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009398 ShouldExpand, RetainExpansion,
9399 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009400 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009401
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009402 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009403 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009405 NamedDecl *Pack = E->getPack();
9406 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009407 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009408 Pack));
9409 if (!Pack)
9410 return ExprError();
9411 }
9412
Chad Rosier1dcde962012-08-08 18:46:20 +00009413
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009414 // We now know the length of the parameter pack, so build a new expression
9415 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009416 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9417 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009418 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009419}
9420
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009421template<typename Derived>
9422ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009423TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9424 SubstNonTypeTemplateParmPackExpr *E) {
9425 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009426 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009427}
9428
9429template<typename Derived>
9430ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009431TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9432 SubstNonTypeTemplateParmExpr *E) {
9433 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009434 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009435}
9436
9437template<typename Derived>
9438ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009439TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9440 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009441 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009442}
9443
9444template<typename Derived>
9445ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009446TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9447 MaterializeTemporaryExpr *E) {
9448 return getDerived().TransformExpr(E->GetTemporaryExpr());
9449}
Chad Rosier1dcde962012-08-08 18:46:20 +00009450
Douglas Gregorfe314812011-06-21 17:03:29 +00009451template<typename Derived>
9452ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009453TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9454 CXXStdInitializerListExpr *E) {
9455 return getDerived().TransformExpr(E->getSubExpr());
9456}
9457
9458template<typename Derived>
9459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009460TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009461 return SemaRef.MaybeBindToTemporary(E);
9462}
9463
9464template<typename Derived>
9465ExprResult
9466TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009467 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009468}
9469
9470template<typename Derived>
9471ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009472TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9473 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9474 if (SubExpr.isInvalid())
9475 return ExprError();
9476
9477 if (!getDerived().AlwaysRebuild() &&
9478 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009479 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009480
9481 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009482}
9483
9484template<typename Derived>
9485ExprResult
9486TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9487 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009488 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009489 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009490 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009491 /*IsCall=*/false, Elements, &ArgChanged))
9492 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009493
Ted Kremeneke65b0862012-03-06 20:05:56 +00009494 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9495 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009496
Ted Kremeneke65b0862012-03-06 20:05:56 +00009497 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9498 Elements.data(),
9499 Elements.size());
9500}
9501
9502template<typename Derived>
9503ExprResult
9504TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009505 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009506 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009507 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009508 bool ArgChanged = false;
9509 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9510 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009511
Ted Kremeneke65b0862012-03-06 20:05:56 +00009512 if (OrigElement.isPackExpansion()) {
9513 // This key/value element is a pack expansion.
9514 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9515 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9516 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9517 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9518
9519 // Determine whether the set of unexpanded parameter packs can
9520 // and should be expanded.
9521 bool Expand = true;
9522 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009523 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9524 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009525 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9526 OrigElement.Value->getLocEnd());
9527 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9528 PatternRange,
9529 Unexpanded,
9530 Expand, RetainExpansion,
9531 NumExpansions))
9532 return ExprError();
9533
9534 if (!Expand) {
9535 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009536 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009537 // expansion.
9538 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9539 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9540 if (Key.isInvalid())
9541 return ExprError();
9542
9543 if (Key.get() != OrigElement.Key)
9544 ArgChanged = true;
9545
9546 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9547 if (Value.isInvalid())
9548 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009549
Ted Kremeneke65b0862012-03-06 20:05:56 +00009550 if (Value.get() != OrigElement.Value)
9551 ArgChanged = true;
9552
Chad Rosier1dcde962012-08-08 18:46:20 +00009553 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009554 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9555 };
9556 Elements.push_back(Expansion);
9557 continue;
9558 }
9559
9560 // Record right away that the argument was changed. This needs
9561 // to happen even if the array expands to nothing.
9562 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009563
Ted Kremeneke65b0862012-03-06 20:05:56 +00009564 // The transform has determined that we should perform an elementwise
9565 // expansion of the pattern. Do so.
9566 for (unsigned I = 0; I != *NumExpansions; ++I) {
9567 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9568 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9569 if (Key.isInvalid())
9570 return ExprError();
9571
9572 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9573 if (Value.isInvalid())
9574 return ExprError();
9575
Chad Rosier1dcde962012-08-08 18:46:20 +00009576 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009577 Key.get(), Value.get(), SourceLocation(), NumExpansions
9578 };
9579
9580 // If any unexpanded parameter packs remain, we still have a
9581 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009582 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009583 if (Key.get()->containsUnexpandedParameterPack() ||
9584 Value.get()->containsUnexpandedParameterPack())
9585 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009586
Ted Kremeneke65b0862012-03-06 20:05:56 +00009587 Elements.push_back(Element);
9588 }
9589
Richard Smith9467be42014-06-06 17:33:35 +00009590 // FIXME: Retain a pack expansion if RetainExpansion is true.
9591
Ted Kremeneke65b0862012-03-06 20:05:56 +00009592 // We've finished with this pack expansion.
9593 continue;
9594 }
9595
9596 // Transform and check key.
9597 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9598 if (Key.isInvalid())
9599 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009600
Ted Kremeneke65b0862012-03-06 20:05:56 +00009601 if (Key.get() != OrigElement.Key)
9602 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009603
Ted Kremeneke65b0862012-03-06 20:05:56 +00009604 // Transform and check value.
9605 ExprResult Value
9606 = getDerived().TransformExpr(OrigElement.Value);
9607 if (Value.isInvalid())
9608 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009609
Ted Kremeneke65b0862012-03-06 20:05:56 +00009610 if (Value.get() != OrigElement.Value)
9611 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009612
9613 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009614 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009615 };
9616 Elements.push_back(Element);
9617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009618
Ted Kremeneke65b0862012-03-06 20:05:56 +00009619 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9620 return SemaRef.MaybeBindToTemporary(E);
9621
9622 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9623 Elements.data(),
9624 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009625}
9626
Mike Stump11289f42009-09-09 15:08:12 +00009627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009629TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009630 TypeSourceInfo *EncodedTypeInfo
9631 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9632 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009634
Douglas Gregora16548e2009-08-11 05:31:07 +00009635 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009636 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009637 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009638
9639 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009640 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009641 E->getRParenLoc());
9642}
Mike Stump11289f42009-09-09 15:08:12 +00009643
Douglas Gregora16548e2009-08-11 05:31:07 +00009644template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009645ExprResult TreeTransform<Derived>::
9646TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009647 // This is a kind of implicit conversion, and it needs to get dropped
9648 // and recomputed for the same general reasons that ImplicitCastExprs
9649 // do, as well a more specific one: this expression is only valid when
9650 // it appears *immediately* as an argument expression.
9651 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009652}
9653
9654template<typename Derived>
9655ExprResult TreeTransform<Derived>::
9656TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009657 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009658 = getDerived().TransformType(E->getTypeInfoAsWritten());
9659 if (!TSInfo)
9660 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009661
John McCall31168b02011-06-15 23:02:42 +00009662 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009663 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009664 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009665
John McCall31168b02011-06-15 23:02:42 +00009666 if (!getDerived().AlwaysRebuild() &&
9667 TSInfo == E->getTypeInfoAsWritten() &&
9668 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009669 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009670
John McCall31168b02011-06-15 23:02:42 +00009671 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009672 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009673 Result.get());
9674}
9675
9676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009678TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009679 // Transform arguments.
9680 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009681 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009682 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009683 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009684 &ArgChanged))
9685 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009686
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009687 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9688 // Class message: transform the receiver type.
9689 TypeSourceInfo *ReceiverTypeInfo
9690 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9691 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009692 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009693
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009694 // If nothing changed, just retain the existing message send.
9695 if (!getDerived().AlwaysRebuild() &&
9696 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009697 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009698
9699 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009700 SmallVector<SourceLocation, 16> SelLocs;
9701 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009702 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9703 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009704 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009705 E->getMethodDecl(),
9706 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009707 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009708 E->getRightLoc());
9709 }
9710
9711 // Instance message: transform the receiver
9712 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9713 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009714 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009715 = getDerived().TransformExpr(E->getInstanceReceiver());
9716 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009717 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009718
9719 // If nothing changed, just retain the existing message send.
9720 if (!getDerived().AlwaysRebuild() &&
9721 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009722 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009723
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009724 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009725 SmallVector<SourceLocation, 16> SelLocs;
9726 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009727 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009728 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009729 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009730 E->getMethodDecl(),
9731 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009732 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009733 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009734}
9735
Mike Stump11289f42009-09-09 15:08:12 +00009736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009738TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009739 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009740}
9741
Mike Stump11289f42009-09-09 15:08:12 +00009742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009744TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009745 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009746}
9747
Mike Stump11289f42009-09-09 15:08:12 +00009748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009750TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009751 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009752 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009753 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009754 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009755
9756 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009757
Douglas Gregord51d90d2010-04-26 20:11:03 +00009758 // If nothing changed, just retain the existing expression.
9759 if (!getDerived().AlwaysRebuild() &&
9760 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009761 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009762
John McCallb268a282010-08-23 23:25:46 +00009763 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009764 E->getLocation(),
9765 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009766}
9767
Mike Stump11289f42009-09-09 15:08:12 +00009768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009769ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009770TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009771 // 'super' and types never change. Property never changes. Just
9772 // retain the existing expression.
9773 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009774 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009775
Douglas Gregor9faee212010-04-26 20:47:02 +00009776 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009777 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009778 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009779 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009780
Douglas Gregor9faee212010-04-26 20:47:02 +00009781 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009782
Douglas Gregor9faee212010-04-26 20:47:02 +00009783 // If nothing changed, just retain the existing expression.
9784 if (!getDerived().AlwaysRebuild() &&
9785 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009786 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009787
John McCallb7bd14f2010-12-02 01:19:52 +00009788 if (E->isExplicitProperty())
9789 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9790 E->getExplicitProperty(),
9791 E->getLocation());
9792
9793 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009794 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009795 E->getImplicitPropertyGetter(),
9796 E->getImplicitPropertySetter(),
9797 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009798}
9799
Mike Stump11289f42009-09-09 15:08:12 +00009800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009801ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009802TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9803 // Transform the base expression.
9804 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9805 if (Base.isInvalid())
9806 return ExprError();
9807
9808 // Transform the key expression.
9809 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9810 if (Key.isInvalid())
9811 return ExprError();
9812
9813 // If nothing changed, just retain the existing expression.
9814 if (!getDerived().AlwaysRebuild() &&
9815 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009816 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009817
Chad Rosier1dcde962012-08-08 18:46:20 +00009818 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009819 Base.get(), Key.get(),
9820 E->getAtIndexMethodDecl(),
9821 E->setAtIndexMethodDecl());
9822}
9823
9824template<typename Derived>
9825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009826TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009827 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009828 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009829 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009830 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009831
Douglas Gregord51d90d2010-04-26 20:11:03 +00009832 // If nothing changed, just retain the existing expression.
9833 if (!getDerived().AlwaysRebuild() &&
9834 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009835 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009836
John McCallb268a282010-08-23 23:25:46 +00009837 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009838 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009839 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009840}
9841
Mike Stump11289f42009-09-09 15:08:12 +00009842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009844TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009845 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009846 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009847 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009848 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009849 SubExprs, &ArgumentChanged))
9850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009851
Douglas Gregora16548e2009-08-11 05:31:07 +00009852 if (!getDerived().AlwaysRebuild() &&
9853 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009854 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009855
Douglas Gregora16548e2009-08-11 05:31:07 +00009856 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009857 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009858 E->getRParenLoc());
9859}
9860
Mike Stump11289f42009-09-09 15:08:12 +00009861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009862ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009863TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9864 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9865 if (SrcExpr.isInvalid())
9866 return ExprError();
9867
9868 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9869 if (!Type)
9870 return ExprError();
9871
9872 if (!getDerived().AlwaysRebuild() &&
9873 Type == E->getTypeSourceInfo() &&
9874 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009875 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009876
9877 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9878 SrcExpr.get(), Type,
9879 E->getRParenLoc());
9880}
9881
9882template<typename Derived>
9883ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009884TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009885 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009886
Craig Topperc3ec1492014-05-26 06:22:03 +00009887 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009888 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9889
9890 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009891 blockScope->TheDecl->setBlockMissingReturnType(
9892 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009893
Chris Lattner01cf8db2011-07-20 06:58:45 +00009894 SmallVector<ParmVarDecl*, 4> params;
9895 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009896
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009897 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009898 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9899 oldBlock->param_begin(),
9900 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009901 nullptr, paramTypes, &params)) {
9902 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009903 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009904 }
John McCall490112f2011-02-04 18:33:18 +00009905
Jordan Rosea0a86be2013-03-08 22:25:36 +00009906 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009907 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009908 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009909
Jordan Rose5c382722013-03-08 21:51:21 +00009910 QualType functionType =
9911 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009912 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009913 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009914
9915 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009916 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009917 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009918
9919 if (!oldBlock->blockMissingReturnType()) {
9920 blockScope->HasImplicitReturnType = false;
9921 blockScope->ReturnType = exprResultType;
9922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009923
John McCall3882ace2011-01-05 12:14:39 +00009924 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009925 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009926 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009927 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009928 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009929 }
John McCall3882ace2011-01-05 12:14:39 +00009930
John McCall490112f2011-02-04 18:33:18 +00009931#ifndef NDEBUG
9932 // In builds with assertions, make sure that we captured everything we
9933 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009934 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009935 for (const auto &I : oldBlock->captures()) {
9936 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009937
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009938 // Ignore parameter packs.
9939 if (isa<ParmVarDecl>(oldCapture) &&
9940 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9941 continue;
John McCall490112f2011-02-04 18:33:18 +00009942
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009943 VarDecl *newCapture =
9944 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9945 oldCapture));
9946 assert(blockScope->CaptureMap.count(newCapture));
9947 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009948 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009949 }
9950#endif
9951
9952 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009953 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009954}
9955
Mike Stump11289f42009-09-09 15:08:12 +00009956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009957ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009958TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009959 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009960}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009961
9962template<typename Derived>
9963ExprResult
9964TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009965 QualType RetTy = getDerived().TransformType(E->getType());
9966 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009967 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009968 SubExprs.reserve(E->getNumSubExprs());
9969 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9970 SubExprs, &ArgumentChanged))
9971 return ExprError();
9972
9973 if (!getDerived().AlwaysRebuild() &&
9974 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009975 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009976
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009977 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009978 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009979}
Chad Rosier1dcde962012-08-08 18:46:20 +00009980
Douglas Gregora16548e2009-08-11 05:31:07 +00009981//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009982// Type reconstruction
9983//===----------------------------------------------------------------------===//
9984
Mike Stump11289f42009-09-09 15:08:12 +00009985template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009986QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9987 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009988 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009989 getDerived().getBaseEntity());
9990}
9991
Mike Stump11289f42009-09-09 15:08:12 +00009992template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009993QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9994 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009995 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009996 getDerived().getBaseEntity());
9997}
9998
Mike Stump11289f42009-09-09 15:08:12 +00009999template<typename Derived>
10000QualType
John McCall70dd5f62009-10-30 00:06:24 +000010001TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10002 bool WrittenAsLValue,
10003 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010004 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010005 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010006}
10007
10008template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010009QualType
John McCall70dd5f62009-10-30 00:06:24 +000010010TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10011 QualType ClassType,
10012 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010013 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10014 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010015}
10016
10017template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010018QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010019TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10020 ArrayType::ArraySizeModifier SizeMod,
10021 const llvm::APInt *Size,
10022 Expr *SizeExpr,
10023 unsigned IndexTypeQuals,
10024 SourceRange BracketsRange) {
10025 if (SizeExpr || !Size)
10026 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10027 IndexTypeQuals, BracketsRange,
10028 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010029
10030 QualType Types[] = {
10031 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10032 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10033 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010034 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010035 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010036 QualType SizeType;
10037 for (unsigned I = 0; I != NumTypes; ++I)
10038 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10039 SizeType = Types[I];
10040 break;
10041 }
Mike Stump11289f42009-09-09 15:08:12 +000010042
Eli Friedman9562f392012-01-25 23:20:27 +000010043 // Note that we can return a VariableArrayType here in the case where
10044 // the element type was a dependent VariableArrayType.
10045 IntegerLiteral *ArraySize
10046 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10047 /*FIXME*/BracketsRange.getBegin());
10048 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010049 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010050 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010051}
Mike Stump11289f42009-09-09 15:08:12 +000010052
Douglas Gregord6ff3322009-08-04 16:50:30 +000010053template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010054QualType
10055TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010056 ArrayType::ArraySizeModifier SizeMod,
10057 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010058 unsigned IndexTypeQuals,
10059 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010060 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010061 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010062}
10063
10064template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010065QualType
Mike Stump11289f42009-09-09 15:08:12 +000010066TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010067 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010068 unsigned IndexTypeQuals,
10069 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010070 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010071 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010072}
Mike Stump11289f42009-09-09 15:08:12 +000010073
Douglas Gregord6ff3322009-08-04 16:50:30 +000010074template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010075QualType
10076TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010077 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010078 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010079 unsigned IndexTypeQuals,
10080 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010081 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010082 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010083 IndexTypeQuals, BracketsRange);
10084}
10085
10086template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010087QualType
10088TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010089 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010090 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010091 unsigned IndexTypeQuals,
10092 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010093 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010094 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010095 IndexTypeQuals, BracketsRange);
10096}
10097
10098template<typename Derived>
10099QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010100 unsigned NumElements,
10101 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010102 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010103 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010104}
Mike Stump11289f42009-09-09 15:08:12 +000010105
Douglas Gregord6ff3322009-08-04 16:50:30 +000010106template<typename Derived>
10107QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10108 unsigned NumElements,
10109 SourceLocation AttributeLoc) {
10110 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10111 NumElements, true);
10112 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010113 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10114 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010115 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010116}
Mike Stump11289f42009-09-09 15:08:12 +000010117
Douglas Gregord6ff3322009-08-04 16:50:30 +000010118template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010119QualType
10120TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010121 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010122 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010123 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010124}
Mike Stump11289f42009-09-09 15:08:12 +000010125
Douglas Gregord6ff3322009-08-04 16:50:30 +000010126template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010127QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10128 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010129 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010130 const FunctionProtoType::ExtProtoInfo &EPI) {
10131 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010132 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010133 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010134 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010135}
Mike Stump11289f42009-09-09 15:08:12 +000010136
Douglas Gregord6ff3322009-08-04 16:50:30 +000010137template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010138QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10139 return SemaRef.Context.getFunctionNoProtoType(T);
10140}
10141
10142template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010143QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10144 assert(D && "no decl found");
10145 if (D->isInvalidDecl()) return QualType();
10146
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010147 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010148 TypeDecl *Ty;
10149 if (isa<UsingDecl>(D)) {
10150 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010151 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010152 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10153
10154 // A valid resolved using typename decl points to exactly one type decl.
10155 assert(++Using->shadow_begin() == Using->shadow_end());
10156 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010157
John McCallb96ec562009-12-04 22:46:56 +000010158 } else {
10159 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10160 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10161 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10162 }
10163
10164 return SemaRef.Context.getTypeDeclType(Ty);
10165}
10166
10167template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010168QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10169 SourceLocation Loc) {
10170 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010171}
10172
10173template<typename Derived>
10174QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10175 return SemaRef.Context.getTypeOfType(Underlying);
10176}
10177
10178template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010179QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10180 SourceLocation Loc) {
10181 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010182}
10183
10184template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010185QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10186 UnaryTransformType::UTTKind UKind,
10187 SourceLocation Loc) {
10188 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10189}
10190
10191template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010192QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010193 TemplateName Template,
10194 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010195 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010196 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010197}
Mike Stump11289f42009-09-09 15:08:12 +000010198
Douglas Gregor1135c352009-08-06 05:28:30 +000010199template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010200QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10201 SourceLocation KWLoc) {
10202 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10203}
10204
10205template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010206TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010207TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010208 bool TemplateKW,
10209 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010210 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010211 Template);
10212}
10213
10214template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010215TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010216TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10217 const IdentifierInfo &Name,
10218 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010219 QualType ObjectType,
10220 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010221 UnqualifiedId TemplateName;
10222 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010223 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010224 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010225 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010226 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010227 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010228 /*EnteringContext=*/false,
10229 Template);
John McCall31f82722010-11-12 08:19:04 +000010230 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010231}
Mike Stump11289f42009-09-09 15:08:12 +000010232
Douglas Gregora16548e2009-08-11 05:31:07 +000010233template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010234TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010235TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010236 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010237 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010238 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010239 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010240 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010241 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010242 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010243 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010244 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010245 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010246 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010247 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010248 /*EnteringContext=*/false,
10249 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010250 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010251}
Chad Rosier1dcde962012-08-08 18:46:20 +000010252
Douglas Gregor71395fa2009-11-04 00:56:37 +000010253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010254ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010255TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10256 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010257 Expr *OrigCallee,
10258 Expr *First,
10259 Expr *Second) {
10260 Expr *Callee = OrigCallee->IgnoreParenCasts();
10261 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010262
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010263 if (First->getObjectKind() == OK_ObjCProperty) {
10264 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10265 if (BinaryOperator::isAssignmentOp(Opc))
10266 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10267 First, Second);
10268 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10269 if (Result.isInvalid())
10270 return ExprError();
10271 First = Result.get();
10272 }
10273
10274 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10275 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10276 if (Result.isInvalid())
10277 return ExprError();
10278 Second = Result.get();
10279 }
10280
Douglas Gregora16548e2009-08-11 05:31:07 +000010281 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010282 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010283 if (!First->getType()->isOverloadableType() &&
10284 !Second->getType()->isOverloadableType())
10285 return getSema().CreateBuiltinArraySubscriptExpr(First,
10286 Callee->getLocStart(),
10287 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010288 } else if (Op == OO_Arrow) {
10289 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010290 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10291 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010292 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010293 // The argument is not of overloadable type, so try to create a
10294 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010295 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010296 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010297
John McCallb268a282010-08-23 23:25:46 +000010298 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010299 }
10300 } else {
John McCallb268a282010-08-23 23:25:46 +000010301 if (!First->getType()->isOverloadableType() &&
10302 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010303 // Neither of the arguments is an overloadable type, so try to
10304 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010305 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010306 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010307 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010308 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010310
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010311 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010312 }
10313 }
Mike Stump11289f42009-09-09 15:08:12 +000010314
10315 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010316 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010317 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010318
John McCallb268a282010-08-23 23:25:46 +000010319 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010320 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010321 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010322 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010323 // If we've resolved this to a particular non-member function, just call
10324 // that function. If we resolved it to a member function,
10325 // CreateOverloaded* will find that function for us.
10326 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10327 if (!isa<CXXMethodDecl>(ND))
10328 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010329 }
Mike Stump11289f42009-09-09 15:08:12 +000010330
Douglas Gregora16548e2009-08-11 05:31:07 +000010331 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010332 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010333 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010334
Douglas Gregora16548e2009-08-11 05:31:07 +000010335 // Create the overloaded operator invocation for unary operators.
10336 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010337 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010338 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010339 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010340 }
Mike Stump11289f42009-09-09 15:08:12 +000010341
Douglas Gregore9d62932011-07-15 16:25:15 +000010342 if (Op == OO_Subscript) {
10343 SourceLocation LBrace;
10344 SourceLocation RBrace;
10345
10346 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10347 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10348 LBrace = SourceLocation::getFromRawEncoding(
10349 NameLoc.CXXOperatorName.BeginOpNameLoc);
10350 RBrace = SourceLocation::getFromRawEncoding(
10351 NameLoc.CXXOperatorName.EndOpNameLoc);
10352 } else {
10353 LBrace = Callee->getLocStart();
10354 RBrace = OpLoc;
10355 }
10356
10357 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10358 First, Second);
10359 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010360
Douglas Gregora16548e2009-08-11 05:31:07 +000010361 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010362 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010363 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010364 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10365 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010367
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010368 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010369}
Mike Stump11289f42009-09-09 15:08:12 +000010370
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010371template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010372ExprResult
John McCallb268a282010-08-23 23:25:46 +000010373TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010374 SourceLocation OperatorLoc,
10375 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010376 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010377 TypeSourceInfo *ScopeType,
10378 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010379 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010380 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010381 QualType BaseType = Base->getType();
10382 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010383 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010384 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010385 !BaseType->getAs<PointerType>()->getPointeeType()
10386 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010387 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010388 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010389 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010390 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010391 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010392 /*FIXME?*/true);
10393 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010394
Douglas Gregor678f90d2010-02-25 01:56:36 +000010395 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010396 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10397 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10398 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10399 NameInfo.setNamedTypeInfo(DestroyedType);
10400
Richard Smith8e4a3862012-05-15 06:15:11 +000010401 // The scope type is now known to be a valid nested name specifier
10402 // component. Tack it on to the end of the nested name specifier.
10403 if (ScopeType)
10404 SS.Extend(SemaRef.Context, SourceLocation(),
10405 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010406
Abramo Bagnara7945c982012-01-27 09:46:47 +000010407 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010408 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010409 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010410 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010411 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010412 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010413 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010414}
10415
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010416template<typename Derived>
10417StmtResult
10418TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010419 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010420 CapturedDecl *CD = S->getCapturedDecl();
10421 unsigned NumParams = CD->getNumParams();
10422 unsigned ContextParamPos = CD->getContextParamPosition();
10423 SmallVector<Sema::CapturedParamNameType, 4> Params;
10424 for (unsigned I = 0; I < NumParams; ++I) {
10425 if (I != ContextParamPos) {
10426 Params.push_back(
10427 std::make_pair(
10428 CD->getParam(I)->getName(),
10429 getDerived().TransformType(CD->getParam(I)->getType())));
10430 } else {
10431 Params.push_back(std::make_pair(StringRef(), QualType()));
10432 }
10433 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010434 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010435 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010436 StmtResult Body;
10437 {
10438 Sema::CompoundScopeRAII CompoundScope(getSema());
10439 Body = getDerived().TransformStmt(S->getCapturedStmt());
10440 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010441
10442 if (Body.isInvalid()) {
10443 getSema().ActOnCapturedRegionError();
10444 return StmtError();
10445 }
10446
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010447 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010448}
10449
Douglas Gregord6ff3322009-08-04 16:50:30 +000010450} // end namespace clang
10451
10452#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H