blob: 83068858548393a977ac88c270d078ddaf25a921 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000607
Richard Smithdb2630f2012-10-21 03:28:35 +0000608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000609 bool IsAddressOfOperand,
610 TypeSourceInfo **RecoveryTSI);
611
612 ExprResult TransformParenDependentScopeDeclRefExpr(
613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
614 TypeSourceInfo **RecoveryTSI);
615
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000616 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000617
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
619// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000620#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000622 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000623#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000625 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000626#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000627#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000628
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000629#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000630 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000631 OMPClause *Transform ## Class(Class *S);
632#include "clang/Basic/OpenMPKinds.def"
633
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 /// \brief Build a new pointer type given its pointee type.
635 ///
636 /// By default, performs semantic analysis when building the pointer type.
637 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
640 /// \brief Build a new block pointer type given its pointee type.
641 ///
Mike Stump11289f42009-09-09 15:08:12 +0000642 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000644 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000647 ///
John McCall70dd5f62009-10-30 00:06:24 +0000648 /// By default, performs semantic analysis when building the
649 /// reference type. Subclasses may override this routine to provide
650 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 ///
John McCall70dd5f62009-10-30 00:06:24 +0000652 /// \param LValue whether the type was written with an lvalue sigil
653 /// or an rvalue sigil.
654 QualType RebuildReferenceType(QualType ReferentType,
655 bool LValue,
656 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new member pointer type given the pointee type and the
659 /// class type it refers into.
660 ///
661 /// By default, performs semantic analysis when building the member pointer
662 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000663 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
664 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 /// \brief Build a new array type given the element type, size
667 /// modifier, size of the array (if known), size expression, and index type
668 /// qualifiers.
669 ///
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 QualType RebuildArrayType(QualType ElementType,
674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt *Size,
676 Expr *SizeExpr,
677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new constant array type given the element type, size
681 /// modifier, (known) size of the array, and index type qualifiers.
682 ///
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 ArrayType::ArraySizeModifier SizeMod,
687 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000688 unsigned IndexTypeQuals,
689 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 /// \brief Build a new incomplete array type given the element type, size
692 /// modifier, and index type qualifiers.
693 ///
694 /// By default, performs semantic analysis when building the array type.
695 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000696 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700
Mike Stump11289f42009-09-09 15:08:12 +0000701 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// size modifier, size expression, and index type qualifiers.
703 ///
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000706 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
711
Mike Stump11289f42009-09-09 15:08:12 +0000712 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// size modifier, size expression, and index type qualifiers.
714 ///
715 /// By default, performs semantic analysis when building the array type.
716 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000717 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000719 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
722
723 /// \brief Build a new vector type given the element type and
724 /// number of elements.
725 ///
726 /// By default, performs semantic analysis when building the vector type.
727 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000728 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000729 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// \brief Build a new extended vector type given the element type and
732 /// number of elements.
733 ///
734 /// By default, performs semantic analysis when building the vector type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
737 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000738
739 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// given the element type and number of elements.
741 ///
742 /// By default, performs semantic analysis when building the vector type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000745 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new function type.
749 ///
750 /// By default, performs semantic analysis when building the function type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000753 llvm::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.
Rafael Espindolaab417692013-07-09 12:05:01 +00001204 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1205 SourceLocation StartLoc, SourceLocation EndLoc) {
1206 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001207 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Anders Carlssonaaeef072010-01-24 05:50:09 +00001210 /// \brief Build a new inline asm statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001214 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1215 bool IsVolatile, unsigned NumOutputs,
1216 unsigned NumInputs, IdentifierInfo **Names,
1217 MultiExprArg Constraints, MultiExprArg Exprs,
1218 Expr *AsmString, MultiExprArg Clobbers,
1219 SourceLocation RParenLoc) {
1220 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1221 NumInputs, Names, Constraints, Exprs,
1222 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001223 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001224
Chad Rosier32503022012-06-11 20:47:18 +00001225 /// \brief Build a new MS style inline asm statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001229 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001230 ArrayRef<Token> AsmToks,
1231 StringRef AsmString,
1232 unsigned NumOutputs, unsigned NumInputs,
1233 ArrayRef<StringRef> Constraints,
1234 ArrayRef<StringRef> Clobbers,
1235 ArrayRef<Expr*> Exprs,
1236 SourceLocation EndLoc) {
1237 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1238 NumOutputs, NumInputs,
1239 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001240 }
1241
James Dennett2a4d13c2012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001247 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001248 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001249 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001250 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001251 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001252 }
1253
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001254 /// \brief Rebuild an Objective-C exception declaration.
1255 ///
1256 /// By default, performs semantic analysis to build the new declaration.
1257 /// Subclasses may override this routine to provide different behavior.
1258 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1259 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001260 return getSema().BuildObjCExceptionDecl(TInfo, T,
1261 ExceptionDecl->getInnerLocStart(),
1262 ExceptionDecl->getLocation(),
1263 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001265
James Dennett2a4d13c2012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001271 SourceLocation RParenLoc,
1272 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001273 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001274 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001275 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001277
James Dennett2a4d13c2012-06-15 07:13:21 +00001278 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001282 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001283 Stmt *Body) {
1284 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001286
James Dennett2a4d13c2012-06-15 07:13:21 +00001287 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 ///
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001292 Expr *Operand) {
1293 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001295
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001296 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001300 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1301 ArrayRef<OMPClause *> Clauses,
1302 Stmt *AStmt,
1303 SourceLocation StartLoc,
1304 SourceLocation EndLoc) {
1305 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1306 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001307 }
1308
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309 /// \brief Build a new OpenMP 'if' clause.
1310 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001311 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1318 LParenLoc, EndLoc);
1319 }
1320
Alexey Bataev568a8332014-03-06 06:15:19 +00001321 /// \brief Build a new OpenMP 'num_threads' clause.
1322 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001323 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1326 SourceLocation StartLoc,
1327 SourceLocation LParenLoc,
1328 SourceLocation EndLoc) {
1329 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1330 LParenLoc, EndLoc);
1331 }
1332
Alexey Bataev62c87d22014-03-21 04:51:18 +00001333 /// \brief Build a new OpenMP 'safelen' clause.
1334 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001335 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001336 /// Subclasses may override this routine to provide different behavior.
1337 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1341 }
1342
Alexander Musman8bd31e62014-05-27 15:12:19 +00001343 /// \brief Build a new OpenMP 'collapse' clause.
1344 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001345 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1351 EndLoc);
1352 }
1353
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001354 /// \brief Build a new OpenMP 'default' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1359 SourceLocation KindKwLoc,
1360 SourceLocation StartLoc,
1361 SourceLocation LParenLoc,
1362 SourceLocation EndLoc) {
1363 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1364 StartLoc, LParenLoc, EndLoc);
1365 }
1366
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001367 /// \brief Build a new OpenMP 'proc_bind' clause.
1368 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001369 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001370 /// Subclasses may override this routine to provide different behavior.
1371 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1372 SourceLocation KindKwLoc,
1373 SourceLocation StartLoc,
1374 SourceLocation LParenLoc,
1375 SourceLocation EndLoc) {
1376 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1377 StartLoc, LParenLoc, EndLoc);
1378 }
1379
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001380 /// \brief Build a new OpenMP 'private' clause.
1381 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001382 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001383 /// Subclasses may override this routine to provide different behavior.
1384 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1385 SourceLocation StartLoc,
1386 SourceLocation LParenLoc,
1387 SourceLocation EndLoc) {
1388 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1389 EndLoc);
1390 }
1391
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001392 /// \brief Build a new OpenMP 'firstprivate' clause.
1393 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001394 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001395 /// Subclasses may override this routine to provide different behavior.
1396 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1397 SourceLocation StartLoc,
1398 SourceLocation LParenLoc,
1399 SourceLocation EndLoc) {
1400 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1401 EndLoc);
1402 }
1403
Alexander Musman1bb328c2014-06-04 13:06:39 +00001404 /// \brief Build a new OpenMP 'lastprivate' clause.
1405 ///
1406 /// By default, performs semantic analysis to build the new OpenMP clause.
1407 /// Subclasses may override this routine to provide different behavior.
1408 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1409 SourceLocation StartLoc,
1410 SourceLocation LParenLoc,
1411 SourceLocation EndLoc) {
1412 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1413 EndLoc);
1414 }
1415
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001416 /// \brief Build a new OpenMP 'shared' clause.
1417 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001418 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001419 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001420 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1421 SourceLocation StartLoc,
1422 SourceLocation LParenLoc,
1423 SourceLocation EndLoc) {
1424 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1425 EndLoc);
1426 }
1427
Alexander Musman8dba6642014-04-22 13:09:42 +00001428 /// \brief Build a new OpenMP 'linear' clause.
1429 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001430 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001431 /// Subclasses may override this routine to provide different behavior.
1432 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation ColonLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1438 ColonLoc, EndLoc);
1439 }
1440
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001441 /// \brief Build a new OpenMP 'aligned' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation ColonLoc,
1449 SourceLocation EndLoc) {
1450 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1451 LParenLoc, ColonLoc, EndLoc);
1452 }
1453
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001454 /// \brief Build a new OpenMP 'copyin' clause.
1455 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001456 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001457 /// Subclasses may override this routine to provide different behavior.
1458 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation EndLoc) {
1462 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1463 EndLoc);
1464 }
1465
James Dennett2a4d13c2012-06-15 07:13:21 +00001466 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001467 ///
1468 /// By default, performs semantic analysis to build the new statement.
1469 /// Subclasses may override this routine to provide different behavior.
1470 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1471 Expr *object) {
1472 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1473 }
1474
James Dennett2a4d13c2012-06-15 07:13:21 +00001475 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001476 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001477 /// By default, performs semantic analysis to build the new statement.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001480 Expr *Object, Stmt *Body) {
1481 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001482 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001483
James Dennett2a4d13c2012-06-15 07:13:21 +00001484 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001485 ///
1486 /// By default, performs semantic analysis to build the new statement.
1487 /// Subclasses may override this routine to provide different behavior.
1488 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1489 Stmt *Body) {
1490 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1491 }
John McCall53848232011-07-27 01:07:15 +00001492
Douglas Gregorf68a5082010-04-22 23:10:45 +00001493 /// \brief Build a new Objective-C fast enumeration statement.
1494 ///
1495 /// By default, performs semantic analysis to build the new statement.
1496 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001497 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001498 Stmt *Element,
1499 Expr *Collection,
1500 SourceLocation RParenLoc,
1501 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001502 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001503 Element,
John McCallb268a282010-08-23 23:25:46 +00001504 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001505 RParenLoc);
1506 if (ForEachStmt.isInvalid())
1507 return StmtError();
1508
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001509 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001510 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001511
Douglas Gregorebe10102009-08-20 07:17:43 +00001512 /// \brief Build a new C++ exception declaration.
1513 ///
1514 /// By default, performs semantic analysis to build the new decaration.
1515 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001516 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001517 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001518 SourceLocation StartLoc,
1519 SourceLocation IdLoc,
1520 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001521 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001522 StartLoc, IdLoc, Id);
1523 if (Var)
1524 getSema().CurContext->addDecl(Var);
1525 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001526 }
1527
1528 /// \brief Build a new C++ catch statement.
1529 ///
1530 /// By default, performs semantic analysis to build the new statement.
1531 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001532 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001533 VarDecl *ExceptionDecl,
1534 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001535 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1536 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001537 }
Mike Stump11289f42009-09-09 15:08:12 +00001538
Douglas Gregorebe10102009-08-20 07:17:43 +00001539 /// \brief Build a new C++ try statement.
1540 ///
1541 /// By default, performs semantic analysis to build the new statement.
1542 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001543 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1544 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001545 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001546 }
Mike Stump11289f42009-09-09 15:08:12 +00001547
Richard Smith02e85f32011-04-14 22:09:26 +00001548 /// \brief Build a new C++0x range-based for statement.
1549 ///
1550 /// By default, performs semantic analysis to build the new statement.
1551 /// Subclasses may override this routine to provide different behavior.
1552 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1553 SourceLocation ColonLoc,
1554 Stmt *Range, Stmt *BeginEnd,
1555 Expr *Cond, Expr *Inc,
1556 Stmt *LoopVar,
1557 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001558 // If we've just learned that the range is actually an Objective-C
1559 // collection, treat this as an Objective-C fast enumeration loop.
1560 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1561 if (RangeStmt->isSingleDecl()) {
1562 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001563 if (RangeVar->isInvalidDecl())
1564 return StmtError();
1565
Douglas Gregorf7106af2013-04-08 18:40:13 +00001566 Expr *RangeExpr = RangeVar->getInit();
1567 if (!RangeExpr->isTypeDependent() &&
1568 RangeExpr->getType()->isObjCObjectPointerType())
1569 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1570 RParenLoc);
1571 }
1572 }
1573 }
1574
Richard Smith02e85f32011-04-14 22:09:26 +00001575 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001576 Cond, Inc, LoopVar, RParenLoc,
1577 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001578 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001579
1580 /// \brief Build a new C++0x range-based for statement.
1581 ///
1582 /// By default, performs semantic analysis to build the new statement.
1583 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001584 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001585 bool IsIfExists,
1586 NestedNameSpecifierLoc QualifierLoc,
1587 DeclarationNameInfo NameInfo,
1588 Stmt *Nested) {
1589 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1590 QualifierLoc, NameInfo, Nested);
1591 }
1592
Richard Smith02e85f32011-04-14 22:09:26 +00001593 /// \brief Attach body to a C++0x range-based for statement.
1594 ///
1595 /// By default, performs semantic analysis to finish the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
1597 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1598 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001600
David Majnemerfad8f482013-10-15 09:33:02 +00001601 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1602 Stmt *TryBlock, Stmt *Handler) {
1603 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001604 }
1605
David Majnemerfad8f482013-10-15 09:33:02 +00001606 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001607 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001608 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001609 }
1610
David Majnemerfad8f482013-10-15 09:33:02 +00001611 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1612 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001613 }
1614
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// \brief Build a new expression that references a declaration.
1616 ///
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001619 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001620 LookupResult &R,
1621 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001622 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1623 }
1624
1625
1626 /// \brief Build a new expression that references a declaration.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001630 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001631 ValueDecl *VD,
1632 const DeclarationNameInfo &NameInfo,
1633 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001634 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001635 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001636
1637 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001638
1639 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 }
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001643 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001646 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001648 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
1650
Douglas Gregorad8a3362009-09-04 17:36:40 +00001651 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001652 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001656 SourceLocation OperatorLoc,
1657 bool isArrow,
1658 CXXScopeSpec &SS,
1659 TypeSourceInfo *ScopeType,
1660 SourceLocation CCLoc,
1661 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001662 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001663
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001665 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001669 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001670 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001671 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 }
Mike Stump11289f42009-09-09 15:08:12 +00001673
Douglas Gregor882211c2010-04-28 22:16:22 +00001674 /// \brief Build a new builtin offsetof expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001678 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001679 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001680 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001681 unsigned NumComponents,
1682 SourceLocation RParenLoc) {
1683 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1684 NumComponents, RParenLoc);
1685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001686
1687 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001688 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001689 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001692 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1693 SourceLocation OpLoc,
1694 UnaryExprOrTypeTrait ExprKind,
1695 SourceRange R) {
1696 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 }
1698
Peter Collingbournee190dee2011-03-11 19:24:49 +00001699 /// \brief Build a new sizeof, alignof or vec step expression with an
1700 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001701 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001704 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1705 UnaryExprOrTypeTrait ExprKind,
1706 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001707 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001708 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001711
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001712 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 }
Mike Stump11289f42009-09-09 15:08:12 +00001714
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001716 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001719 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001721 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001723 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001724 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 RBracketLoc);
1726 }
1727
1728 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001729 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001732 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001734 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001735 Expr *ExecConfig = nullptr) {
1736 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001737 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
1739
1740 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001741 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 /// 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001745 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001746 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001747 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001748 const DeclarationNameInfo &MemberNameInfo,
1749 ValueDecl *Member,
1750 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001751 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001752 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001753 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1754 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001755 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001756 // We have a reference to an unnamed field. This is always the
1757 // base of an anonymous struct/union member access, i.e. the
1758 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001759 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001760 assert(Member->getType()->isRecordType() &&
1761 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001762
Richard Smithcab9a7d2011-10-26 19:06:56 +00001763 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001764 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001765 QualifierLoc.getNestedNameSpecifier(),
1766 FoundDecl, Member);
1767 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001768 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001769 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001770 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001771 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001772 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001773 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001774 cast<FieldDecl>(Member)->getType(),
1775 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001776 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001777 }
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001779 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001780 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001781
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001782 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001783 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001784
John McCall16df1e52010-03-30 21:47:33 +00001785 // FIXME: this involves duplicating earlier analysis in a lot of
1786 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001787 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001788 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001789 R.resolveKind();
1790
John McCallb268a282010-08-23 23:25:46 +00001791 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001792 SS, TemplateKWLoc,
1793 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001794 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 }
Mike Stump11289f42009-09-09 15:08:12 +00001796
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001798 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001801 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001802 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001803 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001804 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
1806
1807 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001808 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001811 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001812 SourceLocation QuestionLoc,
1813 Expr *LHS,
1814 SourceLocation ColonLoc,
1815 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001816 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1817 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 }
1819
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001821 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001824 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001825 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001827 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001828 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001829 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001833 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001836 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001837 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001839 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001840 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001841 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001845 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001848 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 SourceLocation OpLoc,
1850 SourceLocation AccessorLoc,
1851 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001852
John McCall10eae182009-11-30 22:42:35 +00001853 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001854 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001855 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001856 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001857 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001858 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001859 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001860 /* TemplateArgs */ nullptr);
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 initializer list 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 RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001868 MultiExprArg Inits,
1869 SourceLocation RBraceLoc,
1870 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001871 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001872 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001873 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001874 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001875
Douglas Gregord3d93062009-11-09 17:16:50 +00001876 // Patch in the result type we were given, which may have been computed
1877 // when the initial InitListExpr was built.
1878 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1879 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001880 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 }
Mike Stump11289f42009-09-09 15:08:12 +00001882
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001884 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001887 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 MultiExprArg ArrayExprs,
1889 SourceLocation EqualOrColonLoc,
1890 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001891 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001894 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001897
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001898 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 }
Mike Stump11289f42009-09-09 15:08:12 +00001900
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001902 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// By default, builds the implicit value initialization without performing
1904 /// any semantic analysis. Subclasses may override this routine to provide
1905 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001907 return new (SemaRef.Context) ImplicitValueInitExpr(T);
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 \c va_arg 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 RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001915 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001916 SourceLocation RParenLoc) {
1917 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001918 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001919 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 }
1921
1922 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001923 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001927 MultiExprArg SubExprs,
1928 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001929 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 }
Mike Stump11289f42009-09-09 15:08:12 +00001931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001933 ///
1934 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 /// rather than attempting to map the label statement itself.
1936 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001937 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001938 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001939 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001943 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001947 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001949 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 }
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// \brief Build a new __builtin_choose_expr expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001956 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001957 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 SourceLocation RParenLoc) {
1959 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001960 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 RParenLoc);
1962 }
Mike Stump11289f42009-09-09 15:08:12 +00001963
Peter Collingbourne91147592011-04-15 00:35:48 +00001964 /// \brief Build a new generic selection expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
1968 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1969 SourceLocation DefaultLoc,
1970 SourceLocation RParenLoc,
1971 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001972 ArrayRef<TypeSourceInfo *> Types,
1973 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001974 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001975 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001976 }
1977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// \brief Build a new overloaded operator call expression.
1979 ///
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// The semantic analysis provides the behavior of template instantiation,
1982 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001983 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// argument-dependent lookup, etc. Subclasses may override this routine to
1985 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001986 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001988 Expr *Callee,
1989 Expr *First,
1990 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001991
1992 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// reinterpret_cast.
1994 ///
1995 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001996 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001998 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 Stmt::StmtClass Class,
2000 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002001 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 SourceLocation RAngleLoc,
2003 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002004 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 SourceLocation RParenLoc) {
2006 switch (Class) {
2007 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002008 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002009 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002011
2012 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002013 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002014 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002015 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002018 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002019 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002020 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002024 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002025 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002026 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002027
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002029 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 }
Mike Stump11289f42009-09-09 15:08:12 +00002032
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// \brief Build a new C++ static_cast expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002037 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002039 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 SourceLocation RAngleLoc,
2041 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002044 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002045 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002046 SourceRange(LAngleLoc, RAngleLoc),
2047 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 }
2049
2050 /// \brief Build a new C++ dynamic_cast expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002054 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002056 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 SourceLocation RAngleLoc,
2058 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002059 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002061 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002062 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002063 SourceRange(LAngleLoc, RAngleLoc),
2064 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 }
2066
2067 /// \brief Build a new C++ reinterpret_cast expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002073 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 SourceLocation RAngleLoc,
2075 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002076 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002078 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002079 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002080 SourceRange(LAngleLoc, RAngleLoc),
2081 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 }
2083
2084 /// \brief Build a new C++ const_cast expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002090 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 SourceLocation RAngleLoc,
2092 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002093 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002095 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002096 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002097 SourceRange(LAngleLoc, RAngleLoc),
2098 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 }
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// \brief Build a new C++ functional-style cast expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002105 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2106 SourceLocation LParenLoc,
2107 Expr *Sub,
2108 SourceLocation RParenLoc) {
2109 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002110 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 RParenLoc);
2112 }
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// \brief Build a new C++ typeid(type) expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002118 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002119 SourceLocation TypeidLoc,
2120 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002122 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002123 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 }
Mike Stump11289f42009-09-09 15:08:12 +00002125
Francois Pichet9f4f2072010-09-08 12:20:18 +00002126
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 /// \brief Build a new C++ typeid(expr) expression.
2128 ///
2129 /// By default, performs semantic analysis to build the new expression.
2130 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002131 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002132 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002133 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002135 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002136 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002137 }
2138
Francois Pichet9f4f2072010-09-08 12:20:18 +00002139 /// \brief Build a new C++ __uuidof(type) expression.
2140 ///
2141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
2143 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2144 SourceLocation TypeidLoc,
2145 TypeSourceInfo *Operand,
2146 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002147 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002148 RParenLoc);
2149 }
2150
2151 /// \brief Build a new C++ __uuidof(expr) expression.
2152 ///
2153 /// By default, performs semantic analysis to build the new expression.
2154 /// Subclasses may override this routine to provide different behavior.
2155 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2156 SourceLocation TypeidLoc,
2157 Expr *Operand,
2158 SourceLocation RParenLoc) {
2159 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2160 RParenLoc);
2161 }
2162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new C++ "this" expression.
2164 ///
2165 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002166 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002168 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002169 QualType ThisType,
2170 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002171 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002172 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
2174
2175 /// \brief Build a new C++ throw expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002179 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2180 bool IsThrownVariableInScope) {
2181 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 }
2183
2184 /// \brief Build a new C++ default-argument expression.
2185 ///
2186 /// By default, builds a new default-argument expression, which does not
2187 /// require any semantic analysis. Subclasses may override this routine to
2188 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002189 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002190 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002191 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 }
2193
Richard Smith852c9db2013-04-20 22:23:05 +00002194 /// \brief Build a new C++11 default-initialization expression.
2195 ///
2196 /// By default, builds a new default field initialization expression, which
2197 /// does not require any semantic analysis. Subclasses may override this
2198 /// routine to provide different behavior.
2199 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2200 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002201 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002202 }
2203
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 /// \brief Build a new C++ zero-initialization expression.
2205 ///
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002208 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2209 SourceLocation LParenLoc,
2210 SourceLocation RParenLoc) {
2211 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002212 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 }
Mike Stump11289f42009-09-09 15:08:12 +00002214
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 /// \brief Build a new C++ "new" expression.
2216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002219 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002220 bool UseGlobal,
2221 SourceLocation PlacementLParen,
2222 MultiExprArg PlacementArgs,
2223 SourceLocation PlacementRParen,
2224 SourceRange TypeIdParens,
2225 QualType AllocatedType,
2226 TypeSourceInfo *AllocatedTypeInfo,
2227 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002228 SourceRange DirectInitRange,
2229 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002230 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002232 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002234 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002235 AllocatedType,
2236 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002237 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002238 DirectInitRange,
2239 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 }
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 /// \brief Build a new C++ "delete" expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 bool IsGlobalDelete,
2248 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002249 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002251 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 }
Mike Stump11289f42009-09-09 15:08:12 +00002253
Douglas Gregor29c42f22012-02-24 07:38:34 +00002254 /// \brief Build a new type trait expression.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
2258 ExprResult RebuildTypeTrait(TypeTrait Trait,
2259 SourceLocation StartLoc,
2260 ArrayRef<TypeSourceInfo *> Args,
2261 SourceLocation RParenLoc) {
2262 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002264
John Wiegley6242b6a2011-04-28 00:16:57 +00002265 /// \brief Build a new array type trait expression.
2266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
2269 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2270 SourceLocation StartLoc,
2271 TypeSourceInfo *TSInfo,
2272 Expr *DimExpr,
2273 SourceLocation RParenLoc) {
2274 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2275 }
2276
John Wiegleyf9f65842011-04-25 06:54:41 +00002277 /// \brief Build a new expression trait expression.
2278 ///
2279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
2281 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2282 SourceLocation StartLoc,
2283 Expr *Queried,
2284 SourceLocation RParenLoc) {
2285 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2286 }
2287
Mike Stump11289f42009-09-09 15:08:12 +00002288 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 /// expression.
2290 ///
2291 /// By default, performs semantic analysis to build the new expression.
2292 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002293 ExprResult RebuildDependentScopeDeclRefExpr(
2294 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002295 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002296 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002297 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002298 bool IsAddressOfOperand,
2299 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002301 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002302
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002303 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002304 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2305 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002306
Reid Kleckner32506ed2014-06-12 23:03:48 +00002307 return getSema().BuildQualifiedDeclarationNameExpr(
2308 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 }
2310
2311 /// \brief Build a new template-id expression.
2312 ///
2313 /// By default, performs semantic analysis to build the new expression.
2314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002315 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002316 SourceLocation TemplateKWLoc,
2317 LookupResult &R,
2318 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002319 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002320 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2321 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 }
2323
2324 /// \brief Build a new object-construction expression.
2325 ///
2326 /// By default, performs semantic analysis to build the new expression.
2327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002328 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002329 SourceLocation Loc,
2330 CXXConstructorDecl *Constructor,
2331 bool IsElidable,
2332 MultiExprArg Args,
2333 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002334 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002335 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002336 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002337 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002338 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002339 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002340 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002341 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002342
Douglas Gregordb121ba2009-12-14 16:27:04 +00002343 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002344 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002345 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002346 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002347 RequiresZeroInit, ConstructKind,
2348 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 }
2350
2351 /// \brief Build a new object-construction expression.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002355 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2356 SourceLocation LParenLoc,
2357 MultiExprArg Args,
2358 SourceLocation RParenLoc) {
2359 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002361 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 RParenLoc);
2363 }
2364
2365 /// \brief Build a new object-construction expression.
2366 ///
2367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002369 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2370 SourceLocation LParenLoc,
2371 MultiExprArg Args,
2372 SourceLocation RParenLoc) {
2373 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002375 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002376 RParenLoc);
2377 }
Mike Stump11289f42009-09-09 15:08:12 +00002378
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 /// \brief Build a new member reference expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002383 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002384 QualType BaseType,
2385 bool IsArrow,
2386 SourceLocation OperatorLoc,
2387 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002388 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002389 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002390 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002391 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002393 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002394
John McCallb268a282010-08-23 23:25:46 +00002395 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002396 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002397 SS, TemplateKWLoc,
2398 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002399 MemberNameInfo,
2400 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 }
2402
John McCall10eae182009-11-30 22:42:35 +00002403 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002404 ///
2405 /// By default, performs semantic analysis to build the new expression.
2406 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002407 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2408 SourceLocation OperatorLoc,
2409 bool IsArrow,
2410 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002411 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002412 NamedDecl *FirstQualifierInScope,
2413 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002414 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002415 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002416 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002417
John McCallb268a282010-08-23 23:25:46 +00002418 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002419 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002420 SS, TemplateKWLoc,
2421 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002422 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002423 }
Mike Stump11289f42009-09-09 15:08:12 +00002424
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002425 /// \brief Build a new noexcept expression.
2426 ///
2427 /// By default, performs semantic analysis to build the new expression.
2428 /// Subclasses may override this routine to provide different behavior.
2429 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2430 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2431 }
2432
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002433 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002434 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2435 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002436 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002437 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002438 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002439 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2440 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002441 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002442
2443 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2444 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002445 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002446 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002447
Patrick Beard0caa3942012-04-19 00:25:12 +00002448 /// \brief Build a new Objective-C boxed expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
2452 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2453 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002455
Ted Kremeneke65b0862012-03-06 20:05:56 +00002456 /// \brief Build a new Objective-C array literal.
2457 ///
2458 /// By default, performs semantic analysis to build the new expression.
2459 /// Subclasses may override this routine to provide different behavior.
2460 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2461 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002462 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002463 MultiExprArg(Elements, NumElements));
2464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002465
2466 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002467 Expr *Base, Expr *Key,
2468 ObjCMethodDecl *getterMethod,
2469 ObjCMethodDecl *setterMethod) {
2470 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2471 getterMethod, setterMethod);
2472 }
2473
2474 /// \brief Build a new Objective-C dictionary literal.
2475 ///
2476 /// By default, performs semantic analysis to build the new expression.
2477 /// Subclasses may override this routine to provide different behavior.
2478 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2479 ObjCDictionaryElement *Elements,
2480 unsigned NumElements) {
2481 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002483
James Dennett2a4d13c2012-06-15 07:13:21 +00002484 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 ///
2486 /// By default, performs semantic analysis to build the new expression.
2487 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002488 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002489 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002491 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002492 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002493
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002494 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002495 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002496 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002497 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002498 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002499 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002500 MultiExprArg Args,
2501 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002502 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2503 ReceiverTypeInfo->getType(),
2504 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002505 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002506 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002507 }
2508
2509 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002510 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002511 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002512 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002513 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002514 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002515 MultiExprArg Args,
2516 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002517 return SemaRef.BuildInstanceMessage(Receiver,
2518 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002519 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002520 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002521 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002522 }
2523
Douglas Gregord51d90d2010-04-26 20:11:03 +00002524 /// \brief Build a new Objective-C ivar reference expression.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002528 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002529 SourceLocation IvarLoc,
2530 bool IsArrow, bool IsFreeIvar) {
2531 // FIXME: We lose track of the IsFreeIvar bit.
2532 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002533 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2534 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002535 /*FIXME:*/IvarLoc, IsArrow,
2536 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002537 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002538 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002539 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002540 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002541
2542 /// \brief Build a new Objective-C property reference expression.
2543 ///
2544 /// By default, performs semantic analysis to build the new expression.
2545 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002546 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002547 ObjCPropertyDecl *Property,
2548 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002549 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002550 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2551 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2552 /*FIXME:*/PropertyLoc,
2553 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002554 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002555 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002556 NameInfo,
2557 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002559
John McCallb7bd14f2010-12-02 01:19:52 +00002560 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002561 ///
2562 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002563 /// Subclasses may override this routine to provide different behavior.
2564 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2565 ObjCMethodDecl *Getter,
2566 ObjCMethodDecl *Setter,
2567 SourceLocation PropertyLoc) {
2568 // Since these expressions can only be value-dependent, we do not
2569 // need to perform semantic analysis again.
2570 return Owned(
2571 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2572 VK_LValue, OK_ObjCProperty,
2573 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002574 }
2575
Douglas Gregord51d90d2010-04-26 20:11:03 +00002576 /// \brief Build a new Objective-C "isa" expression.
2577 ///
2578 /// By default, performs semantic analysis to build the new expression.
2579 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002580 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002581 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002582 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002583 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2584 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002585 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002586 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002587 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002588 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002589 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002591
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 /// \brief Build a new shuffle vector 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 RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002597 MultiExprArg SubExprs,
2598 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002599 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002600 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2602 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2603 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002604 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002605
Douglas Gregora16548e2009-08-11 05:31:07 +00002606 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002607 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002608 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2609 SemaRef.Context.BuiltinFnTy,
2610 VK_RValue, BuiltinLoc);
2611 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2612 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002613 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002614
2615 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002616 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002617 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002618 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002619
Douglas Gregora16548e2009-08-11 05:31:07 +00002620 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002621 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 }
John McCall31f82722010-11-12 08:19:04 +00002623
Hal Finkelc4d7c822013-09-18 03:29:45 +00002624 /// \brief Build a new convert vector expression.
2625 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2626 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2627 SourceLocation RParenLoc) {
2628 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2629 BuiltinLoc, RParenLoc);
2630 }
2631
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002632 /// \brief Build a new template argument pack expansion.
2633 ///
2634 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002635 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002636 /// different behavior.
2637 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002638 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002639 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002640 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002641 case TemplateArgument::Expression: {
2642 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002643 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2644 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002645 if (Result.isInvalid())
2646 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002647
Douglas Gregor98318c22011-01-03 21:37:45 +00002648 return TemplateArgumentLoc(Result.get(), Result.get());
2649 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002650
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002651 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002652 return TemplateArgumentLoc(TemplateArgument(
2653 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002654 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002655 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002656 Pattern.getTemplateNameLoc(),
2657 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002659 case TemplateArgument::Null:
2660 case TemplateArgument::Integral:
2661 case TemplateArgument::Declaration:
2662 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002663 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002664 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002665 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002666
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002667 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002668 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002669 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002670 EllipsisLoc,
2671 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002672 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2673 Expansion);
2674 break;
2675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002676
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002677 return TemplateArgumentLoc();
2678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002679
Douglas Gregor968f23a2011-01-03 19:31:53 +00002680 /// \brief Build a new expression pack expansion.
2681 ///
2682 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002683 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002684 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002685 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002686 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002687 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002688 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002689
2690 /// \brief Build a new atomic operation expression.
2691 ///
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
2694 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2695 MultiExprArg SubExprs,
2696 QualType RetTy,
2697 AtomicExpr::AtomicOp Op,
2698 SourceLocation RParenLoc) {
2699 // Just create the expression; there is not any interesting semantic
2700 // analysis here because we can't actually build an AtomicExpr until
2701 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002702 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002703 RParenLoc);
2704 }
2705
John McCall31f82722010-11-12 08:19:04 +00002706private:
Douglas Gregor14454802011-02-25 02:25:35 +00002707 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2708 QualType ObjectType,
2709 NamedDecl *FirstQualifierInScope,
2710 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002711
2712 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2713 QualType ObjectType,
2714 NamedDecl *FirstQualifierInScope,
2715 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002716
2717 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2718 NamedDecl *FirstQualifierInScope,
2719 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002720};
Douglas Gregora16548e2009-08-11 05:31:07 +00002721
Douglas Gregorebe10102009-08-20 07:17:43 +00002722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002723StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002724 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002725 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002726
Douglas Gregorebe10102009-08-20 07:17:43 +00002727 switch (S->getStmtClass()) {
2728 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002729
Douglas Gregorebe10102009-08-20 07:17:43 +00002730 // Transform individual statement nodes
2731#define STMT(Node, Parent) \
2732 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002733#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002734#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002735#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002736
Douglas Gregorebe10102009-08-20 07:17:43 +00002737 // Transform expressions by calling TransformExpr.
2738#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002739#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002740#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002741#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002742 {
John McCalldadc5752010-08-24 06:29:42 +00002743 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002744 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002745 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002746
Richard Smith945f8d32013-01-14 22:39:08 +00002747 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002748 }
Mike Stump11289f42009-09-09 15:08:12 +00002749 }
2750
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002751 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002752}
Mike Stump11289f42009-09-09 15:08:12 +00002753
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002754template<typename Derived>
2755OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2756 if (!S)
2757 return S;
2758
2759 switch (S->getClauseKind()) {
2760 default: break;
2761 // Transform individual clause nodes
2762#define OPENMP_CLAUSE(Name, Class) \
2763 case OMPC_ ## Name : \
2764 return getDerived().Transform ## Class(cast<Class>(S));
2765#include "clang/Basic/OpenMPKinds.def"
2766 }
2767
2768 return S;
2769}
2770
Mike Stump11289f42009-09-09 15:08:12 +00002771
Douglas Gregore922c772009-08-04 22:27:00 +00002772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002773ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002774 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002775 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002776
2777 switch (E->getStmtClass()) {
2778 case Stmt::NoStmtClass: break;
2779#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002780#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002781#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002782 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002783#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002784 }
2785
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002786 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002787}
2788
2789template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002790ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2791 bool CXXDirectInit) {
2792 // Initializers are instantiated like expressions, except that various outer
2793 // layers are stripped.
2794 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002795 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002796
2797 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2798 Init = ExprTemp->getSubExpr();
2799
Richard Smithe6ca4752013-05-30 22:40:16 +00002800 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2801 Init = MTE->GetTemporaryExpr();
2802
Richard Smithd59b8322012-12-19 01:39:02 +00002803 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2804 Init = Binder->getSubExpr();
2805
2806 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2807 Init = ICE->getSubExprAsWritten();
2808
Richard Smithcc1b96d2013-06-12 22:31:48 +00002809 if (CXXStdInitializerListExpr *ILE =
2810 dyn_cast<CXXStdInitializerListExpr>(Init))
2811 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2812
Richard Smith38a549b2012-12-21 08:13:35 +00002813 // If this is not a direct-initializer, we only need to reconstruct
2814 // InitListExprs. Other forms of copy-initialization will be a no-op if
2815 // the initializer is already the right type.
2816 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2817 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2818 return getDerived().TransformExpr(Init);
2819
2820 // Revert value-initialization back to empty parens.
2821 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2822 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002823 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002824 Parens.getEnd());
2825 }
2826
2827 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2828 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002829 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002830 SourceLocation());
2831
2832 // Revert initialization by constructor back to a parenthesized or braced list
2833 // of expressions. Any other form of initializer can just be reused directly.
2834 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002835 return getDerived().TransformExpr(Init);
2836
2837 SmallVector<Expr*, 8> NewArgs;
2838 bool ArgChanged = false;
2839 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2840 /*IsCall*/true, NewArgs, &ArgChanged))
2841 return ExprError();
2842
2843 // If this was list initialization, revert to list form.
2844 if (Construct->isListInitialization())
2845 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2846 Construct->getLocEnd(),
2847 Construct->getType());
2848
Richard Smithd59b8322012-12-19 01:39:02 +00002849 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002850 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002851 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2852 Parens.getEnd());
2853}
2854
2855template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002856bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2857 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002858 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002859 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002860 bool *ArgChanged) {
2861 for (unsigned I = 0; I != NumInputs; ++I) {
2862 // If requested, drop call arguments that need to be dropped.
2863 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2864 if (ArgChanged)
2865 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002866
Douglas Gregora3efea12011-01-03 19:04:46 +00002867 break;
2868 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002869
Douglas Gregor968f23a2011-01-03 19:31:53 +00002870 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2871 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002872
Chris Lattner01cf8db2011-07-20 06:58:45 +00002873 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002874 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2875 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002876
Douglas Gregor968f23a2011-01-03 19:31:53 +00002877 // Determine whether the set of unexpanded parameter packs can and should
2878 // be expanded.
2879 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002880 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002881 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2882 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002883 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2884 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002885 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002886 Expand, RetainExpansion,
2887 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002888 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002889
Douglas Gregor968f23a2011-01-03 19:31:53 +00002890 if (!Expand) {
2891 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002892 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002893 // expansion.
2894 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2895 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2896 if (OutPattern.isInvalid())
2897 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002898
2899 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002900 Expansion->getEllipsisLoc(),
2901 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002902 if (Out.isInvalid())
2903 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002904
Douglas Gregor968f23a2011-01-03 19:31:53 +00002905 if (ArgChanged)
2906 *ArgChanged = true;
2907 Outputs.push_back(Out.get());
2908 continue;
2909 }
John McCall542e7c62011-07-06 07:30:07 +00002910
2911 // Record right away that the argument was changed. This needs
2912 // to happen even if the array expands to nothing.
2913 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
Douglas Gregor968f23a2011-01-03 19:31:53 +00002915 // The transform has determined that we should perform an elementwise
2916 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002917 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2919 ExprResult Out = getDerived().TransformExpr(Pattern);
2920 if (Out.isInvalid())
2921 return true;
2922
Richard Smith9467be42014-06-06 17:33:35 +00002923 // FIXME: Can this happen? We should not try to expand the pack
2924 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002925 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002926 Out = getDerived().RebuildPackExpansion(
2927 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002928 if (Out.isInvalid())
2929 return true;
2930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002931
Douglas Gregor968f23a2011-01-03 19:31:53 +00002932 Outputs.push_back(Out.get());
2933 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002934
Richard Smith9467be42014-06-06 17:33:35 +00002935 // If we're supposed to retain a pack expansion, do so by temporarily
2936 // forgetting the partially-substituted parameter pack.
2937 if (RetainExpansion) {
2938 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2939
2940 ExprResult Out = getDerived().TransformExpr(Pattern);
2941 if (Out.isInvalid())
2942 return true;
2943
2944 Out = getDerived().RebuildPackExpansion(
2945 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
2946 if (Out.isInvalid())
2947 return true;
2948
2949 Outputs.push_back(Out.get());
2950 }
2951
Douglas Gregor968f23a2011-01-03 19:31:53 +00002952 continue;
2953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Richard Smithd59b8322012-12-19 01:39:02 +00002955 ExprResult Result =
2956 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2957 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002958 if (Result.isInvalid())
2959 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
Douglas Gregora3efea12011-01-03 19:04:46 +00002961 if (Result.get() != Inputs[I] && ArgChanged)
2962 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002963
2964 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002966
Douglas Gregora3efea12011-01-03 19:04:46 +00002967 return false;
2968}
2969
2970template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002971NestedNameSpecifierLoc
2972TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2973 NestedNameSpecifierLoc NNS,
2974 QualType ObjectType,
2975 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002976 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002977 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002978 Qualifier = Qualifier.getPrefix())
2979 Qualifiers.push_back(Qualifier);
2980
2981 CXXScopeSpec SS;
2982 while (!Qualifiers.empty()) {
2983 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2984 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002985
Douglas Gregor14454802011-02-25 02:25:35 +00002986 switch (QNNS->getKind()) {
2987 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00002988 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00002989 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002990 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002991 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002992 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002993 FirstQualifierInScope, false))
2994 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002995
Douglas Gregor14454802011-02-25 02:25:35 +00002996 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002997
Douglas Gregor14454802011-02-25 02:25:35 +00002998 case NestedNameSpecifier::Namespace: {
2999 NamespaceDecl *NS
3000 = cast_or_null<NamespaceDecl>(
3001 getDerived().TransformDecl(
3002 Q.getLocalBeginLoc(),
3003 QNNS->getAsNamespace()));
3004 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3005 break;
3006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003007
Douglas Gregor14454802011-02-25 02:25:35 +00003008 case NestedNameSpecifier::NamespaceAlias: {
3009 NamespaceAliasDecl *Alias
3010 = cast_or_null<NamespaceAliasDecl>(
3011 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3012 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003013 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003014 Q.getLocalEndLoc());
3015 break;
3016 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003017
Douglas Gregor14454802011-02-25 02:25:35 +00003018 case NestedNameSpecifier::Global:
3019 // There is no meaningful transformation that one could perform on the
3020 // global scope.
3021 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3022 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregor14454802011-02-25 02:25:35 +00003024 case NestedNameSpecifier::TypeSpecWithTemplate:
3025 case NestedNameSpecifier::TypeSpec: {
3026 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3027 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003028
Douglas Gregor14454802011-02-25 02:25:35 +00003029 if (!TL)
3030 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003031
Douglas Gregor14454802011-02-25 02:25:35 +00003032 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003033 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003034 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003035 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003036 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003037 if (TL.getType()->isEnumeralType())
3038 SemaRef.Diag(TL.getBeginLoc(),
3039 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003040 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3041 Q.getLocalEndLoc());
3042 break;
3043 }
Richard Trieude756fb2011-05-07 01:36:37 +00003044 // If the nested-name-specifier is an invalid type def, don't emit an
3045 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003046 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3047 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003048 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003049 << TL.getType() << SS.getRange();
3050 }
Douglas Gregor14454802011-02-25 02:25:35 +00003051 return NestedNameSpecifierLoc();
3052 }
Douglas Gregore16af532011-02-28 18:50:33 +00003053 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003054
Douglas Gregore16af532011-02-28 18:50:33 +00003055 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003056 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003057 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003058 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor14454802011-02-25 02:25:35 +00003060 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003061 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003062 !getDerived().AlwaysRebuild())
3063 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
3065 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003066 // nested-name-specifier, do so.
3067 if (SS.location_size() == NNS.getDataLength() &&
3068 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3069 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3070
3071 // Allocate new nested-name-specifier location information.
3072 return SS.getWithLocInContext(SemaRef.Context);
3073}
3074
3075template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003076DeclarationNameInfo
3077TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003078::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003079 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003080 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003081 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003082
3083 switch (Name.getNameKind()) {
3084 case DeclarationName::Identifier:
3085 case DeclarationName::ObjCZeroArgSelector:
3086 case DeclarationName::ObjCOneArgSelector:
3087 case DeclarationName::ObjCMultiArgSelector:
3088 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003089 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003090 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003091 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003092
Douglas Gregorf816bd72009-09-03 22:13:48 +00003093 case DeclarationName::CXXConstructorName:
3094 case DeclarationName::CXXDestructorName:
3095 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003096 TypeSourceInfo *NewTInfo;
3097 CanQualType NewCanTy;
3098 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003099 NewTInfo = getDerived().TransformType(OldTInfo);
3100 if (!NewTInfo)
3101 return DeclarationNameInfo();
3102 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003103 }
3104 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003105 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003106 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003107 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003108 if (NewT.isNull())
3109 return DeclarationNameInfo();
3110 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3111 }
Mike Stump11289f42009-09-09 15:08:12 +00003112
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003113 DeclarationName NewName
3114 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3115 NewCanTy);
3116 DeclarationNameInfo NewNameInfo(NameInfo);
3117 NewNameInfo.setName(NewName);
3118 NewNameInfo.setNamedTypeInfo(NewTInfo);
3119 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003120 }
Mike Stump11289f42009-09-09 15:08:12 +00003121 }
3122
David Blaikie83d382b2011-09-23 05:06:16 +00003123 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003124}
3125
3126template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003127TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003128TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3129 TemplateName Name,
3130 SourceLocation NameLoc,
3131 QualType ObjectType,
3132 NamedDecl *FirstQualifierInScope) {
3133 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3134 TemplateDecl *Template = QTN->getTemplateDecl();
3135 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003136
Douglas Gregor9db53502011-03-02 18:07:45 +00003137 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003138 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003139 Template));
3140 if (!TransTemplate)
3141 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003142
Douglas Gregor9db53502011-03-02 18:07:45 +00003143 if (!getDerived().AlwaysRebuild() &&
3144 SS.getScopeRep() == QTN->getQualifier() &&
3145 TransTemplate == Template)
3146 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003147
Douglas Gregor9db53502011-03-02 18:07:45 +00003148 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3149 TransTemplate);
3150 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003151
Douglas Gregor9db53502011-03-02 18:07:45 +00003152 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3153 if (SS.getScopeRep()) {
3154 // These apply to the scope specifier, not the template.
3155 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003156 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003157 }
3158
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 if (!getDerived().AlwaysRebuild() &&
3160 SS.getScopeRep() == DTN->getQualifier() &&
3161 ObjectType.isNull())
3162 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Douglas Gregor9db53502011-03-02 18:07:45 +00003164 if (DTN->isIdentifier()) {
3165 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003166 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003167 NameLoc,
3168 ObjectType,
3169 FirstQualifierInScope);
3170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003171
Douglas Gregor9db53502011-03-02 18:07:45 +00003172 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3173 ObjectType);
3174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregor9db53502011-03-02 18:07:45 +00003176 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3177 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003178 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003179 Template));
3180 if (!TransTemplate)
3181 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregor9db53502011-03-02 18:07:45 +00003183 if (!getDerived().AlwaysRebuild() &&
3184 TransTemplate == Template)
3185 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003186
Douglas Gregor9db53502011-03-02 18:07:45 +00003187 return TemplateName(TransTemplate);
3188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003189
Douglas Gregor9db53502011-03-02 18:07:45 +00003190 if (SubstTemplateTemplateParmPackStorage *SubstPack
3191 = Name.getAsSubstTemplateTemplateParmPack()) {
3192 TemplateTemplateParmDecl *TransParam
3193 = cast_or_null<TemplateTemplateParmDecl>(
3194 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3195 if (!TransParam)
3196 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor9db53502011-03-02 18:07:45 +00003198 if (!getDerived().AlwaysRebuild() &&
3199 TransParam == SubstPack->getParameterPack())
3200 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003201
3202 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003203 SubstPack->getArgumentPack());
3204 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
Douglas Gregor9db53502011-03-02 18:07:45 +00003206 // These should be getting filtered out before they reach the AST.
3207 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003208}
3209
3210template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003211void TreeTransform<Derived>::InventTemplateArgumentLoc(
3212 const TemplateArgument &Arg,
3213 TemplateArgumentLoc &Output) {
3214 SourceLocation Loc = getDerived().getBaseLocation();
3215 switch (Arg.getKind()) {
3216 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003217 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003218 break;
3219
3220 case TemplateArgument::Type:
3221 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003222 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003223
John McCall0ad16662009-10-29 08:12:44 +00003224 break;
3225
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003226 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003227 case TemplateArgument::TemplateExpansion: {
3228 NestedNameSpecifierLocBuilder Builder;
3229 TemplateName Template = Arg.getAsTemplate();
3230 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3231 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3232 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3233 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003234
Douglas Gregor9d802122011-03-02 17:09:35 +00003235 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003236 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003237 Builder.getWithLocInContext(SemaRef.Context),
3238 Loc);
3239 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003240 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003241 Builder.getWithLocInContext(SemaRef.Context),
3242 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003243
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003244 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003245 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003246
John McCall0ad16662009-10-29 08:12:44 +00003247 case TemplateArgument::Expression:
3248 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3249 break;
3250
3251 case TemplateArgument::Declaration:
3252 case TemplateArgument::Integral:
3253 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003254 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003255 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003256 break;
3257 }
3258}
3259
3260template<typename Derived>
3261bool TreeTransform<Derived>::TransformTemplateArgument(
3262 const TemplateArgumentLoc &Input,
3263 TemplateArgumentLoc &Output) {
3264 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003265 switch (Arg.getKind()) {
3266 case TemplateArgument::Null:
3267 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003268 case TemplateArgument::Pack:
3269 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003270 case TemplateArgument::NullPtr:
3271 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003272
Douglas Gregore922c772009-08-04 22:27:00 +00003273 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003274 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003275 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003276 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003277
3278 DI = getDerived().TransformType(DI);
3279 if (!DI) return true;
3280
3281 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3282 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003283 }
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003285 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003286 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3287 if (QualifierLoc) {
3288 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3289 if (!QualifierLoc)
3290 return true;
3291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregordf846d12011-03-02 18:46:51 +00003293 CXXScopeSpec SS;
3294 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003295 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003296 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3297 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003298 if (Template.isNull())
3299 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregor9d802122011-03-02 17:09:35 +00003301 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003302 Input.getTemplateNameLoc());
3303 return false;
3304 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003305
3306 case TemplateArgument::TemplateExpansion:
3307 llvm_unreachable("Caller should expand pack expansions");
3308
Douglas Gregore922c772009-08-04 22:27:00 +00003309 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003310 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003311 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003312 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003313
John McCall0ad16662009-10-29 08:12:44 +00003314 Expr *InputExpr = Input.getSourceExpression();
3315 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3316
Chris Lattnercdb591a2011-04-25 20:37:58 +00003317 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003318 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003319 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003320 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003321 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003322 }
Douglas Gregore922c772009-08-04 22:27:00 +00003323 }
Mike Stump11289f42009-09-09 15:08:12 +00003324
Douglas Gregore922c772009-08-04 22:27:00 +00003325 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003326 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003327}
3328
Douglas Gregorfe921a72010-12-20 23:36:19 +00003329/// \brief Iterator adaptor that invents template argument location information
3330/// for each of the template arguments in its underlying iterator.
3331template<typename Derived, typename InputIterator>
3332class TemplateArgumentLocInventIterator {
3333 TreeTransform<Derived> &Self;
3334 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336public:
3337 typedef TemplateArgumentLoc value_type;
3338 typedef TemplateArgumentLoc reference;
3339 typedef typename std::iterator_traits<InputIterator>::difference_type
3340 difference_type;
3341 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003342
Douglas Gregorfe921a72010-12-20 23:36:19 +00003343 class pointer {
3344 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregorfe921a72010-12-20 23:36:19 +00003346 public:
3347 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003348
Douglas Gregorfe921a72010-12-20 23:36:19 +00003349 const TemplateArgumentLoc *operator->() const { return &Arg; }
3350 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregorfe921a72010-12-20 23:36:19 +00003352 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Douglas Gregorfe921a72010-12-20 23:36:19 +00003354 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3355 InputIterator Iter)
3356 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregorfe921a72010-12-20 23:36:19 +00003358 TemplateArgumentLocInventIterator &operator++() {
3359 ++Iter;
3360 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003361 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregorfe921a72010-12-20 23:36:19 +00003363 TemplateArgumentLocInventIterator operator++(int) {
3364 TemplateArgumentLocInventIterator Old(*this);
3365 ++(*this);
3366 return Old;
3367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregorfe921a72010-12-20 23:36:19 +00003369 reference operator*() const {
3370 TemplateArgumentLoc Result;
3371 Self.InventTemplateArgumentLoc(*Iter, Result);
3372 return Result;
3373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregorfe921a72010-12-20 23:36:19 +00003375 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003376
Douglas Gregorfe921a72010-12-20 23:36:19 +00003377 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3378 const TemplateArgumentLocInventIterator &Y) {
3379 return X.Iter == Y.Iter;
3380 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003381
Douglas Gregorfe921a72010-12-20 23:36:19 +00003382 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3383 const TemplateArgumentLocInventIterator &Y) {
3384 return X.Iter != Y.Iter;
3385 }
3386};
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor42cafa82010-12-20 17:42:22 +00003388template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003389template<typename InputIterator>
3390bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3391 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003392 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003393 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003394 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003395 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003397 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3398 // Unpack argument packs, which we translate them into separate
3399 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003400 // FIXME: We could do much better if we could guarantee that the
3401 // TemplateArgumentLocInfo for the pack expansion would be usable for
3402 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003403 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003404 TemplateArgument::pack_iterator>
3405 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003406 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003407 In.getArgument().pack_begin()),
3408 PackLocIterator(*this,
3409 In.getArgument().pack_end()),
3410 Outputs))
3411 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003413 continue;
3414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003416 if (In.getArgument().isPackExpansion()) {
3417 // We have a pack expansion, for which we will be substituting into
3418 // the pattern.
3419 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003420 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003421 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003422 = getSema().getTemplateArgumentPackExpansionPattern(
3423 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Chris Lattner01cf8db2011-07-20 06:58:45 +00003425 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003426 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3427 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003429 // Determine whether the set of unexpanded parameter packs can and should
3430 // be expanded.
3431 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003432 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003433 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003434 if (getDerived().TryExpandParameterPacks(Ellipsis,
3435 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003436 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003437 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003438 RetainExpansion,
3439 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003440 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003442 if (!Expand) {
3443 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003444 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003445 // expansion.
3446 TemplateArgumentLoc OutPattern;
3447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3448 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3449 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003451 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3452 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003453 if (Out.getArgument().isNull())
3454 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003456 Outputs.addArgument(Out);
3457 continue;
3458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003460 // The transform has determined that we should perform an elementwise
3461 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003462 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3464
3465 if (getDerived().TransformTemplateArgument(Pattern, Out))
3466 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003467
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003468 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003469 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3470 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003471 if (Out.getArgument().isNull())
3472 return true;
3473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003475 Outputs.addArgument(Out);
3476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor48d24112011-01-10 20:53:55 +00003478 // If we're supposed to retain a pack expansion, do so by temporarily
3479 // forgetting the partially-substituted parameter pack.
3480 if (RetainExpansion) {
3481 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
Douglas Gregor48d24112011-01-10 20:53:55 +00003483 if (getDerived().TransformTemplateArgument(Pattern, Out))
3484 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003486 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3487 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003488 if (Out.getArgument().isNull())
3489 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor48d24112011-01-10 20:53:55 +00003491 Outputs.addArgument(Out);
3492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003494 continue;
3495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003496
3497 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003498 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003499 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003500
Douglas Gregor42cafa82010-12-20 17:42:22 +00003501 Outputs.addArgument(Out);
3502 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
Douglas Gregor42cafa82010-12-20 17:42:22 +00003504 return false;
3505
3506}
3507
Douglas Gregord6ff3322009-08-04 16:50:30 +00003508//===----------------------------------------------------------------------===//
3509// Type transformation
3510//===----------------------------------------------------------------------===//
3511
3512template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003513QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003514 if (getDerived().AlreadyTransformed(T))
3515 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003516
John McCall550e0c22009-10-21 00:40:46 +00003517 // Temporary workaround. All of these transformations should
3518 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003519 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3520 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
John McCall31f82722010-11-12 08:19:04 +00003522 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003523
John McCall550e0c22009-10-21 00:40:46 +00003524 if (!NewDI)
3525 return QualType();
3526
3527 return NewDI->getType();
3528}
3529
3530template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003531TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003532 // Refine the base location to the type's location.
3533 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3534 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003535 if (getDerived().AlreadyTransformed(DI->getType()))
3536 return DI;
3537
3538 TypeLocBuilder TLB;
3539
3540 TypeLoc TL = DI->getTypeLoc();
3541 TLB.reserve(TL.getFullDataSize());
3542
John McCall31f82722010-11-12 08:19:04 +00003543 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003544 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003545 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003546
John McCallbcd03502009-12-07 02:54:59 +00003547 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003548}
3549
3550template<typename Derived>
3551QualType
John McCall31f82722010-11-12 08:19:04 +00003552TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003553 switch (T.getTypeLocClass()) {
3554#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003555#define TYPELOC(CLASS, PARENT) \
3556 case TypeLoc::CLASS: \
3557 return getDerived().Transform##CLASS##Type(TLB, \
3558 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003559#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003560 }
Mike Stump11289f42009-09-09 15:08:12 +00003561
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003562 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003563}
3564
3565/// FIXME: By default, this routine adds type qualifiers only to types
3566/// that can have qualifiers, and silently suppresses those qualifiers
3567/// that are not permitted (e.g., qualifiers on reference or function
3568/// types). This is the right thing for template instantiation, but
3569/// probably not for other clients.
3570template<typename Derived>
3571QualType
3572TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003573 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003574 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003575
John McCall31f82722010-11-12 08:19:04 +00003576 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003577 if (Result.isNull())
3578 return QualType();
3579
3580 // Silently suppress qualifiers if the result type can't be qualified.
3581 // FIXME: this is the right thing for template instantiation, but
3582 // probably not for other clients.
3583 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003584 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003585
John McCall31168b02011-06-15 23:02:42 +00003586 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003587 // resulting type.
3588 if (Quals.hasObjCLifetime()) {
3589 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3590 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003591 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003592 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003593 // A lifetime qualifier applied to a substituted template parameter
3594 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003595 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003596 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003597 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3598 QualType Replacement = SubstTypeParam->getReplacementType();
3599 Qualifiers Qs = Replacement.getQualifiers();
3600 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003601 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003602 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3603 Qs);
3604 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003605 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003606 Replacement);
3607 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003608 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3609 // 'auto' types behave the same way as template parameters.
3610 QualType Deduced = AutoTy->getDeducedType();
3611 Qualifiers Qs = Deduced.getQualifiers();
3612 Qs.removeObjCLifetime();
3613 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3614 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003615 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3616 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003617 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003618 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003619 // Otherwise, complain about the addition of a qualifier to an
3620 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003621 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003622 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003623 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003624
Douglas Gregore46db902011-06-17 22:11:49 +00003625 Quals.removeObjCLifetime();
3626 }
3627 }
3628 }
John McCallcb0f89a2010-06-05 06:41:15 +00003629 if (!Quals.empty()) {
3630 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003631 // BuildQualifiedType might not add qualifiers if they are invalid.
3632 if (Result.hasLocalQualifiers())
3633 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003634 // No location information to preserve.
3635 }
John McCall550e0c22009-10-21 00:40:46 +00003636
3637 return Result;
3638}
3639
Douglas Gregor14454802011-02-25 02:25:35 +00003640template<typename Derived>
3641TypeLoc
3642TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3643 QualType ObjectType,
3644 NamedDecl *UnqualLookup,
3645 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003646 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003647 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003649 TypeSourceInfo *TSI =
3650 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3651 if (TSI)
3652 return TSI->getTypeLoc();
3653 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003654}
3655
Douglas Gregor579c15f2011-03-02 18:32:08 +00003656template<typename Derived>
3657TypeSourceInfo *
3658TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3659 QualType ObjectType,
3660 NamedDecl *UnqualLookup,
3661 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003662 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003663 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003664
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003665 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3666 UnqualLookup, SS);
3667}
3668
3669template <typename Derived>
3670TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3671 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3672 CXXScopeSpec &SS) {
3673 QualType T = TL.getType();
3674 assert(!getDerived().AlreadyTransformed(T));
3675
Douglas Gregor579c15f2011-03-02 18:32:08 +00003676 TypeLocBuilder TLB;
3677 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003678
Douglas Gregor579c15f2011-03-02 18:32:08 +00003679 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003680 TemplateSpecializationTypeLoc SpecTL =
3681 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003682
Douglas Gregor579c15f2011-03-02 18:32:08 +00003683 TemplateName Template
3684 = getDerived().TransformTemplateName(SS,
3685 SpecTL.getTypePtr()->getTemplateName(),
3686 SpecTL.getTemplateNameLoc(),
3687 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003688 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003689 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003690
3691 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003692 Template);
3693 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003694 DependentTemplateSpecializationTypeLoc SpecTL =
3695 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003696
Douglas Gregor579c15f2011-03-02 18:32:08 +00003697 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003698 = getDerived().RebuildTemplateName(SS,
3699 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003700 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003701 ObjectType, UnqualLookup);
3702 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003703 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003704
3705 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003706 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003707 Template,
3708 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003709 } else {
3710 // Nothing special needs to be done for these.
3711 Result = getDerived().TransformType(TLB, TL);
3712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
3714 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003715 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003716
Douglas Gregor579c15f2011-03-02 18:32:08 +00003717 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3718}
3719
John McCall550e0c22009-10-21 00:40:46 +00003720template <class TyLoc> static inline
3721QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3722 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3723 NewT.setNameLoc(T.getNameLoc());
3724 return T.getType();
3725}
3726
John McCall550e0c22009-10-21 00:40:46 +00003727template<typename Derived>
3728QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003729 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003730 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3731 NewT.setBuiltinLoc(T.getBuiltinLoc());
3732 if (T.needsExtraLocalData())
3733 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3734 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003735}
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregord6ff3322009-08-04 16:50:30 +00003737template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003738QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003739 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003740 // FIXME: recurse?
3741 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003742}
Mike Stump11289f42009-09-09 15:08:12 +00003743
Reid Kleckner0503a872013-12-05 01:23:43 +00003744template <typename Derived>
3745QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3746 AdjustedTypeLoc TL) {
3747 // Adjustments applied during transformation are handled elsewhere.
3748 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3749}
3750
Douglas Gregord6ff3322009-08-04 16:50:30 +00003751template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003752QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3753 DecayedTypeLoc TL) {
3754 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3755 if (OriginalType.isNull())
3756 return QualType();
3757
3758 QualType Result = TL.getType();
3759 if (getDerived().AlwaysRebuild() ||
3760 OriginalType != TL.getOriginalLoc().getType())
3761 Result = SemaRef.Context.getDecayedType(OriginalType);
3762 TLB.push<DecayedTypeLoc>(Result);
3763 // Nothing to set for DecayedTypeLoc.
3764 return Result;
3765}
3766
3767template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003768QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003769 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003770 QualType PointeeType
3771 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003772 if (PointeeType.isNull())
3773 return QualType();
3774
3775 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003776 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003777 // A dependent pointer type 'T *' has is being transformed such
3778 // that an Objective-C class type is being replaced for 'T'. The
3779 // resulting pointer type is an ObjCObjectPointerType, not a
3780 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003781 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
John McCall8b07ec22010-05-15 11:32:37 +00003783 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3784 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003785 return Result;
3786 }
John McCall31f82722010-11-12 08:19:04 +00003787
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003788 if (getDerived().AlwaysRebuild() ||
3789 PointeeType != TL.getPointeeLoc().getType()) {
3790 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3791 if (Result.isNull())
3792 return QualType();
3793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
John McCall31168b02011-06-15 23:02:42 +00003795 // Objective-C ARC can add lifetime qualifiers to the type that we're
3796 // pointing to.
3797 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003799 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3800 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003801 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003802}
Mike Stump11289f42009-09-09 15:08:12 +00003803
3804template<typename Derived>
3805QualType
John McCall550e0c22009-10-21 00:40:46 +00003806TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003807 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003808 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003809 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3810 if (PointeeType.isNull())
3811 return QualType();
3812
3813 QualType Result = TL.getType();
3814 if (getDerived().AlwaysRebuild() ||
3815 PointeeType != TL.getPointeeLoc().getType()) {
3816 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003817 TL.getSigilLoc());
3818 if (Result.isNull())
3819 return QualType();
3820 }
3821
Douglas Gregor049211a2010-04-22 16:50:51 +00003822 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003823 NewT.setSigilLoc(TL.getSigilLoc());
3824 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003825}
3826
John McCall70dd5f62009-10-30 00:06:24 +00003827/// Transforms a reference type. Note that somewhat paradoxically we
3828/// don't care whether the type itself is an l-value type or an r-value
3829/// type; we only care if the type was *written* as an l-value type
3830/// or an r-value type.
3831template<typename Derived>
3832QualType
3833TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003834 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003835 const ReferenceType *T = TL.getTypePtr();
3836
3837 // Note that this works with the pointee-as-written.
3838 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3839 if (PointeeType.isNull())
3840 return QualType();
3841
3842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() ||
3844 PointeeType != T->getPointeeTypeAsWritten()) {
3845 Result = getDerived().RebuildReferenceType(PointeeType,
3846 T->isSpelledAsLValue(),
3847 TL.getSigilLoc());
3848 if (Result.isNull())
3849 return QualType();
3850 }
3851
John McCall31168b02011-06-15 23:02:42 +00003852 // Objective-C ARC can add lifetime qualifiers to the type that we're
3853 // referring to.
3854 TLB.TypeWasModifiedSafely(
3855 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3856
John McCall70dd5f62009-10-30 00:06:24 +00003857 // r-value references can be rebuilt as l-value references.
3858 ReferenceTypeLoc NewTL;
3859 if (isa<LValueReferenceType>(Result))
3860 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3861 else
3862 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3863 NewTL.setSigilLoc(TL.getSigilLoc());
3864
3865 return Result;
3866}
3867
Mike Stump11289f42009-09-09 15:08:12 +00003868template<typename Derived>
3869QualType
John McCall550e0c22009-10-21 00:40:46 +00003870TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003871 LValueReferenceTypeLoc TL) {
3872 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003873}
3874
Mike Stump11289f42009-09-09 15:08:12 +00003875template<typename Derived>
3876QualType
John McCall550e0c22009-10-21 00:40:46 +00003877TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003878 RValueReferenceTypeLoc TL) {
3879 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003883QualType
John McCall550e0c22009-10-21 00:40:46 +00003884TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003885 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003886 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887 if (PointeeType.isNull())
3888 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003889
Abramo Bagnara509357842011-03-05 14:42:21 +00003890 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003891 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003892 if (OldClsTInfo) {
3893 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3894 if (!NewClsTInfo)
3895 return QualType();
3896 }
3897
3898 const MemberPointerType *T = TL.getTypePtr();
3899 QualType OldClsType = QualType(T->getClass(), 0);
3900 QualType NewClsType;
3901 if (NewClsTInfo)
3902 NewClsType = NewClsTInfo->getType();
3903 else {
3904 NewClsType = getDerived().TransformType(OldClsType);
3905 if (NewClsType.isNull())
3906 return QualType();
3907 }
Mike Stump11289f42009-09-09 15:08:12 +00003908
John McCall550e0c22009-10-21 00:40:46 +00003909 QualType Result = TL.getType();
3910 if (getDerived().AlwaysRebuild() ||
3911 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003912 NewClsType != OldClsType) {
3913 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003914 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003915 if (Result.isNull())
3916 return QualType();
3917 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003918
Reid Kleckner0503a872013-12-05 01:23:43 +00003919 // If we had to adjust the pointee type when building a member pointer, make
3920 // sure to push TypeLoc info for it.
3921 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3922 if (MPT && PointeeType != MPT->getPointeeType()) {
3923 assert(isa<AdjustedType>(MPT->getPointeeType()));
3924 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3925 }
3926
John McCall550e0c22009-10-21 00:40:46 +00003927 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3928 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003929 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003930
3931 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003932}
3933
Mike Stump11289f42009-09-09 15:08:12 +00003934template<typename Derived>
3935QualType
John McCall550e0c22009-10-21 00:40:46 +00003936TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003937 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003938 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003939 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003940 if (ElementType.isNull())
3941 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003942
John McCall550e0c22009-10-21 00:40:46 +00003943 QualType Result = TL.getType();
3944 if (getDerived().AlwaysRebuild() ||
3945 ElementType != T->getElementType()) {
3946 Result = getDerived().RebuildConstantArrayType(ElementType,
3947 T->getSizeModifier(),
3948 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003949 T->getIndexTypeCVRQualifiers(),
3950 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003951 if (Result.isNull())
3952 return QualType();
3953 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003954
3955 // We might have either a ConstantArrayType or a VariableArrayType now:
3956 // a ConstantArrayType is allowed to have an element type which is a
3957 // VariableArrayType if the type is dependent. Fortunately, all array
3958 // types have the same location layout.
3959 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003960 NewTL.setLBracketLoc(TL.getLBracketLoc());
3961 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003962
John McCall550e0c22009-10-21 00:40:46 +00003963 Expr *Size = TL.getSizeExpr();
3964 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003965 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3966 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003967 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3968 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003969 }
3970 NewTL.setSizeExpr(Size);
3971
3972 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003973}
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregord6ff3322009-08-04 16:50:30 +00003975template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003976QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003977 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003978 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003979 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003980 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003981 if (ElementType.isNull())
3982 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003983
John McCall550e0c22009-10-21 00:40:46 +00003984 QualType Result = TL.getType();
3985 if (getDerived().AlwaysRebuild() ||
3986 ElementType != T->getElementType()) {
3987 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003989 T->getIndexTypeCVRQualifiers(),
3990 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003991 if (Result.isNull())
3992 return QualType();
3993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
John McCall550e0c22009-10-21 00:40:46 +00003995 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3996 NewTL.setLBracketLoc(TL.getLBracketLoc());
3997 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00003998 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00003999
4000 return Result;
4001}
4002
4003template<typename Derived>
4004QualType
4005TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004006 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004007 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004008 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4009 if (ElementType.isNull())
4010 return QualType();
4011
John McCalldadc5752010-08-24 06:29:42 +00004012 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004013 = getDerived().TransformExpr(T->getSizeExpr());
4014 if (SizeResult.isInvalid())
4015 return QualType();
4016
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004017 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004018
4019 QualType Result = TL.getType();
4020 if (getDerived().AlwaysRebuild() ||
4021 ElementType != T->getElementType() ||
4022 Size != T->getSizeExpr()) {
4023 Result = getDerived().RebuildVariableArrayType(ElementType,
4024 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004025 Size,
John McCall550e0c22009-10-21 00:40:46 +00004026 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004027 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004028 if (Result.isNull())
4029 return QualType();
4030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004031
Serge Pavlov774c6d02014-02-06 03:49:11 +00004032 // We might have constant size array now, but fortunately it has the same
4033 // location layout.
4034 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004035 NewTL.setLBracketLoc(TL.getLBracketLoc());
4036 NewTL.setRBracketLoc(TL.getRBracketLoc());
4037 NewTL.setSizeExpr(Size);
4038
4039 return Result;
4040}
4041
4042template<typename Derived>
4043QualType
4044TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004045 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004046 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004047 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4048 if (ElementType.isNull())
4049 return QualType();
4050
Richard Smith764d2fe2011-12-20 02:08:33 +00004051 // Array bounds are constant expressions.
4052 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4053 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004054
John McCall33ddac02011-01-19 10:06:00 +00004055 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4056 Expr *origSize = TL.getSizeExpr();
4057 if (!origSize) origSize = T->getSizeExpr();
4058
4059 ExprResult sizeResult
4060 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004061 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004062 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004063 return QualType();
4064
John McCall33ddac02011-01-19 10:06:00 +00004065 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004066
4067 QualType Result = TL.getType();
4068 if (getDerived().AlwaysRebuild() ||
4069 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004070 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004071 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4072 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004073 size,
John McCall550e0c22009-10-21 00:40:46 +00004074 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004075 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004076 if (Result.isNull())
4077 return QualType();
4078 }
John McCall550e0c22009-10-21 00:40:46 +00004079
4080 // We might have any sort of array type now, but fortunately they
4081 // all have the same location layout.
4082 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4083 NewTL.setLBracketLoc(TL.getLBracketLoc());
4084 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004085 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004086
4087 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
4090template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004091QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004092 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004094 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004095
4096 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097 QualType ElementType = getDerived().TransformType(T->getElementType());
4098 if (ElementType.isNull())
4099 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004100
Richard Smith764d2fe2011-12-20 02:08:33 +00004101 // Vector sizes are constant expressions.
4102 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4103 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004104
John McCalldadc5752010-08-24 06:29:42 +00004105 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004106 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107 if (Size.isInvalid())
4108 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004109
John McCall550e0c22009-10-21 00:40:46 +00004110 QualType Result = TL.getType();
4111 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004112 ElementType != T->getElementType() ||
4113 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004114 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004115 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004117 if (Result.isNull())
4118 return QualType();
4119 }
John McCall550e0c22009-10-21 00:40:46 +00004120
4121 // Result might be dependent or not.
4122 if (isa<DependentSizedExtVectorType>(Result)) {
4123 DependentSizedExtVectorTypeLoc NewTL
4124 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4125 NewTL.setNameLoc(TL.getNameLoc());
4126 } else {
4127 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4128 NewTL.setNameLoc(TL.getNameLoc());
4129 }
4130
4131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
4134template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004135QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004136 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004137 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138 QualType ElementType = getDerived().TransformType(T->getElementType());
4139 if (ElementType.isNull())
4140 return QualType();
4141
John McCall550e0c22009-10-21 00:40:46 +00004142 QualType Result = TL.getType();
4143 if (getDerived().AlwaysRebuild() ||
4144 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004145 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004146 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004147 if (Result.isNull())
4148 return QualType();
4149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
John McCall550e0c22009-10-21 00:40:46 +00004151 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4152 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004153
John McCall550e0c22009-10-21 00:40:46 +00004154 return Result;
4155}
4156
4157template<typename Derived>
4158QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004159 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004160 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004161 QualType ElementType = getDerived().TransformType(T->getElementType());
4162 if (ElementType.isNull())
4163 return QualType();
4164
4165 QualType Result = TL.getType();
4166 if (getDerived().AlwaysRebuild() ||
4167 ElementType != T->getElementType()) {
4168 Result = getDerived().RebuildExtVectorType(ElementType,
4169 T->getNumElements(),
4170 /*FIXME*/ SourceLocation());
4171 if (Result.isNull())
4172 return QualType();
4173 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004174
John McCall550e0c22009-10-21 00:40:46 +00004175 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4176 NewTL.setNameLoc(TL.getNameLoc());
4177
4178 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004179}
Mike Stump11289f42009-09-09 15:08:12 +00004180
David Blaikie05785d12013-02-20 22:23:23 +00004181template <typename Derived>
4182ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4183 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4184 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004185 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004186 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004187
Douglas Gregor715e4612011-01-14 22:40:04 +00004188 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004189 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004190 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004191 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004192 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004193
Douglas Gregor715e4612011-01-14 22:40:04 +00004194 TypeLocBuilder TLB;
4195 TypeLoc NewTL = OldDI->getTypeLoc();
4196 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004197
4198 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004199 OldExpansionTL.getPatternLoc());
4200 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004201 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004202
4203 Result = RebuildPackExpansionType(Result,
4204 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004205 OldExpansionTL.getEllipsisLoc(),
4206 NumExpansions);
4207 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004208 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004209
Douglas Gregor715e4612011-01-14 22:40:04 +00004210 PackExpansionTypeLoc NewExpansionTL
4211 = TLB.push<PackExpansionTypeLoc>(Result);
4212 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4213 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4214 } else
4215 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004216 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004217 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004218
John McCall8fb0d9d2011-05-01 22:35:37 +00004219 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004220 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004221
4222 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4223 OldParm->getDeclContext(),
4224 OldParm->getInnerLocStart(),
4225 OldParm->getLocation(),
4226 OldParm->getIdentifier(),
4227 NewDI->getType(),
4228 NewDI,
4229 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004230 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004231 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4232 OldParm->getFunctionScopeIndex() + indexAdjustment);
4233 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004234}
4235
4236template<typename Derived>
4237bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004238 TransformFunctionTypeParams(SourceLocation Loc,
4239 ParmVarDecl **Params, unsigned NumParams,
4240 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004241 SmallVectorImpl<QualType> &OutParamTypes,
4242 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004243 int indexAdjustment = 0;
4244
Douglas Gregordd472162011-01-07 00:20:55 +00004245 for (unsigned i = 0; i != NumParams; ++i) {
4246 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004247 assert(OldParm->getFunctionScopeIndex() == i);
4248
David Blaikie05785d12013-02-20 22:23:23 +00004249 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004250 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004251 if (OldParm->isParameterPack()) {
4252 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004253 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004254
Douglas Gregor5499af42011-01-05 23:12:31 +00004255 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004256 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004257 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004258 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4259 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004260 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4261
Douglas Gregor5499af42011-01-05 23:12:31 +00004262 // Determine whether we should expand the parameter packs.
4263 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004264 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004265 Optional<unsigned> OrigNumExpansions =
4266 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004267 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004268 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4269 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004270 Unexpanded,
4271 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004272 RetainExpansion,
4273 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004274 return true;
4275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004276
Douglas Gregor5499af42011-01-05 23:12:31 +00004277 if (ShouldExpand) {
4278 // Expand the function parameter pack into multiple, separate
4279 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004280 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004281 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004282 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004283 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004284 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004285 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004286 OrigNumExpansions,
4287 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004288 if (!NewParm)
4289 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004290
Douglas Gregordd472162011-01-07 00:20:55 +00004291 OutParamTypes.push_back(NewParm->getType());
4292 if (PVars)
4293 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004294 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004295
4296 // If we're supposed to retain a pack expansion, do so by temporarily
4297 // forgetting the partially-substituted parameter pack.
4298 if (RetainExpansion) {
4299 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004300 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004301 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004302 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004303 OrigNumExpansions,
4304 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004305 if (!NewParm)
4306 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004308 OutParamTypes.push_back(NewParm->getType());
4309 if (PVars)
4310 PVars->push_back(NewParm);
4311 }
4312
John McCall8fb0d9d2011-05-01 22:35:37 +00004313 // The next parameter should have the same adjustment as the
4314 // last thing we pushed, but we post-incremented indexAdjustment
4315 // on every push. Also, if we push nothing, the adjustment should
4316 // go down by one.
4317 indexAdjustment--;
4318
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 // We're done with the pack expansion.
4320 continue;
4321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004322
4323 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004324 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4326 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004327 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004328 NumExpansions,
4329 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004330 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004331 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004332 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004334
John McCall58f10c32010-03-11 09:03:00 +00004335 if (!NewParm)
4336 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004337
Douglas Gregordd472162011-01-07 00:20:55 +00004338 OutParamTypes.push_back(NewParm->getType());
4339 if (PVars)
4340 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004341 continue;
4342 }
John McCall58f10c32010-03-11 09:03:00 +00004343
4344 // Deal with the possibility that we don't have a parameter
4345 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004346 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004347 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004348 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004349 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004350 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004351 = dyn_cast<PackExpansionType>(OldType)) {
4352 // We have a function parameter pack that may need to be expanded.
4353 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004354 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004355 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004356
Douglas Gregor5499af42011-01-05 23:12:31 +00004357 // Determine whether we should expand the parameter packs.
4358 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004359 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004360 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004361 Unexpanded,
4362 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004363 RetainExpansion,
4364 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004365 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004367
Douglas Gregor5499af42011-01-05 23:12:31 +00004368 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004369 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004370 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004371 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004372 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4373 QualType NewType = getDerived().TransformType(Pattern);
4374 if (NewType.isNull())
4375 return true;
John McCall58f10c32010-03-11 09:03:00 +00004376
Douglas Gregordd472162011-01-07 00:20:55 +00004377 OutParamTypes.push_back(NewType);
4378 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004379 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004381
Douglas Gregor5499af42011-01-05 23:12:31 +00004382 // We're done with the pack expansion.
4383 continue;
4384 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004385
Douglas Gregor48d24112011-01-10 20:53:55 +00004386 // If we're supposed to retain a pack expansion, do so by temporarily
4387 // forgetting the partially-substituted parameter pack.
4388 if (RetainExpansion) {
4389 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4390 QualType NewType = getDerived().TransformType(Pattern);
4391 if (NewType.isNull())
4392 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004393
Douglas Gregor48d24112011-01-10 20:53:55 +00004394 OutParamTypes.push_back(NewType);
4395 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004396 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004397 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004398
Chad Rosier1dcde962012-08-08 18:46:20 +00004399 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004400 // expansion.
4401 OldType = Expansion->getPattern();
4402 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004403 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4404 NewType = getDerived().TransformType(OldType);
4405 } else {
4406 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004407 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004408
Douglas Gregor5499af42011-01-05 23:12:31 +00004409 if (NewType.isNull())
4410 return true;
4411
4412 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004413 NewType = getSema().Context.getPackExpansionType(NewType,
4414 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004415
Douglas Gregordd472162011-01-07 00:20:55 +00004416 OutParamTypes.push_back(NewType);
4417 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004418 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004419 }
4420
John McCall8fb0d9d2011-05-01 22:35:37 +00004421#ifndef NDEBUG
4422 if (PVars) {
4423 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4424 if (ParmVarDecl *parm = (*PVars)[i])
4425 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004426 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004427#endif
4428
4429 return false;
4430}
John McCall58f10c32010-03-11 09:03:00 +00004431
4432template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004433QualType
John McCall550e0c22009-10-21 00:40:46 +00004434TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004435 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004436 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004437}
4438
4439template<typename Derived>
4440QualType
4441TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4442 FunctionProtoTypeLoc TL,
4443 CXXRecordDecl *ThisContext,
4444 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004445 // Transform the parameters and return type.
4446 //
Richard Smithf623c962012-04-17 00:58:00 +00004447 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004448 // When the function has a trailing return type, we instantiate the
4449 // parameters before the return type, since the return type can then refer
4450 // to the parameters themselves (via decltype, sizeof, etc.).
4451 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004452 SmallVector<QualType, 4> ParamTypes;
4453 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004454 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004455
Douglas Gregor7fb25412010-10-01 18:44:50 +00004456 QualType ResultType;
4457
Richard Smith1226c602012-08-14 22:51:13 +00004458 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004459 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004460 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004461 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004462 return QualType();
4463
Douglas Gregor3024f072012-04-16 07:05:22 +00004464 {
4465 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004466 // If a declaration declares a member function or member function
4467 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004468 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004469 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004470 // declarator.
4471 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004472
Alp Toker42a16a62014-01-25 23:51:36 +00004473 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004474 if (ResultType.isNull())
4475 return QualType();
4476 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004477 }
4478 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004479 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004480 if (ResultType.isNull())
4481 return QualType();
4482
Alp Toker9cacbab2014-01-20 20:26:09 +00004483 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004484 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004485 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004486 return QualType();
4487 }
4488
Richard Smithf623c962012-04-17 00:58:00 +00004489 // FIXME: Need to transform the exception-specification too.
4490
John McCall550e0c22009-10-21 00:40:46 +00004491 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004492 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004493 T->getNumParams() != ParamTypes.size() ||
4494 !std::equal(T->param_type_begin(), T->param_type_end(),
4495 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004496 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004497 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004498 if (Result.isNull())
4499 return QualType();
4500 }
Mike Stump11289f42009-09-09 15:08:12 +00004501
John McCall550e0c22009-10-21 00:40:46 +00004502 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004503 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004504 NewTL.setLParenLoc(TL.getLParenLoc());
4505 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004506 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004507 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4508 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004509
4510 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004511}
Mike Stump11289f42009-09-09 15:08:12 +00004512
Douglas Gregord6ff3322009-08-04 16:50:30 +00004513template<typename Derived>
4514QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004515 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004516 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004517 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004518 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004519 if (ResultType.isNull())
4520 return QualType();
4521
4522 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004523 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004524 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4525
4526 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004527 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004528 NewTL.setLParenLoc(TL.getLParenLoc());
4529 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004530 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004531
4532 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533}
Mike Stump11289f42009-09-09 15:08:12 +00004534
John McCallb96ec562009-12-04 22:46:56 +00004535template<typename Derived> QualType
4536TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004537 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004538 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004539 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004540 if (!D)
4541 return QualType();
4542
4543 QualType Result = TL.getType();
4544 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4545 Result = getDerived().RebuildUnresolvedUsingType(D);
4546 if (Result.isNull())
4547 return QualType();
4548 }
4549
4550 // We might get an arbitrary type spec type back. We should at
4551 // least always get a type spec type, though.
4552 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4553 NewTL.setNameLoc(TL.getNameLoc());
4554
4555 return Result;
4556}
4557
Douglas Gregord6ff3322009-08-04 16:50:30 +00004558template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004559QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004560 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004561 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004562 TypedefNameDecl *Typedef
4563 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4564 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004565 if (!Typedef)
4566 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004567
John McCall550e0c22009-10-21 00:40:46 +00004568 QualType Result = TL.getType();
4569 if (getDerived().AlwaysRebuild() ||
4570 Typedef != T->getDecl()) {
4571 Result = getDerived().RebuildTypedefType(Typedef);
4572 if (Result.isNull())
4573 return QualType();
4574 }
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCall550e0c22009-10-21 00:40:46 +00004576 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4577 NewTL.setNameLoc(TL.getNameLoc());
4578
4579 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004580}
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregord6ff3322009-08-04 16:50:30 +00004582template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004583QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004584 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004585 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004586 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4587 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCalldadc5752010-08-24 06:29:42 +00004589 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 if (E.isInvalid())
4591 return QualType();
4592
Eli Friedmane4f22df2012-02-29 04:03:55 +00004593 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4594 if (E.isInvalid())
4595 return QualType();
4596
John McCall550e0c22009-10-21 00:40:46 +00004597 QualType Result = TL.getType();
4598 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004599 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004600 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004601 if (Result.isNull())
4602 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004603 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004604 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004605
John McCall550e0c22009-10-21 00:40:46 +00004606 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004607 NewTL.setTypeofLoc(TL.getTypeofLoc());
4608 NewTL.setLParenLoc(TL.getLParenLoc());
4609 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004610
4611 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612}
Mike Stump11289f42009-09-09 15:08:12 +00004613
4614template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004615QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004616 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004617 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4618 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4619 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004620 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004621
John McCall550e0c22009-10-21 00:40:46 +00004622 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004623 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4624 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004625 if (Result.isNull())
4626 return QualType();
4627 }
Mike Stump11289f42009-09-09 15:08:12 +00004628
John McCall550e0c22009-10-21 00:40:46 +00004629 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004630 NewTL.setTypeofLoc(TL.getTypeofLoc());
4631 NewTL.setLParenLoc(TL.getLParenLoc());
4632 NewTL.setRParenLoc(TL.getRParenLoc());
4633 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004634
4635 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004636}
Mike Stump11289f42009-09-09 15:08:12 +00004637
4638template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004639QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004640 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004641 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004642
Douglas Gregore922c772009-08-04 22:27:00 +00004643 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4645 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004646
John McCalldadc5752010-08-24 06:29:42 +00004647 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004648 if (E.isInvalid())
4649 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004650
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004651 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004652 if (E.isInvalid())
4653 return QualType();
4654
John McCall550e0c22009-10-21 00:40:46 +00004655 QualType Result = TL.getType();
4656 if (getDerived().AlwaysRebuild() ||
4657 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004658 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004659 if (Result.isNull())
4660 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004661 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004662 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004663
John McCall550e0c22009-10-21 00:40:46 +00004664 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4665 NewTL.setNameLoc(TL.getNameLoc());
4666
4667 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004668}
4669
4670template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004671QualType TreeTransform<Derived>::TransformUnaryTransformType(
4672 TypeLocBuilder &TLB,
4673 UnaryTransformTypeLoc TL) {
4674 QualType Result = TL.getType();
4675 if (Result->isDependentType()) {
4676 const UnaryTransformType *T = TL.getTypePtr();
4677 QualType NewBase =
4678 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4679 Result = getDerived().RebuildUnaryTransformType(NewBase,
4680 T->getUTTKind(),
4681 TL.getKWLoc());
4682 if (Result.isNull())
4683 return QualType();
4684 }
4685
4686 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4687 NewTL.setKWLoc(TL.getKWLoc());
4688 NewTL.setParensRange(TL.getParensRange());
4689 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4690 return Result;
4691}
4692
4693template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004694QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4695 AutoTypeLoc TL) {
4696 const AutoType *T = TL.getTypePtr();
4697 QualType OldDeduced = T->getDeducedType();
4698 QualType NewDeduced;
4699 if (!OldDeduced.isNull()) {
4700 NewDeduced = getDerived().TransformType(OldDeduced);
4701 if (NewDeduced.isNull())
4702 return QualType();
4703 }
4704
4705 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004706 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4707 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004708 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004709 if (Result.isNull())
4710 return QualType();
4711 }
4712
4713 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4714 NewTL.setNameLoc(TL.getNameLoc());
4715
4716 return Result;
4717}
4718
4719template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004720QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004721 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004722 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004723 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004724 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4725 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004726 if (!Record)
4727 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004728
John McCall550e0c22009-10-21 00:40:46 +00004729 QualType Result = TL.getType();
4730 if (getDerived().AlwaysRebuild() ||
4731 Record != T->getDecl()) {
4732 Result = getDerived().RebuildRecordType(Record);
4733 if (Result.isNull())
4734 return QualType();
4735 }
Mike Stump11289f42009-09-09 15:08:12 +00004736
John McCall550e0c22009-10-21 00:40:46 +00004737 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4738 NewTL.setNameLoc(TL.getNameLoc());
4739
4740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741}
Mike Stump11289f42009-09-09 15:08:12 +00004742
4743template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004744QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004745 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004746 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004747 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004748 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4749 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004750 if (!Enum)
4751 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004752
John McCall550e0c22009-10-21 00:40:46 +00004753 QualType Result = TL.getType();
4754 if (getDerived().AlwaysRebuild() ||
4755 Enum != T->getDecl()) {
4756 Result = getDerived().RebuildEnumType(Enum);
4757 if (Result.isNull())
4758 return QualType();
4759 }
Mike Stump11289f42009-09-09 15:08:12 +00004760
John McCall550e0c22009-10-21 00:40:46 +00004761 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4762 NewTL.setNameLoc(TL.getNameLoc());
4763
4764 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004765}
John McCallfcc33b02009-09-05 00:15:47 +00004766
John McCalle78aac42010-03-10 03:28:59 +00004767template<typename Derived>
4768QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4769 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004770 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004771 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4772 TL.getTypePtr()->getDecl());
4773 if (!D) return QualType();
4774
4775 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4776 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4777 return T;
4778}
4779
Douglas Gregord6ff3322009-08-04 16:50:30 +00004780template<typename Derived>
4781QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004782 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004783 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004784 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004785}
4786
Mike Stump11289f42009-09-09 15:08:12 +00004787template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004788QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004789 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004790 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004791 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004792
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004793 // Substitute into the replacement type, which itself might involve something
4794 // that needs to be transformed. This only tends to occur with default
4795 // template arguments of template template parameters.
4796 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4797 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4798 if (Replacement.isNull())
4799 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004800
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004801 // Always canonicalize the replacement type.
4802 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4803 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004804 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004805 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004806
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004807 // Propagate type-source information.
4808 SubstTemplateTypeParmTypeLoc NewTL
4809 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4810 NewTL.setNameLoc(TL.getNameLoc());
4811 return Result;
4812
John McCallcebee162009-10-18 09:09:24 +00004813}
4814
4815template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004816QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4817 TypeLocBuilder &TLB,
4818 SubstTemplateTypeParmPackTypeLoc TL) {
4819 return TransformTypeSpecType(TLB, TL);
4820}
4821
4822template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004823QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004824 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004825 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004826 const TemplateSpecializationType *T = TL.getTypePtr();
4827
Douglas Gregordf846d12011-03-02 18:46:51 +00004828 // The nested-name-specifier never matters in a TemplateSpecializationType,
4829 // because we can't have a dependent nested-name-specifier anyway.
4830 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004831 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004832 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4833 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004834 if (Template.isNull())
4835 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004836
John McCall31f82722010-11-12 08:19:04 +00004837 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4838}
4839
Eli Friedman0dfb8892011-10-06 23:00:33 +00004840template<typename Derived>
4841QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4842 AtomicTypeLoc TL) {
4843 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4844 if (ValueType.isNull())
4845 return QualType();
4846
4847 QualType Result = TL.getType();
4848 if (getDerived().AlwaysRebuild() ||
4849 ValueType != TL.getValueLoc().getType()) {
4850 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4851 if (Result.isNull())
4852 return QualType();
4853 }
4854
4855 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4856 NewTL.setKWLoc(TL.getKWLoc());
4857 NewTL.setLParenLoc(TL.getLParenLoc());
4858 NewTL.setRParenLoc(TL.getRParenLoc());
4859
4860 return Result;
4861}
4862
Chad Rosier1dcde962012-08-08 18:46:20 +00004863 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004864 /// container that provides a \c getArgLoc() member function.
4865 ///
4866 /// This iterator is intended to be used with the iterator form of
4867 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4868 template<typename ArgLocContainer>
4869 class TemplateArgumentLocContainerIterator {
4870 ArgLocContainer *Container;
4871 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004872
Douglas Gregorfe921a72010-12-20 23:36:19 +00004873 public:
4874 typedef TemplateArgumentLoc value_type;
4875 typedef TemplateArgumentLoc reference;
4876 typedef int difference_type;
4877 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004878
Douglas Gregorfe921a72010-12-20 23:36:19 +00004879 class pointer {
4880 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004881
Douglas Gregorfe921a72010-12-20 23:36:19 +00004882 public:
4883 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004884
Douglas Gregorfe921a72010-12-20 23:36:19 +00004885 const TemplateArgumentLoc *operator->() const {
4886 return &Arg;
4887 }
4888 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004889
4890
Douglas Gregorfe921a72010-12-20 23:36:19 +00004891 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004892
Douglas Gregorfe921a72010-12-20 23:36:19 +00004893 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4894 unsigned Index)
4895 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004896
Douglas Gregorfe921a72010-12-20 23:36:19 +00004897 TemplateArgumentLocContainerIterator &operator++() {
4898 ++Index;
4899 return *this;
4900 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004901
Douglas Gregorfe921a72010-12-20 23:36:19 +00004902 TemplateArgumentLocContainerIterator operator++(int) {
4903 TemplateArgumentLocContainerIterator Old(*this);
4904 ++(*this);
4905 return Old;
4906 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004907
Douglas Gregorfe921a72010-12-20 23:36:19 +00004908 TemplateArgumentLoc operator*() const {
4909 return Container->getArgLoc(Index);
4910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004911
Douglas Gregorfe921a72010-12-20 23:36:19 +00004912 pointer operator->() const {
4913 return pointer(Container->getArgLoc(Index));
4914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004915
Douglas Gregorfe921a72010-12-20 23:36:19 +00004916 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004917 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004918 return X.Container == Y.Container && X.Index == Y.Index;
4919 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004920
Douglas Gregorfe921a72010-12-20 23:36:19 +00004921 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004922 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004923 return !(X == Y);
4924 }
4925 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004926
4927
John McCall31f82722010-11-12 08:19:04 +00004928template <typename Derived>
4929QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4930 TypeLocBuilder &TLB,
4931 TemplateSpecializationTypeLoc TL,
4932 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004933 TemplateArgumentListInfo NewTemplateArgs;
4934 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4935 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004936 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4937 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004938 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004939 ArgIterator(TL, TL.getNumArgs()),
4940 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004941 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004942
John McCall0ad16662009-10-29 08:12:44 +00004943 // FIXME: maybe don't rebuild if all the template arguments are the same.
4944
4945 QualType Result =
4946 getDerived().RebuildTemplateSpecializationType(Template,
4947 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004948 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004949
4950 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004951 // Specializations of template template parameters are represented as
4952 // TemplateSpecializationTypes, and substitution of type alias templates
4953 // within a dependent context can transform them into
4954 // DependentTemplateSpecializationTypes.
4955 if (isa<DependentTemplateSpecializationType>(Result)) {
4956 DependentTemplateSpecializationTypeLoc NewTL
4957 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004958 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004959 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004960 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004961 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004962 NewTL.setLAngleLoc(TL.getLAngleLoc());
4963 NewTL.setRAngleLoc(TL.getRAngleLoc());
4964 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4965 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4966 return Result;
4967 }
4968
John McCall0ad16662009-10-29 08:12:44 +00004969 TemplateSpecializationTypeLoc NewTL
4970 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004971 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004972 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4973 NewTL.setLAngleLoc(TL.getLAngleLoc());
4974 NewTL.setRAngleLoc(TL.getRAngleLoc());
4975 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4976 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004977 }
Mike Stump11289f42009-09-09 15:08:12 +00004978
John McCall0ad16662009-10-29 08:12:44 +00004979 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980}
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregor5a064722011-02-28 17:23:35 +00004982template <typename Derived>
4983QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4984 TypeLocBuilder &TLB,
4985 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004986 TemplateName Template,
4987 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004988 TemplateArgumentListInfo NewTemplateArgs;
4989 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4990 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4991 typedef TemplateArgumentLocContainerIterator<
4992 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004993 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004994 ArgIterator(TL, TL.getNumArgs()),
4995 NewTemplateArgs))
4996 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004997
Douglas Gregor5a064722011-02-28 17:23:35 +00004998 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004999
Douglas Gregor5a064722011-02-28 17:23:35 +00005000 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5001 QualType Result
5002 = getSema().Context.getDependentTemplateSpecializationType(
5003 TL.getTypePtr()->getKeyword(),
5004 DTN->getQualifier(),
5005 DTN->getIdentifier(),
5006 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005007
Douglas Gregor5a064722011-02-28 17:23:35 +00005008 DependentTemplateSpecializationTypeLoc NewTL
5009 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005010 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005011 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005012 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005013 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005014 NewTL.setLAngleLoc(TL.getLAngleLoc());
5015 NewTL.setRAngleLoc(TL.getRAngleLoc());
5016 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5017 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5018 return Result;
5019 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005020
5021 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005022 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005023 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005024 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005025
Douglas Gregor5a064722011-02-28 17:23:35 +00005026 if (!Result.isNull()) {
5027 /// FIXME: Wrap this in an elaborated-type-specifier?
5028 TemplateSpecializationTypeLoc NewTL
5029 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005030 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005031 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005032 NewTL.setLAngleLoc(TL.getLAngleLoc());
5033 NewTL.setRAngleLoc(TL.getRAngleLoc());
5034 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5035 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005037
Douglas Gregor5a064722011-02-28 17:23:35 +00005038 return Result;
5039}
5040
Mike Stump11289f42009-09-09 15:08:12 +00005041template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005042QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005043TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005044 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005045 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005046
Douglas Gregor844cb502011-03-01 18:12:44 +00005047 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005048 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005049 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005050 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005051 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5052 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005053 return QualType();
5054 }
Mike Stump11289f42009-09-09 15:08:12 +00005055
John McCall31f82722010-11-12 08:19:04 +00005056 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5057 if (NamedT.isNull())
5058 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005059
Richard Smith3f1b5d02011-05-05 21:57:07 +00005060 // C++0x [dcl.type.elab]p2:
5061 // If the identifier resolves to a typedef-name or the simple-template-id
5062 // resolves to an alias template specialization, the
5063 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005064 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5065 if (const TemplateSpecializationType *TST =
5066 NamedT->getAs<TemplateSpecializationType>()) {
5067 TemplateName Template = TST->getTemplateName();
5068 if (TypeAliasTemplateDecl *TAT =
5069 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5070 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5071 diag::err_tag_reference_non_tag) << 4;
5072 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5073 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005074 }
5075 }
5076
John McCall550e0c22009-10-21 00:40:46 +00005077 QualType Result = TL.getType();
5078 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005079 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005080 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005081 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005082 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005083 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005084 if (Result.isNull())
5085 return QualType();
5086 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005087
Abramo Bagnara6150c882010-05-11 21:36:43 +00005088 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005089 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005090 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005092}
Mike Stump11289f42009-09-09 15:08:12 +00005093
5094template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005095QualType TreeTransform<Derived>::TransformAttributedType(
5096 TypeLocBuilder &TLB,
5097 AttributedTypeLoc TL) {
5098 const AttributedType *oldType = TL.getTypePtr();
5099 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5100 if (modifiedType.isNull())
5101 return QualType();
5102
5103 QualType result = TL.getType();
5104
5105 // FIXME: dependent operand expressions?
5106 if (getDerived().AlwaysRebuild() ||
5107 modifiedType != oldType->getModifiedType()) {
5108 // TODO: this is really lame; we should really be rebuilding the
5109 // equivalent type from first principles.
5110 QualType equivalentType
5111 = getDerived().TransformType(oldType->getEquivalentType());
5112 if (equivalentType.isNull())
5113 return QualType();
5114 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5115 modifiedType,
5116 equivalentType);
5117 }
5118
5119 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5120 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5121 if (TL.hasAttrOperand())
5122 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5123 if (TL.hasAttrExprOperand())
5124 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5125 else if (TL.hasAttrEnumOperand())
5126 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5127
5128 return result;
5129}
5130
5131template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005132QualType
5133TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5134 ParenTypeLoc TL) {
5135 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5136 if (Inner.isNull())
5137 return QualType();
5138
5139 QualType Result = TL.getType();
5140 if (getDerived().AlwaysRebuild() ||
5141 Inner != TL.getInnerLoc().getType()) {
5142 Result = getDerived().RebuildParenType(Inner);
5143 if (Result.isNull())
5144 return QualType();
5145 }
5146
5147 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5148 NewTL.setLParenLoc(TL.getLParenLoc());
5149 NewTL.setRParenLoc(TL.getRParenLoc());
5150 return Result;
5151}
5152
5153template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005154QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005155 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005156 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005157
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005158 NestedNameSpecifierLoc QualifierLoc
5159 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5160 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005161 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005162
John McCallc392f372010-06-11 00:33:02 +00005163 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005164 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005165 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005166 QualifierLoc,
5167 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005168 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005169 if (Result.isNull())
5170 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005171
Abramo Bagnarad7548482010-05-19 21:37:53 +00005172 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5173 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005174 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5175
Abramo Bagnarad7548482010-05-19 21:37:53 +00005176 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005177 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005178 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005179 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005180 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005181 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005182 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005183 NewTL.setNameLoc(TL.getNameLoc());
5184 }
John McCall550e0c22009-10-21 00:40:46 +00005185 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregord6ff3322009-08-04 16:50:30 +00005188template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005189QualType TreeTransform<Derived>::
5190 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005191 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005192 NestedNameSpecifierLoc QualifierLoc;
5193 if (TL.getQualifierLoc()) {
5194 QualifierLoc
5195 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5196 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005197 return QualType();
5198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005199
John McCall31f82722010-11-12 08:19:04 +00005200 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005201 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005202}
5203
5204template<typename Derived>
5205QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005206TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5207 DependentTemplateSpecializationTypeLoc TL,
5208 NestedNameSpecifierLoc QualifierLoc) {
5209 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005210
Douglas Gregora7a795b2011-03-01 20:11:18 +00005211 TemplateArgumentListInfo NewTemplateArgs;
5212 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5213 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005214
Douglas Gregora7a795b2011-03-01 20:11:18 +00005215 typedef TemplateArgumentLocContainerIterator<
5216 DependentTemplateSpecializationTypeLoc> ArgIterator;
5217 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5218 ArgIterator(TL, TL.getNumArgs()),
5219 NewTemplateArgs))
5220 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005221
Douglas Gregora7a795b2011-03-01 20:11:18 +00005222 QualType Result
5223 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5224 QualifierLoc,
5225 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005226 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005227 NewTemplateArgs);
5228 if (Result.isNull())
5229 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005230
Douglas Gregora7a795b2011-03-01 20:11:18 +00005231 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5232 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005233
Douglas Gregora7a795b2011-03-01 20:11:18 +00005234 // Copy information relevant to the template specialization.
5235 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005236 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005237 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005238 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005239 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5240 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005241 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005242 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005243
Douglas Gregora7a795b2011-03-01 20:11:18 +00005244 // Copy information relevant to the elaborated type.
5245 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005246 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005247 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005248 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5249 DependentTemplateSpecializationTypeLoc SpecTL
5250 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005251 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005252 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005253 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005254 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005255 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5256 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005257 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005258 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005259 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005260 TemplateSpecializationTypeLoc SpecTL
5261 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005262 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005263 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005264 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5265 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005266 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005267 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005268 }
5269 return Result;
5270}
5271
5272template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005273QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5274 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005275 QualType Pattern
5276 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005277 if (Pattern.isNull())
5278 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005279
5280 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005281 if (getDerived().AlwaysRebuild() ||
5282 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005283 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005284 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005285 TL.getEllipsisLoc(),
5286 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005287 if (Result.isNull())
5288 return QualType();
5289 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005290
Douglas Gregor822d0302011-01-12 17:07:58 +00005291 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5292 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5293 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005294}
5295
5296template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005297QualType
5298TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005299 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005300 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005301 TLB.pushFullCopy(TL);
5302 return TL.getType();
5303}
5304
5305template<typename Derived>
5306QualType
5307TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005308 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005309 // ObjCObjectType is never dependent.
5310 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005311 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005312}
Mike Stump11289f42009-09-09 15:08:12 +00005313
5314template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005315QualType
5316TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005317 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005318 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005319 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005320 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005321}
5322
Douglas Gregord6ff3322009-08-04 16:50:30 +00005323//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005324// Statement transformation
5325//===----------------------------------------------------------------------===//
5326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005327StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005328TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005329 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005330}
5331
5332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005333StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005334TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5335 return getDerived().TransformCompoundStmt(S, false);
5336}
5337
5338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005339StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005340TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005342 Sema::CompoundScopeRAII CompoundScope(getSema());
5343
John McCall1ababa62010-08-27 19:56:05 +00005344 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005345 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005346 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005347 for (auto *B : S->body()) {
5348 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005349 if (Result.isInvalid()) {
5350 // Immediately fail if this was a DeclStmt, since it's very
5351 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005352 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005353 return StmtError();
5354
5355 // Otherwise, just keep processing substatements and fail later.
5356 SubStmtInvalid = true;
5357 continue;
5358 }
Mike Stump11289f42009-09-09 15:08:12 +00005359
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005360 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005361 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005362 }
Mike Stump11289f42009-09-09 15:08:12 +00005363
John McCall1ababa62010-08-27 19:56:05 +00005364 if (SubStmtInvalid)
5365 return StmtError();
5366
Douglas Gregorebe10102009-08-20 07:17:43 +00005367 if (!getDerived().AlwaysRebuild() &&
5368 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005369 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005370
5371 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005372 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005373 S->getRBracLoc(),
5374 IsStmtExpr);
5375}
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregorebe10102009-08-20 07:17:43 +00005377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005378StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005379TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005380 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005381 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005382 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5383 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005384
Eli Friedman06577382009-11-19 03:14:00 +00005385 // Transform the left-hand case value.
5386 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005387 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005388 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005390
Eli Friedman06577382009-11-19 03:14:00 +00005391 // Transform the right-hand case value (for the GNU case-range extension).
5392 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005393 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005394 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005395 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005396 }
Mike Stump11289f42009-09-09 15:08:12 +00005397
Douglas Gregorebe10102009-08-20 07:17:43 +00005398 // Build the case statement.
5399 // Case statements are always rebuilt so that they will attached to their
5400 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005401 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005402 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005403 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005404 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005405 S->getColonLoc());
5406 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005407 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005408
Douglas Gregorebe10102009-08-20 07:17:43 +00005409 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005410 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005411 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregorebe10102009-08-20 07:17:43 +00005414 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005415 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005416}
5417
5418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005419StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005420TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005421 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005422 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005423 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005424 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregorebe10102009-08-20 07:17:43 +00005426 // Default statements are always rebuilt
5427 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005428 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005429}
Mike Stump11289f42009-09-09 15:08:12 +00005430
Douglas Gregorebe10102009-08-20 07:17:43 +00005431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005432StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005433TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005434 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005435 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005436 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005437
Chris Lattnercab02a62011-02-17 20:34:02 +00005438 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5439 S->getDecl());
5440 if (!LD)
5441 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005442
5443
Douglas Gregorebe10102009-08-20 07:17:43 +00005444 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005445 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005446 cast<LabelDecl>(LD), SourceLocation(),
5447 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005448}
Mike Stump11289f42009-09-09 15:08:12 +00005449
Douglas Gregorebe10102009-08-20 07:17:43 +00005450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005451StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005452TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5453 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5454 if (SubStmt.isInvalid())
5455 return StmtError();
5456
5457 // TODO: transform attributes
5458 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5459 return S;
5460
5461 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5462 S->getAttrs(),
5463 SubStmt.get());
5464}
5465
5466template<typename Derived>
5467StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005468TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005469 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005470 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005471 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005472 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005473 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005474 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005475 getDerived().TransformDefinition(
5476 S->getConditionVariable()->getLocation(),
5477 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005478 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005479 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005480 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005481 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005482
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005483 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005484 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005485
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005486 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005487 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005488 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005489 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005490 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005492
John McCallb268a282010-08-23 23:25:46 +00005493 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005494 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005496
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005497 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005498 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005500
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005502 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 if (Then.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 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005507 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005508 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005510
Douglas Gregorebe10102009-08-20 07:17:43 +00005511 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005512 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005513 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005514 Then.get() == S->getThen() &&
5515 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005516 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005518 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005519 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005520 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005521}
5522
5523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005524StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005525TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005527 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005528 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005529 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005530 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005531 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005532 getDerived().TransformDefinition(
5533 S->getConditionVariable()->getLocation(),
5534 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005535 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005537 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005538 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005539
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005540 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005542 }
Mike Stump11289f42009-09-09 15:08:12 +00005543
Douglas Gregorebe10102009-08-20 07:17:43 +00005544 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005545 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005546 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005547 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005548 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregorebe10102009-08-20 07:17:43 +00005551 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005552 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005553 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005555
Douglas Gregorebe10102009-08-20 07:17:43 +00005556 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005557 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5558 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregorebe10102009-08-20 07:17:43 +00005561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005562StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005563TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005565 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005566 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005567 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005568 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005569 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005570 getDerived().TransformDefinition(
5571 S->getConditionVariable()->getLocation(),
5572 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005573 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005575 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005576 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005577
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005578 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005580
5581 if (S->getCond()) {
5582 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005583 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5584 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005585 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005586 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005588 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005589 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005590 }
Mike Stump11289f42009-09-09 15:08:12 +00005591
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005592 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005593 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005595
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005597 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005599 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005602 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005603 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005605 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005606
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005607 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005608 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005609}
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregorebe10102009-08-20 07:17:43 +00005611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005612StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005613TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005615 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005616 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005617 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005619 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005620 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005621 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005622 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 if (!getDerived().AlwaysRebuild() &&
5625 Cond.get() == S->getCond() &&
5626 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005627 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005628
John McCallb268a282010-08-23 23:25:46 +00005629 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5630 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005631 S->getRParenLoc());
5632}
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregorebe10102009-08-20 07:17:43 +00005634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005635StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005636TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005637 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005638 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005639 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005640 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregorebe10102009-08-20 07:17:43 +00005642 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005643 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005644 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005645 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005646 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005647 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005648 getDerived().TransformDefinition(
5649 S->getConditionVariable()->getLocation(),
5650 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005651 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005652 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005653 } else {
5654 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005655
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005656 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005658
5659 if (S->getCond()) {
5660 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005661 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5662 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005663 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005664 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005665 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005666
John McCallb268a282010-08-23 23:25:46 +00005667 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005668 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005669 }
Mike Stump11289f42009-09-09 15:08:12 +00005670
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005671 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005672 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005673 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005674
Douglas Gregorebe10102009-08-20 07:17:43 +00005675 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005676 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005677 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005678 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005679
Richard Smith945f8d32013-01-14 22:39:08 +00005680 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005681 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005685 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 if (!getDerived().AlwaysRebuild() &&
5690 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005691 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 Inc.get() == S->getInc() &&
5693 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005694 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005695
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005697 Init.get(), FullCond, ConditionVar,
5698 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005699}
5700
5701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005702StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005703TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005704 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5705 S->getLabel());
5706 if (!LD)
5707 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005708
Douglas Gregorebe10102009-08-20 07:17:43 +00005709 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005710 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005711 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005712}
5713
5714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005715StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005716TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005717 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005718 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005719 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005720 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregorebe10102009-08-20 07:17:43 +00005722 if (!getDerived().AlwaysRebuild() &&
5723 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005724 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005725
5726 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005727 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005728}
5729
5730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005732TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005733 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005734}
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregorebe10102009-08-20 07:17:43 +00005736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005737StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005738TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005739 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005740}
Mike Stump11289f42009-09-09 15:08:12 +00005741
Douglas Gregorebe10102009-08-20 07:17:43 +00005742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005743StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005744TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005745 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005746 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005748
Mike Stump11289f42009-09-09 15:08:12 +00005749 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005750 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005751 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005752}
Mike Stump11289f42009-09-09 15:08:12 +00005753
Douglas Gregorebe10102009-08-20 07:17:43 +00005754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005755StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005756TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005758 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005759 for (auto *D : S->decls()) {
5760 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005761 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005762 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005763
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005764 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005765 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005766
Douglas Gregorebe10102009-08-20 07:17:43 +00005767 Decls.push_back(Transformed);
5768 }
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregorebe10102009-08-20 07:17:43 +00005770 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005771 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005772
Rafael Espindolaab417692013-07-09 12:05:01 +00005773 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005774}
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregorebe10102009-08-20 07:17:43 +00005776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005777StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005778TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005779
Benjamin Kramerf0623432012-08-23 22:51:59 +00005780 SmallVector<Expr*, 8> Constraints;
5781 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005782 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005783
John McCalldadc5752010-08-24 06:29:42 +00005784 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005785 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005786
5787 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005788
Anders Carlssonaaeef072010-01-24 05:50:09 +00005789 // Go through the outputs.
5790 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005791 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005792
Anders Carlssonaaeef072010-01-24 05:50:09 +00005793 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005794 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Anders Carlssonaaeef072010-01-24 05:50:09 +00005796 // Transform the output expr.
5797 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005798 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005799 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005800 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005801
Anders Carlssonaaeef072010-01-24 05:50:09 +00005802 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005803
John McCallb268a282010-08-23 23:25:46 +00005804 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005806
Anders Carlssonaaeef072010-01-24 05:50:09 +00005807 // Go through the inputs.
5808 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005809 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005810
Anders Carlssonaaeef072010-01-24 05:50:09 +00005811 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005812 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005813
Anders Carlssonaaeef072010-01-24 05:50:09 +00005814 // Transform the input expr.
5815 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005816 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005817 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005818 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
Anders Carlssonaaeef072010-01-24 05:50:09 +00005820 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005821
John McCallb268a282010-08-23 23:25:46 +00005822 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005823 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005824
Anders Carlssonaaeef072010-01-24 05:50:09 +00005825 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005826 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005827
5828 // Go through the clobbers.
5829 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005830 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005831
5832 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005833 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005834 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5835 S->isVolatile(), S->getNumOutputs(),
5836 S->getNumInputs(), Names.data(),
5837 Constraints, Exprs, AsmString.get(),
5838 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005839}
5840
Chad Rosier32503022012-06-11 20:47:18 +00005841template<typename Derived>
5842StmtResult
5843TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005844 ArrayRef<Token> AsmToks =
5845 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005846
John McCallf413f5e2013-05-03 00:10:13 +00005847 bool HadError = false, HadChange = false;
5848
5849 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5850 SmallVector<Expr*, 8> TransformedExprs;
5851 TransformedExprs.reserve(SrcExprs.size());
5852 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5853 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5854 if (!Result.isUsable()) {
5855 HadError = true;
5856 } else {
5857 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005858 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005859 }
5860 }
5861
5862 if (HadError) return StmtError();
5863 if (!HadChange && !getDerived().AlwaysRebuild())
5864 return Owned(S);
5865
Chad Rosierb6f46c12012-08-15 16:53:30 +00005866 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005867 AsmToks, S->getAsmString(),
5868 S->getNumOutputs(), S->getNumInputs(),
5869 S->getAllConstraints(), S->getClobbers(),
5870 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005871}
Douglas Gregorebe10102009-08-20 07:17:43 +00005872
5873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005874StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005875TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005876 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005877 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005878 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005879 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
Douglas Gregor96c79492010-04-23 22:50:49 +00005881 // Transform the @catch statements (if present).
5882 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005883 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005884 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005885 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005886 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005887 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005888 if (Catch.get() != S->getCatchStmt(I))
5889 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005890 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Douglas Gregor306de2f2010-04-22 23:59:56 +00005893 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005894 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005895 if (S->getFinallyStmt()) {
5896 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5897 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005899 }
5900
5901 // If nothing changed, just retain this statement.
5902 if (!getDerived().AlwaysRebuild() &&
5903 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005904 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005905 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005906 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005907
Douglas Gregor306de2f2010-04-22 23:59:56 +00005908 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005909 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005910 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005911}
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregorebe10102009-08-20 07:17:43 +00005913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005914StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005915TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005916 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005917 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005918 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005919 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005920 if (FromVar->getTypeSourceInfo()) {
5921 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5922 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005923 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005924 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005925
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005926 QualType T;
5927 if (TSInfo)
5928 T = TSInfo->getType();
5929 else {
5930 T = getDerived().TransformType(FromVar->getType());
5931 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005932 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005933 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005934
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005935 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5936 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005939
John McCalldadc5752010-08-24 06:29:42 +00005940 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005941 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005942 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
5944 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005945 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005946 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005947}
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregorebe10102009-08-20 07:17:43 +00005949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005950StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005951TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005952 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005953 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005954 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005955 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005956
Douglas Gregor306de2f2010-04-22 23:59:56 +00005957 // If nothing changed, just retain this statement.
5958 if (!getDerived().AlwaysRebuild() &&
5959 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005960 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005961
5962 // Build a new statement.
5963 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005964 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005965}
Mike Stump11289f42009-09-09 15:08:12 +00005966
Douglas Gregorebe10102009-08-20 07:17:43 +00005967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005968StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005969TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005970 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005971 if (S->getThrowExpr()) {
5972 Operand = getDerived().TransformExpr(S->getThrowExpr());
5973 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005974 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005976
Douglas Gregor2900c162010-04-22 21:44:01 +00005977 if (!getDerived().AlwaysRebuild() &&
5978 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005979 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005980
John McCallb268a282010-08-23 23:25:46 +00005981 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005982}
Mike Stump11289f42009-09-09 15:08:12 +00005983
Douglas Gregorebe10102009-08-20 07:17:43 +00005984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005985StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005986TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005987 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005988 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005989 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005990 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005992 Object =
5993 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5994 Object.get());
5995 if (Object.isInvalid())
5996 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005997
Douglas Gregor6148de72010-04-22 22:01:21 +00005998 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005999 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006000 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006002
Douglas Gregor6148de72010-04-22 22:01:21 +00006003 // If nothing change, just retain the current statement.
6004 if (!getDerived().AlwaysRebuild() &&
6005 Object.get() == S->getSynchExpr() &&
6006 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006007 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006008
6009 // Build a new statement.
6010 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006011 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006012}
6013
6014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006015StmtResult
John McCall31168b02011-06-15 23:02:42 +00006016TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6017 ObjCAutoreleasePoolStmt *S) {
6018 // Transform the body.
6019 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6020 if (Body.isInvalid())
6021 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006022
John McCall31168b02011-06-15 23:02:42 +00006023 // If nothing changed, just retain this statement.
6024 if (!getDerived().AlwaysRebuild() &&
6025 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006026 return S;
John McCall31168b02011-06-15 23:02:42 +00006027
6028 // Build a new statement.
6029 return getDerived().RebuildObjCAutoreleasePoolStmt(
6030 S->getAtLoc(), Body.get());
6031}
6032
6033template<typename Derived>
6034StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006035TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006036 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006037 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006038 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006039 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006041
Douglas Gregorf68a5082010-04-22 23:10:45 +00006042 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006043 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006044 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006045 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006046
Douglas Gregorf68a5082010-04-22 23:10:45 +00006047 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006048 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006049 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006050 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006051
Douglas Gregorf68a5082010-04-22 23:10:45 +00006052 // If nothing changed, just retain this statement.
6053 if (!getDerived().AlwaysRebuild() &&
6054 Element.get() == S->getElement() &&
6055 Collection.get() == S->getCollection() &&
6056 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006057 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006058
Douglas Gregorf68a5082010-04-22 23:10:45 +00006059 // Build a new statement.
6060 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006061 Element.get(),
6062 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006063 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006064 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006065}
6066
David Majnemer5f7efef2013-10-15 09:50:08 +00006067template <typename Derived>
6068StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006069 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006070 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006071 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6072 TypeSourceInfo *T =
6073 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006074 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006075 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006076
David Majnemer5f7efef2013-10-15 09:50:08 +00006077 Var = getDerived().RebuildExceptionDecl(
6078 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6079 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006080 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006081 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 }
Mike Stump11289f42009-09-09 15:08:12 +00006083
Douglas Gregorebe10102009-08-20 07:17:43 +00006084 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006085 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006086 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006087 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006088
David Majnemer5f7efef2013-10-15 09:50:08 +00006089 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006091 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006092
David Majnemer5f7efef2013-10-15 09:50:08 +00006093 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006094}
Mike Stump11289f42009-09-09 15:08:12 +00006095
David Majnemer5f7efef2013-10-15 09:50:08 +00006096template <typename Derived>
6097StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006099 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006102
Douglas Gregorebe10102009-08-20 07:17:43 +00006103 // Transform the handlers.
6104 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006105 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006106 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006107 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006108 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006109 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006110
Douglas Gregorebe10102009-08-20 07:17:43 +00006111 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006112 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006113 }
Mike Stump11289f42009-09-09 15:08:12 +00006114
David Majnemer5f7efef2013-10-15 09:50:08 +00006115 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006116 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006117 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006118
John McCallb268a282010-08-23 23:25:46 +00006119 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006120 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006121}
Mike Stump11289f42009-09-09 15:08:12 +00006122
Richard Smith02e85f32011-04-14 22:09:26 +00006123template<typename Derived>
6124StmtResult
6125TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6126 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6127 if (Range.isInvalid())
6128 return StmtError();
6129
6130 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6131 if (BeginEnd.isInvalid())
6132 return StmtError();
6133
6134 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6135 if (Cond.isInvalid())
6136 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006137 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006138 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006139 if (Cond.isInvalid())
6140 return StmtError();
6141 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006142 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006143
6144 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6145 if (Inc.isInvalid())
6146 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006147 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006148 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006149
6150 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6151 if (LoopVar.isInvalid())
6152 return StmtError();
6153
6154 StmtResult NewStmt = S;
6155 if (getDerived().AlwaysRebuild() ||
6156 Range.get() != S->getRangeStmt() ||
6157 BeginEnd.get() != S->getBeginEndStmt() ||
6158 Cond.get() != S->getCond() ||
6159 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006160 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006161 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6162 S->getColonLoc(), Range.get(),
6163 BeginEnd.get(), Cond.get(),
6164 Inc.get(), LoopVar.get(),
6165 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006166 if (NewStmt.isInvalid())
6167 return StmtError();
6168 }
Richard Smith02e85f32011-04-14 22:09:26 +00006169
6170 StmtResult Body = getDerived().TransformStmt(S->getBody());
6171 if (Body.isInvalid())
6172 return StmtError();
6173
6174 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6175 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006176 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006177 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6178 S->getColonLoc(), Range.get(),
6179 BeginEnd.get(), Cond.get(),
6180 Inc.get(), LoopVar.get(),
6181 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006182 if (NewStmt.isInvalid())
6183 return StmtError();
6184 }
Richard Smith02e85f32011-04-14 22:09:26 +00006185
6186 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006187 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006188
6189 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6190}
6191
John Wiegley1c0675e2011-04-28 01:08:34 +00006192template<typename Derived>
6193StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006194TreeTransform<Derived>::TransformMSDependentExistsStmt(
6195 MSDependentExistsStmt *S) {
6196 // Transform the nested-name-specifier, if any.
6197 NestedNameSpecifierLoc QualifierLoc;
6198 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006199 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006200 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6201 if (!QualifierLoc)
6202 return StmtError();
6203 }
6204
6205 // Transform the declaration name.
6206 DeclarationNameInfo NameInfo = S->getNameInfo();
6207 if (NameInfo.getName()) {
6208 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6209 if (!NameInfo.getName())
6210 return StmtError();
6211 }
6212
6213 // Check whether anything changed.
6214 if (!getDerived().AlwaysRebuild() &&
6215 QualifierLoc == S->getQualifierLoc() &&
6216 NameInfo.getName() == S->getNameInfo().getName())
6217 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006218
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006219 // Determine whether this name exists, if we can.
6220 CXXScopeSpec SS;
6221 SS.Adopt(QualifierLoc);
6222 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006223 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006224 case Sema::IER_Exists:
6225 if (S->isIfExists())
6226 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006227
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006228 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6229
6230 case Sema::IER_DoesNotExist:
6231 if (S->isIfNotExists())
6232 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006233
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006234 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006235
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006236 case Sema::IER_Dependent:
6237 Dependent = true;
6238 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006240 case Sema::IER_Error:
6241 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006242 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006243
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006244 // We need to continue with the instantiation, so do so now.
6245 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6246 if (SubStmt.isInvalid())
6247 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006248
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006249 // If we have resolved the name, just transform to the substatement.
6250 if (!Dependent)
6251 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006252
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006253 // The name is still dependent, so build a dependent expression again.
6254 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6255 S->isIfExists(),
6256 QualifierLoc,
6257 NameInfo,
6258 SubStmt.get());
6259}
6260
6261template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006262ExprResult
6263TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6264 NestedNameSpecifierLoc QualifierLoc;
6265 if (E->getQualifierLoc()) {
6266 QualifierLoc
6267 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6268 if (!QualifierLoc)
6269 return ExprError();
6270 }
6271
6272 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6273 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6274 if (!PD)
6275 return ExprError();
6276
6277 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6278 if (Base.isInvalid())
6279 return ExprError();
6280
6281 return new (SemaRef.getASTContext())
6282 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6283 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6284 QualifierLoc, E->getMemberLoc());
6285}
6286
David Majnemerfad8f482013-10-15 09:33:02 +00006287template <typename Derived>
6288StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006289 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006290 if (TryBlock.isInvalid())
6291 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006292
6293 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006294 if (Handler.isInvalid())
6295 return StmtError();
6296
David Majnemerfad8f482013-10-15 09:33:02 +00006297 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6298 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006299 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006300
David Majnemerfad8f482013-10-15 09:33:02 +00006301 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006302 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006303}
6304
David Majnemerfad8f482013-10-15 09:33:02 +00006305template <typename Derived>
6306StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006307 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006308 if (Block.isInvalid())
6309 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006310
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006311 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006312}
6313
David Majnemerfad8f482013-10-15 09:33:02 +00006314template <typename Derived>
6315StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006316 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006317 if (FilterExpr.isInvalid())
6318 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006319
David Majnemer7e755502013-10-15 09:30:14 +00006320 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006321 if (Block.isInvalid())
6322 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006323
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006324 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6325 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006326}
6327
David Majnemerfad8f482013-10-15 09:33:02 +00006328template <typename Derived>
6329StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6330 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006331 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6332 else
6333 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6334}
6335
Alexander Musman64d33f12014-06-04 07:53:32 +00006336//===----------------------------------------------------------------------===//
6337// OpenMP directive transformation
6338//===----------------------------------------------------------------------===//
6339template <typename Derived>
6340StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6341 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006342
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006343 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006344 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006345 ArrayRef<OMPClause *> Clauses = D->clauses();
6346 TClauses.reserve(Clauses.size());
6347 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6348 I != E; ++I) {
6349 if (*I) {
6350 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006351 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006352 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006353 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006354 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006355 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006356 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006357 }
6358 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006359 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006360 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006361 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006362 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006363 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006364 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006365 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006366 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006367
Alexander Musman64d33f12014-06-04 07:53:32 +00006368 return getDerived().RebuildOMPExecutableDirective(
6369 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6370 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006371}
6372
Alexander Musman64d33f12014-06-04 07:53:32 +00006373template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006374StmtResult
6375TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6376 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006377 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006378 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6379 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6380 return Res;
6381}
6382
Alexander Musman64d33f12014-06-04 07:53:32 +00006383template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006384StmtResult
6385TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6386 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006387 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006388 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6389 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006390 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006391}
6392
Alexander Musman64d33f12014-06-04 07:53:32 +00006393//===----------------------------------------------------------------------===//
6394// OpenMP clause transformation
6395//===----------------------------------------------------------------------===//
6396template <typename Derived>
6397OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006398 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6399 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006400 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006401 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006402 C->getLParenLoc(), C->getLocEnd());
6403}
6404
Alexander Musman64d33f12014-06-04 07:53:32 +00006405template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006406OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006407TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6408 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6409 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006410 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006411 return getDerived().RebuildOMPNumThreadsClause(
6412 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006413}
6414
Alexey Bataev62c87d22014-03-21 04:51:18 +00006415template <typename Derived>
6416OMPClause *
6417TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6418 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6419 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006420 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006421 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006422 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006423}
6424
Alexander Musman8bd31e62014-05-27 15:12:19 +00006425template <typename Derived>
6426OMPClause *
6427TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6428 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6429 if (E.isInvalid())
6430 return 0;
6431 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006432 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006433}
6434
Alexander Musman64d33f12014-06-04 07:53:32 +00006435template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006436OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006437TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006438 return getDerived().RebuildOMPDefaultClause(
6439 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6440 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006441}
6442
Alexander Musman64d33f12014-06-04 07:53:32 +00006443template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006444OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006445TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006446 return getDerived().RebuildOMPProcBindClause(
6447 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6448 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006449}
6450
Alexander Musman64d33f12014-06-04 07:53:32 +00006451template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006452OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006453TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006454 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006455 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006456 for (auto *VE : C->varlists()) {
6457 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006458 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006459 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006460 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006461 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006462 return getDerived().RebuildOMPPrivateClause(
6463 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006464}
6465
Alexander Musman64d33f12014-06-04 07:53:32 +00006466template <typename Derived>
6467OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6468 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006469 llvm::SmallVector<Expr *, 16> Vars;
6470 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006471 for (auto *VE : C->varlists()) {
6472 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006473 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006474 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006475 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006476 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006477 return getDerived().RebuildOMPFirstprivateClause(
6478 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006479}
6480
Alexander Musman64d33f12014-06-04 07:53:32 +00006481template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006482OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006483TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6484 llvm::SmallVector<Expr *, 16> Vars;
6485 Vars.reserve(C->varlist_size());
6486 for (auto *VE : C->varlists()) {
6487 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6488 if (EVar.isInvalid())
6489 return nullptr;
6490 Vars.push_back(EVar.get());
6491 }
6492 return getDerived().RebuildOMPLastprivateClause(
6493 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6494}
6495
6496template <typename Derived>
6497OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006498TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6499 llvm::SmallVector<Expr *, 16> Vars;
6500 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006501 for (auto *VE : C->varlists()) {
6502 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006503 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006504 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006505 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006506 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006507 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6508 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006509}
6510
Alexander Musman64d33f12014-06-04 07:53:32 +00006511template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006512OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006513TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6514 llvm::SmallVector<Expr *, 16> Vars;
6515 Vars.reserve(C->varlist_size());
6516 for (auto *VE : C->varlists()) {
6517 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6518 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006519 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006520 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006521 }
6522 ExprResult Step = getDerived().TransformExpr(C->getStep());
6523 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006524 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006525 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6526 C->getLParenLoc(),
6527 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006528}
6529
Alexander Musman64d33f12014-06-04 07:53:32 +00006530template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006531OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006532TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6533 llvm::SmallVector<Expr *, 16> Vars;
6534 Vars.reserve(C->varlist_size());
6535 for (auto *VE : C->varlists()) {
6536 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6537 if (EVar.isInvalid())
6538 return nullptr;
6539 Vars.push_back(EVar.get());
6540 }
6541 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6542 if (Alignment.isInvalid())
6543 return nullptr;
6544 return getDerived().RebuildOMPAlignedClause(
6545 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6546 C->getColonLoc(), C->getLocEnd());
6547}
6548
Alexander Musman64d33f12014-06-04 07:53:32 +00006549template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006550OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006551TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6552 llvm::SmallVector<Expr *, 16> Vars;
6553 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006554 for (auto *VE : C->varlists()) {
6555 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006556 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006557 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006558 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006559 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006560 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6561 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006562}
6563
Douglas Gregorebe10102009-08-20 07:17:43 +00006564//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006565// Expression transformation
6566//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006569TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006570 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006571}
Mike Stump11289f42009-09-09 15:08:12 +00006572
6573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006575TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006576 NestedNameSpecifierLoc QualifierLoc;
6577 if (E->getQualifierLoc()) {
6578 QualifierLoc
6579 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6580 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006582 }
John McCallce546572009-12-08 09:08:17 +00006583
6584 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006585 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6586 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006587 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006589
John McCall815039a2010-08-17 21:27:17 +00006590 DeclarationNameInfo NameInfo = E->getNameInfo();
6591 if (NameInfo.getName()) {
6592 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6593 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006594 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006595 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006596
6597 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006598 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006599 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006600 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006601 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006602
6603 // Mark it referenced in the new context regardless.
6604 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006605 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006606
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006607 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006608 }
John McCallce546572009-12-08 09:08:17 +00006609
Craig Topperc3ec1492014-05-26 06:22:03 +00006610 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006611 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006612 TemplateArgs = &TransArgs;
6613 TransArgs.setLAngleLoc(E->getLAngleLoc());
6614 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006615 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6616 E->getNumTemplateArgs(),
6617 TransArgs))
6618 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006619 }
6620
Chad Rosier1dcde962012-08-08 18:46:20 +00006621 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006622 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006623}
Mike Stump11289f42009-09-09 15:08:12 +00006624
Douglas Gregora16548e2009-08-11 05:31:07 +00006625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006627TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006628 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006629}
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregora16548e2009-08-11 05:31:07 +00006631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006632ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006633TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006634 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006635}
Mike Stump11289f42009-09-09 15:08:12 +00006636
Douglas Gregora16548e2009-08-11 05:31:07 +00006637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006639TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006640 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006641}
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregora16548e2009-08-11 05:31:07 +00006643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006645TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006646 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006651TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006652 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006653}
6654
6655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006656ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006657TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006658 if (FunctionDecl *FD = E->getDirectCallee())
6659 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006660 return SemaRef.MaybeBindToTemporary(E);
6661}
6662
6663template<typename Derived>
6664ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006665TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6666 ExprResult ControllingExpr =
6667 getDerived().TransformExpr(E->getControllingExpr());
6668 if (ControllingExpr.isInvalid())
6669 return ExprError();
6670
Chris Lattner01cf8db2011-07-20 06:58:45 +00006671 SmallVector<Expr *, 4> AssocExprs;
6672 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006673 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6674 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6675 if (TS) {
6676 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6677 if (!AssocType)
6678 return ExprError();
6679 AssocTypes.push_back(AssocType);
6680 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006681 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006682 }
6683
6684 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6685 if (AssocExpr.isInvalid())
6686 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006687 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006688 }
6689
6690 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6691 E->getDefaultLoc(),
6692 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006693 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006694 AssocTypes,
6695 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006696}
6697
6698template<typename Derived>
6699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006700TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006701 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006706 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006707
John McCallb268a282010-08-23 23:25:46 +00006708 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006709 E->getRParen());
6710}
6711
Richard Smithdb2630f2012-10-21 03:28:35 +00006712/// \brief The operand of a unary address-of operator has special rules: it's
6713/// allowed to refer to a non-static member of a class even if there's no 'this'
6714/// object available.
6715template<typename Derived>
6716ExprResult
6717TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6718 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00006719 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00006720 else
6721 return getDerived().TransformExpr(E);
6722}
6723
Mike Stump11289f42009-09-09 15:08:12 +00006724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006726TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006727 ExprResult SubExpr;
6728 if (E->getOpcode() == UO_AddrOf)
6729 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6730 else
6731 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregora16548e2009-08-11 05:31:07 +00006735 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006736 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006737
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6739 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006740 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006741}
Mike Stump11289f42009-09-09 15:08:12 +00006742
Douglas Gregora16548e2009-08-11 05:31:07 +00006743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006744ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006745TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6746 // Transform the type.
6747 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6748 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006749 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006750
Douglas Gregor882211c2010-04-28 22:16:22 +00006751 // Transform all of the components into components similar to what the
6752 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006753 // FIXME: It would be slightly more efficient in the non-dependent case to
6754 // just map FieldDecls, rather than requiring the rebuilder to look for
6755 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006756 // template code that we don't care.
6757 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006758 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006759 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006760 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006761 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6762 const Node &ON = E->getComponent(I);
6763 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006764 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006765 Comp.LocStart = ON.getSourceRange().getBegin();
6766 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006767 switch (ON.getKind()) {
6768 case Node::Array: {
6769 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006770 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006771 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006772 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006773
Douglas Gregor882211c2010-04-28 22:16:22 +00006774 ExprChanged = ExprChanged || Index.get() != FromIndex;
6775 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006776 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006777 break;
6778 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006779
Douglas Gregor882211c2010-04-28 22:16:22 +00006780 case Node::Field:
6781 case Node::Identifier:
6782 Comp.isBrackets = false;
6783 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006784 if (!Comp.U.IdentInfo)
6785 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006786
Douglas Gregor882211c2010-04-28 22:16:22 +00006787 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006788
Douglas Gregord1702062010-04-29 00:18:15 +00006789 case Node::Base:
6790 // Will be recomputed during the rebuild.
6791 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006793
Douglas Gregor882211c2010-04-28 22:16:22 +00006794 Components.push_back(Comp);
6795 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006796
Douglas Gregor882211c2010-04-28 22:16:22 +00006797 // If nothing changed, retain the existing expression.
6798 if (!getDerived().AlwaysRebuild() &&
6799 Type == E->getTypeSourceInfo() &&
6800 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006801 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006802
Douglas Gregor882211c2010-04-28 22:16:22 +00006803 // Build a new offsetof expression.
6804 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6805 Components.data(), Components.size(),
6806 E->getRParenLoc());
6807}
6808
6809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006810ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006811TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6812 assert(getDerived().AlreadyTransformed(E->getType()) &&
6813 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006814 return E;
John McCall8d69a212010-11-15 23:31:06 +00006815}
6816
6817template<typename Derived>
6818ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006819TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006820 // Rebuild the syntactic form. The original syntactic form has
6821 // opaque-value expressions in it, so strip those away and rebuild
6822 // the result. This is a really awful way of doing this, but the
6823 // better solution (rebuilding the semantic expressions and
6824 // rebinding OVEs as necessary) doesn't work; we'd need
6825 // TreeTransform to not strip away implicit conversions.
6826 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6827 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006828 if (result.isInvalid()) return ExprError();
6829
6830 // If that gives us a pseudo-object result back, the pseudo-object
6831 // expression must have been an lvalue-to-rvalue conversion which we
6832 // should reapply.
6833 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006834 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006835
6836 return result;
6837}
6838
6839template<typename Derived>
6840ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006841TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6842 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006844 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006845
John McCallbcd03502009-12-07 02:54:59 +00006846 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006847 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006849
John McCall4c98fd82009-11-04 07:28:41 +00006850 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006851 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006852
Peter Collingbournee190dee2011-03-11 19:24:49 +00006853 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6854 E->getKind(),
6855 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 }
Mike Stump11289f42009-09-09 15:08:12 +00006857
Eli Friedmane4f22df2012-02-29 04:03:55 +00006858 // C++0x [expr.sizeof]p1:
6859 // The operand is either an expression, which is an unevaluated operand
6860 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006861 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6862 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006863
Reid Kleckner32506ed2014-06-12 23:03:48 +00006864 // Try to recover if we have something like sizeof(T::X) where X is a type.
6865 // Notably, there must be *exactly* one set of parens if X is a type.
6866 TypeSourceInfo *RecoveryTSI = nullptr;
6867 ExprResult SubExpr;
6868 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
6869 if (auto *DRE =
6870 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
6871 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
6872 PE, DRE, false, &RecoveryTSI);
6873 else
6874 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6875
6876 if (RecoveryTSI) {
6877 return getDerived().RebuildUnaryExprOrTypeTrait(
6878 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
6879 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00006880 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006881
Eli Friedmane4f22df2012-02-29 04:03:55 +00006882 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006883 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006884
Peter Collingbournee190dee2011-03-11 19:24:49 +00006885 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6886 E->getOperatorLoc(),
6887 E->getKind(),
6888 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006889}
Mike Stump11289f42009-09-09 15:08:12 +00006890
Douglas Gregora16548e2009-08-11 05:31:07 +00006891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006893TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006894 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006895 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006897
John McCalldadc5752010-08-24 06:29:42 +00006898 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006899 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006901
6902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 if (!getDerived().AlwaysRebuild() &&
6904 LHS.get() == E->getLHS() &&
6905 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006906 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006907
John McCallb268a282010-08-23 23:25:46 +00006908 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006909 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006910 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006911 E->getRBracketLoc());
6912}
Mike Stump11289f42009-09-09 15:08:12 +00006913
6914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006916TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006918 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006919 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006920 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006921
6922 // Transform arguments.
6923 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006924 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006925 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006926 &ArgChanged))
6927 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006928
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 if (!getDerived().AlwaysRebuild() &&
6930 Callee.get() == E->getCallee() &&
6931 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006932 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006933
Douglas Gregora16548e2009-08-11 05:31:07 +00006934 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006935 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006937 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006938 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 E->getRParenLoc());
6940}
Mike Stump11289f42009-09-09 15:08:12 +00006941
6942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006945 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006946 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006947 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006948
Douglas Gregorea972d32011-02-28 21:54:11 +00006949 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006950 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006951 QualifierLoc
6952 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006953
Douglas Gregorea972d32011-02-28 21:54:11 +00006954 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006955 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006956 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006957 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006958
Eli Friedman2cfcef62009-12-04 06:40:45 +00006959 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006960 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6961 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006964
John McCall16df1e52010-03-30 21:47:33 +00006965 NamedDecl *FoundDecl = E->getFoundDecl();
6966 if (FoundDecl == E->getMemberDecl()) {
6967 FoundDecl = Member;
6968 } else {
6969 FoundDecl = cast_or_null<NamedDecl>(
6970 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6971 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006972 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006973 }
6974
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 if (!getDerived().AlwaysRebuild() &&
6976 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006977 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006978 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006979 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006980 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006981
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006982 // Mark it referenced in the new context regardless.
6983 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006984 SemaRef.MarkMemberReferenced(E);
6985
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006986 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006987 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006988
John McCall6b51f282009-11-23 01:53:49 +00006989 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006990 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006991 TransArgs.setLAngleLoc(E->getLAngleLoc());
6992 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006993 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6994 E->getNumTemplateArgs(),
6995 TransArgs))
6996 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007000 SourceLocation FakeOperatorLoc =
7001 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007002
John McCall38836f02010-01-15 08:34:02 +00007003 // FIXME: to do this check properly, we will need to preserve the
7004 // first-qualifier-in-scope here, just in case we had a dependent
7005 // base (and therefore couldn't do the check) and a
7006 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007007 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007008
John McCallb268a282010-08-23 23:25:46 +00007009 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007011 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007012 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007013 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007014 Member,
John McCall16df1e52010-03-30 21:47:33 +00007015 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007016 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007017 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007018 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007019}
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007024 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007025 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007027
John McCalldadc5752010-08-24 06:29:42 +00007028 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007031
Douglas Gregora16548e2009-08-11 05:31:07 +00007032 if (!getDerived().AlwaysRebuild() &&
7033 LHS.get() == E->getLHS() &&
7034 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007035 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007036
Lang Hames5de91cc2012-10-02 04:45:10 +00007037 Sema::FPContractStateRAII FPContractState(getSema());
7038 getSema().FPFeatures.fp_contract = E->isFPContractable();
7039
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007041 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007042}
7043
Mike Stump11289f42009-09-09 15:08:12 +00007044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007045ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007046TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007047 CompoundAssignOperator *E) {
7048 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007049}
Mike Stump11289f42009-09-09 15:08:12 +00007050
Douglas Gregora16548e2009-08-11 05:31:07 +00007051template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007052ExprResult TreeTransform<Derived>::
7053TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7054 // Just rebuild the common and RHS expressions and see whether we
7055 // get any changes.
7056
7057 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7058 if (commonExpr.isInvalid())
7059 return ExprError();
7060
7061 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7062 if (rhs.isInvalid())
7063 return ExprError();
7064
7065 if (!getDerived().AlwaysRebuild() &&
7066 commonExpr.get() == e->getCommon() &&
7067 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007068 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007069
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007070 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007071 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007072 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007073 e->getColonLoc(),
7074 rhs.get());
7075}
7076
7077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007079TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007080 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007081 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007083
John McCalldadc5752010-08-24 06:29:42 +00007084 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007085 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007086 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007087
John McCalldadc5752010-08-24 06:29:42 +00007088 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007091
Douglas Gregora16548e2009-08-11 05:31:07 +00007092 if (!getDerived().AlwaysRebuild() &&
7093 Cond.get() == E->getCond() &&
7094 LHS.get() == E->getLHS() &&
7095 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007096 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007097
John McCallb268a282010-08-23 23:25:46 +00007098 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007099 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007100 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007101 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007102 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007103}
Mike Stump11289f42009-09-09 15:08:12 +00007104
7105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007107TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007108 // Implicit casts are eliminated during transformation, since they
7109 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007110 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007111}
Mike Stump11289f42009-09-09 15:08:12 +00007112
Douglas Gregora16548e2009-08-11 05:31:07 +00007113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007116 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7117 if (!Type)
7118 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007119
John McCalldadc5752010-08-24 06:29:42 +00007120 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007121 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007124
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007126 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007127 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007128 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007129
John McCall97513962010-01-15 18:39:57 +00007130 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007131 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007133 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007134}
Mike Stump11289f42009-09-09 15:08:12 +00007135
Douglas Gregora16548e2009-08-11 05:31:07 +00007136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007137ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007138TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007139 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7140 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7141 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007143
John McCalldadc5752010-08-24 06:29:42 +00007144 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007145 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007147
Douglas Gregora16548e2009-08-11 05:31:07 +00007148 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007149 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007150 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007151 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007152
John McCall5d7aa7f2010-01-19 22:33:45 +00007153 // Note: the expression type doesn't necessarily match the
7154 // type-as-written, but that's okay, because it should always be
7155 // derivable from the initializer.
7156
John McCalle15bbff2010-01-18 19:35:47 +00007157 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007158 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007159 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007160}
Mike Stump11289f42009-09-09 15:08:12 +00007161
Douglas Gregora16548e2009-08-11 05:31:07 +00007162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007164TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007165 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007166 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 if (!getDerived().AlwaysRebuild() &&
7170 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007171 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007172
Douglas Gregora16548e2009-08-11 05:31:07 +00007173 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007174 SourceLocation FakeOperatorLoc =
7175 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007176 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 E->getAccessorLoc(),
7178 E->getAccessor());
7179}
Mike Stump11289f42009-09-09 15:08:12 +00007180
Douglas Gregora16548e2009-08-11 05:31:07 +00007181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007183TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007185
Benjamin Kramerf0623432012-08-23 22:51:59 +00007186 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007187 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007188 Inits, &InitChanged))
7189 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007190
Douglas Gregora16548e2009-08-11 05:31:07 +00007191 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007192 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007193
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007194 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007195 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007196}
Mike Stump11289f42009-09-09 15:08:12 +00007197
Douglas Gregora16548e2009-08-11 05:31:07 +00007198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007200TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007202
Douglas Gregorebe10102009-08-20 07:17:43 +00007203 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007204 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007205 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007207
Douglas Gregorebe10102009-08-20 07:17:43 +00007208 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007209 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 bool ExprChanged = false;
7211 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7212 DEnd = E->designators_end();
7213 D != DEnd; ++D) {
7214 if (D->isFieldDesignator()) {
7215 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7216 D->getDotLoc(),
7217 D->getFieldLoc()));
7218 continue;
7219 }
Mike Stump11289f42009-09-09 15:08:12 +00007220
Douglas Gregora16548e2009-08-11 05:31:07 +00007221 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007222 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007225
7226 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007227 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007228
Douglas Gregora16548e2009-08-11 05:31:07 +00007229 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007230 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007231 continue;
7232 }
Mike Stump11289f42009-09-09 15:08:12 +00007233
Douglas Gregora16548e2009-08-11 05:31:07 +00007234 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007235 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007236 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7237 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007239
John McCalldadc5752010-08-24 06:29:42 +00007240 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007241 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007243
7244 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007245 End.get(),
7246 D->getLBracketLoc(),
7247 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007248
Douglas Gregora16548e2009-08-11 05:31:07 +00007249 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7250 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007251
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007252 ArrayExprs.push_back(Start.get());
7253 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007254 }
Mike Stump11289f42009-09-09 15:08:12 +00007255
Douglas Gregora16548e2009-08-11 05:31:07 +00007256 if (!getDerived().AlwaysRebuild() &&
7257 Init.get() == E->getInit() &&
7258 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007259 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007260
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007261 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007262 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007263 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007264}
Mike Stump11289f42009-09-09 15:08:12 +00007265
Douglas Gregora16548e2009-08-11 05:31:07 +00007266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007267ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007268TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007269 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007270 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007271
Douglas Gregor3da3c062009-10-28 00:29:27 +00007272 // FIXME: Will we ever have proper type location here? Will we actually
7273 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007274 QualType T = getDerived().TransformType(E->getType());
7275 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007277
Douglas Gregora16548e2009-08-11 05:31:07 +00007278 if (!getDerived().AlwaysRebuild() &&
7279 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007280 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007281
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 return getDerived().RebuildImplicitValueInitExpr(T);
7283}
Mike Stump11289f42009-09-09 15:08:12 +00007284
Douglas Gregora16548e2009-08-11 05:31:07 +00007285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007287TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007288 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7289 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007291
John McCalldadc5752010-08-24 06:29:42 +00007292 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007293 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007295
Douglas Gregora16548e2009-08-11 05:31:07 +00007296 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007297 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007298 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007299 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007300
John McCallb268a282010-08-23 23:25:46 +00007301 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007302 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007303}
7304
7305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007307TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007308 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007309 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007310 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7311 &ArgumentChanged))
7312 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007313
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007315 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007316 E->getRParenLoc());
7317}
Mike Stump11289f42009-09-09 15:08:12 +00007318
Douglas Gregora16548e2009-08-11 05:31:07 +00007319/// \brief Transform an address-of-label expression.
7320///
7321/// By default, the transformation of an address-of-label expression always
7322/// rebuilds the expression, so that the label identifier can be resolved to
7323/// the corresponding label statement by semantic analysis.
7324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007327 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7328 E->getLabel());
7329 if (!LD)
7330 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007331
Douglas Gregora16548e2009-08-11 05:31:07 +00007332 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007333 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007334}
Mike Stump11289f42009-09-09 15:08:12 +00007335
7336template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007337ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007338TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007339 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007340 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007341 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007342 if (SubStmt.isInvalid()) {
7343 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007344 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007345 }
Mike Stump11289f42009-09-09 15:08:12 +00007346
Douglas Gregora16548e2009-08-11 05:31:07 +00007347 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007348 SubStmt.get() == E->getSubStmt()) {
7349 // Calling this an 'error' is unintuitive, but it does the right thing.
7350 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007351 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007352 }
Mike Stump11289f42009-09-09 15:08:12 +00007353
7354 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007355 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007356 E->getRParenLoc());
7357}
Mike Stump11289f42009-09-09 15:08:12 +00007358
Douglas Gregora16548e2009-08-11 05:31:07 +00007359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007361TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007362 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007365
John McCalldadc5752010-08-24 06:29:42 +00007366 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007369
John McCalldadc5752010-08-24 06:29:42 +00007370 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregora16548e2009-08-11 05:31:07 +00007374 if (!getDerived().AlwaysRebuild() &&
7375 Cond.get() == E->getCond() &&
7376 LHS.get() == E->getLHS() &&
7377 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007378 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007379
Douglas Gregora16548e2009-08-11 05:31:07 +00007380 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007381 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 E->getRParenLoc());
7383}
Mike Stump11289f42009-09-09 15:08:12 +00007384
Douglas Gregora16548e2009-08-11 05:31:07 +00007385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007387TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007388 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007389}
7390
7391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007392ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007393TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007394 switch (E->getOperator()) {
7395 case OO_New:
7396 case OO_Delete:
7397 case OO_Array_New:
7398 case OO_Array_Delete:
7399 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007400
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007401 case OO_Call: {
7402 // This is a call to an object's operator().
7403 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7404
7405 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007406 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007407 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007408 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007409
7410 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007411 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7412 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007413
7414 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007415 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007416 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007417 Args))
7418 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007419
John McCallb268a282010-08-23 23:25:46 +00007420 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007421 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007422 E->getLocEnd());
7423 }
7424
7425#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7426 case OO_##Name:
7427#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7428#include "clang/Basic/OperatorKinds.def"
7429 case OO_Subscript:
7430 // Handled below.
7431 break;
7432
7433 case OO_Conditional:
7434 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007435
7436 case OO_None:
7437 case NUM_OVERLOADED_OPERATORS:
7438 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007439 }
7440
John McCalldadc5752010-08-24 06:29:42 +00007441 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007442 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007444
Richard Smithdb2630f2012-10-21 03:28:35 +00007445 ExprResult First;
7446 if (E->getOperator() == OO_Amp)
7447 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7448 else
7449 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007450 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007451 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007452
John McCalldadc5752010-08-24 06:29:42 +00007453 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007454 if (E->getNumArgs() == 2) {
7455 Second = getDerived().TransformExpr(E->getArg(1));
7456 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007457 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007458 }
Mike Stump11289f42009-09-09 15:08:12 +00007459
Douglas Gregora16548e2009-08-11 05:31:07 +00007460 if (!getDerived().AlwaysRebuild() &&
7461 Callee.get() == E->getCallee() &&
7462 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007463 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007464 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007465
Lang Hames5de91cc2012-10-02 04:45:10 +00007466 Sema::FPContractStateRAII FPContractState(getSema());
7467 getSema().FPFeatures.fp_contract = E->isFPContractable();
7468
Douglas Gregora16548e2009-08-11 05:31:07 +00007469 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7470 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007471 Callee.get(),
7472 First.get(),
7473 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007474}
Mike Stump11289f42009-09-09 15:08:12 +00007475
Douglas Gregora16548e2009-08-11 05:31:07 +00007476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007478TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7479 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007480}
Mike Stump11289f42009-09-09 15:08:12 +00007481
Douglas Gregora16548e2009-08-11 05:31:07 +00007482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007483ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007484TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7485 // Transform the callee.
7486 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7487 if (Callee.isInvalid())
7488 return ExprError();
7489
7490 // Transform exec config.
7491 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7492 if (EC.isInvalid())
7493 return ExprError();
7494
7495 // Transform arguments.
7496 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007497 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007498 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007499 &ArgChanged))
7500 return ExprError();
7501
7502 if (!getDerived().AlwaysRebuild() &&
7503 Callee.get() == E->getCallee() &&
7504 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007505 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007506
7507 // FIXME: Wrong source location information for the '('.
7508 SourceLocation FakeLParenLoc
7509 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7510 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007511 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007512 E->getRParenLoc(), EC.get());
7513}
7514
7515template<typename Derived>
7516ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007517TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007518 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7519 if (!Type)
7520 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007521
John McCalldadc5752010-08-24 06:29:42 +00007522 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007523 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007524 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007526
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007528 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007529 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007530 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007531 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007532 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007533 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007534 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007535 E->getAngleBrackets().getEnd(),
7536 // FIXME. this should be '(' location
7537 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007538 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007539 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007540}
Mike Stump11289f42009-09-09 15:08:12 +00007541
Douglas Gregora16548e2009-08-11 05:31:07 +00007542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007544TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7545 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007546}
Mike Stump11289f42009-09-09 15:08:12 +00007547
7548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007550TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7551 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007552}
7553
Douglas Gregora16548e2009-08-11 05:31:07 +00007554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007555ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007556TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007557 CXXReinterpretCastExpr *E) {
7558 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007559}
Mike Stump11289f42009-09-09 15:08:12 +00007560
Douglas Gregora16548e2009-08-11 05:31:07 +00007561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007563TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7564 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007565}
Mike Stump11289f42009-09-09 15:08:12 +00007566
Douglas Gregora16548e2009-08-11 05:31:07 +00007567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007568ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007569TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007570 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007571 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7572 if (!Type)
7573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007574
John McCalldadc5752010-08-24 06:29:42 +00007575 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007576 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007579
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007581 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007582 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007583 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007584
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007585 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007586 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007587 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 E->getRParenLoc());
7589}
Mike Stump11289f42009-09-09 15:08:12 +00007590
Douglas Gregora16548e2009-08-11 05:31:07 +00007591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007593TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007595 TypeSourceInfo *TInfo
7596 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7597 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregora16548e2009-08-11 05:31:07 +00007600 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007601 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007602 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007603
Douglas Gregor9da64192010-04-26 22:37:10 +00007604 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7605 E->getLocStart(),
7606 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 E->getLocEnd());
7608 }
Mike Stump11289f42009-09-09 15:08:12 +00007609
Eli Friedman456f0182012-01-20 01:26:23 +00007610 // We don't know whether the subexpression is potentially evaluated until
7611 // after we perform semantic analysis. We speculatively assume it is
7612 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007613 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007614 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7615 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007616
John McCalldadc5752010-08-24 06:29:42 +00007617 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007618 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007620
Douglas Gregora16548e2009-08-11 05:31:07 +00007621 if (!getDerived().AlwaysRebuild() &&
7622 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007623 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007624
Douglas Gregor9da64192010-04-26 22:37:10 +00007625 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7626 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007627 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 E->getLocEnd());
7629}
7630
7631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007632ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007633TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7634 if (E->isTypeOperand()) {
7635 TypeSourceInfo *TInfo
7636 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7637 if (!TInfo)
7638 return ExprError();
7639
7640 if (!getDerived().AlwaysRebuild() &&
7641 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007642 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007643
Douglas Gregor69735112011-03-06 17:40:41 +00007644 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007645 E->getLocStart(),
7646 TInfo,
7647 E->getLocEnd());
7648 }
7649
Francois Pichet9f4f2072010-09-08 12:20:18 +00007650 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7651
7652 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7653 if (SubExpr.isInvalid())
7654 return ExprError();
7655
7656 if (!getDerived().AlwaysRebuild() &&
7657 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007658 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007659
7660 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7661 E->getLocStart(),
7662 SubExpr.get(),
7663 E->getLocEnd());
7664}
7665
7666template<typename Derived>
7667ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007668TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007669 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007670}
Mike Stump11289f42009-09-09 15:08:12 +00007671
Douglas Gregora16548e2009-08-11 05:31:07 +00007672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007673ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007674TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007675 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007676 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007677}
Mike Stump11289f42009-09-09 15:08:12 +00007678
Douglas Gregora16548e2009-08-11 05:31:07 +00007679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007681TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007682 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007683
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007684 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7685 // Make sure that we capture 'this'.
7686 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007687 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007688 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007689
Douglas Gregorb15af892010-01-07 23:12:05 +00007690 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007691}
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007695TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007696 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007698 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007699
Douglas Gregora16548e2009-08-11 05:31:07 +00007700 if (!getDerived().AlwaysRebuild() &&
7701 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007702 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007703
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007704 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7705 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007706}
Mike Stump11289f42009-09-09 15:08:12 +00007707
Douglas Gregora16548e2009-08-11 05:31:07 +00007708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007709ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007710TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007711 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007712 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7713 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007716
Chandler Carruth794da4c2010-02-08 06:42:49 +00007717 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007719 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007720
Douglas Gregor033f6752009-12-23 23:03:06 +00007721 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007722}
Mike Stump11289f42009-09-09 15:08:12 +00007723
Douglas Gregora16548e2009-08-11 05:31:07 +00007724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007725ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007726TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7727 FieldDecl *Field
7728 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7729 E->getField()));
7730 if (!Field)
7731 return ExprError();
7732
7733 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007734 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007735
7736 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7737}
7738
7739template<typename Derived>
7740ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007741TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7742 CXXScalarValueInitExpr *E) {
7743 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7744 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007745 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007746
Douglas Gregora16548e2009-08-11 05:31:07 +00007747 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007748 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007749 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007750
Chad Rosier1dcde962012-08-08 18:46:20 +00007751 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007752 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007753 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007754}
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>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007759 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007760 TypeSourceInfo *AllocTypeInfo
7761 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7762 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007764
Douglas Gregora16548e2009-08-11 05:31:07 +00007765 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007766 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007767 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007769
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 // Transform the placement arguments (if any).
7771 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007772 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007773 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007774 E->getNumPlacementArgs(), true,
7775 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007777
Sebastian Redl6047f072012-02-16 12:22:20 +00007778 // Transform the initializer (if any).
7779 Expr *OldInit = E->getInitializer();
7780 ExprResult NewInit;
7781 if (OldInit)
7782 NewInit = getDerived().TransformExpr(OldInit);
7783 if (NewInit.isInvalid())
7784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007785
Sebastian Redl6047f072012-02-16 12:22:20 +00007786 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007787 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007788 if (E->getOperatorNew()) {
7789 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007790 getDerived().TransformDecl(E->getLocStart(),
7791 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007792 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007793 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007794 }
7795
Craig Topperc3ec1492014-05-26 06:22:03 +00007796 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007797 if (E->getOperatorDelete()) {
7798 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007799 getDerived().TransformDecl(E->getLocStart(),
7800 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007801 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007802 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007803 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007804
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007806 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007807 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007808 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007809 OperatorNew == E->getOperatorNew() &&
7810 OperatorDelete == E->getOperatorDelete() &&
7811 !ArgumentChanged) {
7812 // Mark any declarations we need as referenced.
7813 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007814 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007815 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007816 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007817 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007818
Sebastian Redl6047f072012-02-16 12:22:20 +00007819 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007820 QualType ElementType
7821 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7822 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7823 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7824 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007825 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007826 }
7827 }
7828 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007829
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007830 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007831 }
Mike Stump11289f42009-09-09 15:08:12 +00007832
Douglas Gregor0744ef62010-09-07 21:49:58 +00007833 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007834 if (!ArraySize.get()) {
7835 // If no array size was specified, but the new expression was
7836 // instantiated with an array type (e.g., "new T" where T is
7837 // instantiated with "int[4]"), extract the outer bound from the
7838 // array type as our array size. We do this with constant and
7839 // dependently-sized array types.
7840 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7841 if (!ArrayT) {
7842 // Do nothing
7843 } else if (const ConstantArrayType *ConsArrayT
7844 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007845 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7846 SemaRef.Context.getSizeType(),
7847 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007848 AllocType = ConsArrayT->getElementType();
7849 } else if (const DependentSizedArrayType *DepArrayT
7850 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7851 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007852 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007853 AllocType = DepArrayT->getElementType();
7854 }
7855 }
7856 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007857
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7859 E->isGlobalNew(),
7860 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007861 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007862 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007863 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007864 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007865 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007866 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007867 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007868 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007869}
Mike Stump11289f42009-09-09 15:08:12 +00007870
Douglas Gregora16548e2009-08-11 05:31:07 +00007871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007873TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007874 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007875 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007877
Douglas Gregord2d9da02010-02-26 00:38:10 +00007878 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007879 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007880 if (E->getOperatorDelete()) {
7881 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007882 getDerived().TransformDecl(E->getLocStart(),
7883 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007884 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007885 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007887
Douglas Gregora16548e2009-08-11 05:31:07 +00007888 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007889 Operand.get() == E->getArgument() &&
7890 OperatorDelete == E->getOperatorDelete()) {
7891 // Mark any declarations we need as referenced.
7892 // FIXME: instantiation-specific.
7893 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007894 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007895
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007896 if (!E->getArgument()->isTypeDependent()) {
7897 QualType Destroyed = SemaRef.Context.getBaseElementType(
7898 E->getDestroyedType());
7899 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7900 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007901 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007902 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007903 }
7904 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007905
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007906 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007907 }
Mike Stump11289f42009-09-09 15:08:12 +00007908
Douglas Gregora16548e2009-08-11 05:31:07 +00007909 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7910 E->isGlobalDelete(),
7911 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007912 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007913}
Mike Stump11289f42009-09-09 15:08:12 +00007914
Douglas Gregora16548e2009-08-11 05:31:07 +00007915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007916ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007917TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007918 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007919 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007920 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007922
John McCallba7bf592010-08-24 05:47:05 +00007923 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007924 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007925 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007926 E->getOperatorLoc(),
7927 E->isArrow()? tok::arrow : tok::period,
7928 ObjectTypePtr,
7929 MayBePseudoDestructor);
7930 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007932
John McCallba7bf592010-08-24 05:47:05 +00007933 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007934 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7935 if (QualifierLoc) {
7936 QualifierLoc
7937 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7938 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007939 return ExprError();
7940 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007941 CXXScopeSpec SS;
7942 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007943
Douglas Gregor678f90d2010-02-25 01:56:36 +00007944 PseudoDestructorTypeStorage Destroyed;
7945 if (E->getDestroyedTypeInfo()) {
7946 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007947 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007948 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007949 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007950 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007951 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007952 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007953 // We aren't likely to be able to resolve the identifier down to a type
7954 // now anyway, so just retain the identifier.
7955 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7956 E->getDestroyedTypeLoc());
7957 } else {
7958 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007959 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007960 *E->getDestroyedTypeIdentifier(),
7961 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007962 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007963 SS, ObjectTypePtr,
7964 false);
7965 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007966 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007967
Douglas Gregor678f90d2010-02-25 01:56:36 +00007968 Destroyed
7969 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7970 E->getDestroyedTypeLoc());
7971 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007972
Craig Topperc3ec1492014-05-26 06:22:03 +00007973 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007974 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007975 CXXScopeSpec EmptySS;
7976 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00007977 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007978 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007979 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007981
John McCallb268a282010-08-23 23:25:46 +00007982 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007983 E->getOperatorLoc(),
7984 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007985 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007986 ScopeTypeInfo,
7987 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007988 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007989 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007990}
Mike Stump11289f42009-09-09 15:08:12 +00007991
Douglas Gregorad8a3362009-09-04 17:36:40 +00007992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007993ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007994TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007995 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007996 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7997 Sema::LookupOrdinaryName);
7998
7999 // Transform all the decls.
8000 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8001 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008002 NamedDecl *InstD = static_cast<NamedDecl*>(
8003 getDerived().TransformDecl(Old->getNameLoc(),
8004 *I));
John McCall84d87672009-12-10 09:41:52 +00008005 if (!InstD) {
8006 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8007 // This can happen because of dependent hiding.
8008 if (isa<UsingShadowDecl>(*I))
8009 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008010 else {
8011 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008012 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008013 }
John McCall84d87672009-12-10 09:41:52 +00008014 }
John McCalle66edc12009-11-24 19:00:30 +00008015
8016 // Expand using declarations.
8017 if (isa<UsingDecl>(InstD)) {
8018 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008019 for (auto *I : UD->shadows())
8020 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008021 continue;
8022 }
8023
8024 R.addDecl(InstD);
8025 }
8026
8027 // Resolve a kind, but don't do any further analysis. If it's
8028 // ambiguous, the callee needs to deal with it.
8029 R.resolveKind();
8030
8031 // Rebuild the nested-name qualifier, if present.
8032 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008033 if (Old->getQualifierLoc()) {
8034 NestedNameSpecifierLoc QualifierLoc
8035 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8036 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008037 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008038
Douglas Gregor0da1d432011-02-28 20:01:57 +00008039 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008040 }
8041
Douglas Gregor9262f472010-04-27 18:19:34 +00008042 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008043 CXXRecordDecl *NamingClass
8044 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8045 Old->getNameLoc(),
8046 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008047 if (!NamingClass) {
8048 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008049 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008051
Douglas Gregorda7be082010-04-27 16:10:10 +00008052 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008053 }
8054
Abramo Bagnara7945c982012-01-27 09:46:47 +00008055 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8056
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008057 // If we have neither explicit template arguments, nor the template keyword,
8058 // it's a normal declaration name.
8059 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008060 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8061
8062 // If we have template arguments, rebuild them, then rebuild the
8063 // templateid expression.
8064 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008065 if (Old->hasExplicitTemplateArgs() &&
8066 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008067 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008068 TransArgs)) {
8069 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008070 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008071 }
John McCalle66edc12009-11-24 19:00:30 +00008072
Abramo Bagnara7945c982012-01-27 09:46:47 +00008073 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008074 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008075}
Mike Stump11289f42009-09-09 15:08:12 +00008076
Douglas Gregora16548e2009-08-11 05:31:07 +00008077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008078ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008079TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8080 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008081 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008082 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8083 TypeSourceInfo *From = E->getArg(I);
8084 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008085 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008086 TypeLocBuilder TLB;
8087 TLB.reserve(FromTL.getFullDataSize());
8088 QualType To = getDerived().TransformType(TLB, FromTL);
8089 if (To.isNull())
8090 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008091
Douglas Gregor29c42f22012-02-24 07:38:34 +00008092 if (To == From->getType())
8093 Args.push_back(From);
8094 else {
8095 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8096 ArgChanged = true;
8097 }
8098 continue;
8099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008100
Douglas Gregor29c42f22012-02-24 07:38:34 +00008101 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008102
Douglas Gregor29c42f22012-02-24 07:38:34 +00008103 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008104 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008105 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8106 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8107 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008108
Douglas Gregor29c42f22012-02-24 07:38:34 +00008109 // Determine whether the set of unexpanded parameter packs can and should
8110 // be expanded.
8111 bool Expand = true;
8112 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008113 Optional<unsigned> OrigNumExpansions =
8114 ExpansionTL.getTypePtr()->getNumExpansions();
8115 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008116 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8117 PatternTL.getSourceRange(),
8118 Unexpanded,
8119 Expand, RetainExpansion,
8120 NumExpansions))
8121 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008122
Douglas Gregor29c42f22012-02-24 07:38:34 +00008123 if (!Expand) {
8124 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008125 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008126 // expansion.
8127 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008128
Douglas Gregor29c42f22012-02-24 07:38:34 +00008129 TypeLocBuilder TLB;
8130 TLB.reserve(From->getTypeLoc().getFullDataSize());
8131
8132 QualType To = getDerived().TransformType(TLB, PatternTL);
8133 if (To.isNull())
8134 return ExprError();
8135
Chad Rosier1dcde962012-08-08 18:46:20 +00008136 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008137 PatternTL.getSourceRange(),
8138 ExpansionTL.getEllipsisLoc(),
8139 NumExpansions);
8140 if (To.isNull())
8141 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008142
Douglas Gregor29c42f22012-02-24 07:38:34 +00008143 PackExpansionTypeLoc ToExpansionTL
8144 = TLB.push<PackExpansionTypeLoc>(To);
8145 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8146 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8147 continue;
8148 }
8149
8150 // Expand the pack expansion by substituting for each argument in the
8151 // pack(s).
8152 for (unsigned I = 0; I != *NumExpansions; ++I) {
8153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8154 TypeLocBuilder TLB;
8155 TLB.reserve(PatternTL.getFullDataSize());
8156 QualType To = getDerived().TransformType(TLB, PatternTL);
8157 if (To.isNull())
8158 return ExprError();
8159
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008160 if (To->containsUnexpandedParameterPack()) {
8161 To = getDerived().RebuildPackExpansionType(To,
8162 PatternTL.getSourceRange(),
8163 ExpansionTL.getEllipsisLoc(),
8164 NumExpansions);
8165 if (To.isNull())
8166 return ExprError();
8167
8168 PackExpansionTypeLoc ToExpansionTL
8169 = TLB.push<PackExpansionTypeLoc>(To);
8170 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8171 }
8172
Douglas Gregor29c42f22012-02-24 07:38:34 +00008173 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008175
Douglas Gregor29c42f22012-02-24 07:38:34 +00008176 if (!RetainExpansion)
8177 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008178
Douglas Gregor29c42f22012-02-24 07:38:34 +00008179 // If we're supposed to retain a pack expansion, do so by temporarily
8180 // forgetting the partially-substituted parameter pack.
8181 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8182
8183 TypeLocBuilder TLB;
8184 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008185
Douglas Gregor29c42f22012-02-24 07:38:34 +00008186 QualType To = getDerived().TransformType(TLB, PatternTL);
8187 if (To.isNull())
8188 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008189
8190 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008191 PatternTL.getSourceRange(),
8192 ExpansionTL.getEllipsisLoc(),
8193 NumExpansions);
8194 if (To.isNull())
8195 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008196
Douglas Gregor29c42f22012-02-24 07:38:34 +00008197 PackExpansionTypeLoc ToExpansionTL
8198 = TLB.push<PackExpansionTypeLoc>(To);
8199 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8200 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8201 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008202
Douglas Gregor29c42f22012-02-24 07:38:34 +00008203 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008204 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008205
8206 return getDerived().RebuildTypeTrait(E->getTrait(),
8207 E->getLocStart(),
8208 Args,
8209 E->getLocEnd());
8210}
8211
8212template<typename Derived>
8213ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008214TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8215 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8216 if (!T)
8217 return ExprError();
8218
8219 if (!getDerived().AlwaysRebuild() &&
8220 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008221 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008222
8223 ExprResult SubExpr;
8224 {
8225 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8226 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8227 if (SubExpr.isInvalid())
8228 return ExprError();
8229
8230 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008231 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008232 }
8233
8234 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8235 E->getLocStart(),
8236 T,
8237 SubExpr.get(),
8238 E->getLocEnd());
8239}
8240
8241template<typename Derived>
8242ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008243TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8244 ExprResult SubExpr;
8245 {
8246 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8247 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8248 if (SubExpr.isInvalid())
8249 return ExprError();
8250
8251 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008252 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008253 }
8254
8255 return getDerived().RebuildExpressionTrait(
8256 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8257}
8258
Reid Kleckner32506ed2014-06-12 23:03:48 +00008259template <typename Derived>
8260ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8261 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8262 TypeSourceInfo **RecoveryTSI) {
8263 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8264 DRE, AddrTaken, RecoveryTSI);
8265
8266 // Propagate both errors and recovered types, which return ExprEmpty.
8267 if (!NewDRE.isUsable())
8268 return NewDRE;
8269
8270 // We got an expr, wrap it up in parens.
8271 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8272 return PE;
8273 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8274 PE->getRParen());
8275}
8276
8277template <typename Derived>
8278ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8279 DependentScopeDeclRefExpr *E) {
8280 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8281 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008282}
8283
8284template<typename Derived>
8285ExprResult
8286TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8287 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008288 bool IsAddressOfOperand,
8289 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008290 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008291 NestedNameSpecifierLoc QualifierLoc
8292 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8293 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008294 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008295 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008296
John McCall31f82722010-11-12 08:19:04 +00008297 // TODO: If this is a conversion-function-id, verify that the
8298 // destination type name (if present) resolves the same way after
8299 // instantiation as it did in the local scope.
8300
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008301 DeclarationNameInfo NameInfo
8302 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8303 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008305
John McCalle66edc12009-11-24 19:00:30 +00008306 if (!E->hasExplicitTemplateArgs()) {
8307 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008308 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008309 // Note: it is sufficient to compare the Name component of NameInfo:
8310 // if name has not changed, DNLoc has not changed either.
8311 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008312 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008313
Reid Kleckner32506ed2014-06-12 23:03:48 +00008314 return getDerived().RebuildDependentScopeDeclRefExpr(
8315 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8316 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008317 }
John McCall6b51f282009-11-23 01:53:49 +00008318
8319 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008320 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8321 E->getNumTemplateArgs(),
8322 TransArgs))
8323 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008324
Reid Kleckner32506ed2014-06-12 23:03:48 +00008325 return getDerived().RebuildDependentScopeDeclRefExpr(
8326 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8327 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008328}
8329
8330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008331ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008332TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008333 // CXXConstructExprs other than for list-initialization and
8334 // CXXTemporaryObjectExpr are always implicit, so when we have
8335 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008336 if ((E->getNumArgs() == 1 ||
8337 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008338 (!getDerived().DropCallArgument(E->getArg(0))) &&
8339 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008340 return getDerived().TransformExpr(E->getArg(0));
8341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8343
8344 QualType T = getDerived().TransformType(E->getType());
8345 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008346 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008347
8348 CXXConstructorDecl *Constructor
8349 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008350 getDerived().TransformDecl(E->getLocStart(),
8351 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008352 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008354
Douglas Gregora16548e2009-08-11 05:31:07 +00008355 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008356 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008357 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008358 &ArgumentChanged))
8359 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 if (!getDerived().AlwaysRebuild() &&
8362 T == E->getType() &&
8363 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008364 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008365 // Mark the constructor as referenced.
8366 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008367 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008368 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008369 }
Mike Stump11289f42009-09-09 15:08:12 +00008370
Douglas Gregordb121ba2009-12-14 16:27:04 +00008371 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8372 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008373 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008374 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008375 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008376 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008377 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008378 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008379}
Mike Stump11289f42009-09-09 15:08:12 +00008380
Douglas Gregora16548e2009-08-11 05:31:07 +00008381/// \brief Transform a C++ temporary-binding expression.
8382///
Douglas Gregor363b1512009-12-24 18:51:59 +00008383/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8384/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008387TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008388 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008389}
Mike Stump11289f42009-09-09 15:08:12 +00008390
John McCall5d413782010-12-06 08:20:24 +00008391/// \brief Transform a C++ expression that contains cleanups that should
8392/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008393///
John McCall5d413782010-12-06 08:20:24 +00008394/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008395/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008397ExprResult
John McCall5d413782010-12-06 08:20:24 +00008398TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008399 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008400}
Mike Stump11289f42009-09-09 15:08:12 +00008401
Douglas Gregora16548e2009-08-11 05:31:07 +00008402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008403ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008404TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008405 CXXTemporaryObjectExpr *E) {
8406 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8407 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008409
Douglas Gregora16548e2009-08-11 05:31:07 +00008410 CXXConstructorDecl *Constructor
8411 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008412 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008413 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008414 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008416
Douglas Gregora16548e2009-08-11 05:31:07 +00008417 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008418 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008420 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008421 &ArgumentChanged))
8422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008423
Douglas Gregora16548e2009-08-11 05:31:07 +00008424 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008425 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008426 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008427 !ArgumentChanged) {
8428 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008429 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008430 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008432
Richard Smithd59b8322012-12-19 01:39:02 +00008433 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008434 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8435 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008436 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008437 E->getLocEnd());
8438}
Mike Stump11289f42009-09-09 15:08:12 +00008439
Douglas Gregora16548e2009-08-11 05:31:07 +00008440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008441ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008442TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008443
8444 // Transform any init-capture expressions before entering the scope of the
8445 // lambda body, because they are not semantically within that scope.
8446 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8447 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8448 E->explicit_capture_begin());
8449
8450 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8451 CEnd = E->capture_end();
8452 C != CEnd; ++C) {
8453 if (!C->isInitCapture())
8454 continue;
8455 EnterExpressionEvaluationContext EEEC(getSema(),
8456 Sema::PotentiallyEvaluated);
8457 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8458 C->getCapturedVar()->getInit(),
8459 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8460
8461 if (NewExprInitResult.isInvalid())
8462 return ExprError();
8463 Expr *NewExprInit = NewExprInitResult.get();
8464
8465 VarDecl *OldVD = C->getCapturedVar();
8466 QualType NewInitCaptureType =
8467 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8468 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8469 NewExprInit);
8470 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008471 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8472 std::make_pair(NewExprInitResult, NewInitCaptureType);
8473
8474 }
8475
Faisal Vali524ca282013-11-12 01:40:44 +00008476 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008477 // Transform the template parameters, and add them to the current
8478 // instantiation scope. The null case is handled correctly.
8479 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8480 E->getTemplateParameterList());
8481
8482 // Check to see if the TypeSourceInfo of the call operator needs to
8483 // be transformed, and if so do the transformation in the
8484 // CurrentInstantiationScope.
8485
8486 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8487 FunctionProtoTypeLoc OldCallOpFPTL =
8488 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008489 TypeSourceInfo *NewCallOpTSI = nullptr;
8490
Faisal Vali2cba1332013-10-23 06:44:28 +00008491 const bool CallOpWasAlreadyTransformed =
8492 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8493
8494 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8495 if (CallOpWasAlreadyTransformed)
8496 NewCallOpTSI = OldCallOpTSI;
8497 else {
8498 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8499 // The transformation MUST be done in the CurrentInstantiationScope since
8500 // it introduces a mapping of the original to the newly created
8501 // transformed parameters.
8502
8503 TypeLocBuilder NewCallOpTLBuilder;
8504 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8505 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008506 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008507 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8508 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008509 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008510 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8511 // the vector below - this will be used to synthesize the
8512 // NewCallOperator. Additionally, add the parameters of the untransformed
8513 // lambda call operator to the CurrentInstantiationScope.
8514 SmallVector<ParmVarDecl *, 4> Params;
8515 {
8516 FunctionProtoTypeLoc NewCallOpFPTL =
8517 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8518 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008519 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008520
8521 for (unsigned I = 0; I < NewNumArgs; ++I) {
8522 // If this call operator's type does not require transformation,
8523 // the parameters do not get added to the current instantiation scope,
8524 // - so ADD them! This allows the following to compile when the enclosing
8525 // template is specialized and the entire lambda expression has to be
8526 // transformed.
8527 // template<class T> void foo(T t) {
8528 // auto L = [](auto a) {
8529 // auto M = [](char b) { <-- note: non-generic lambda
8530 // auto N = [](auto c) {
8531 // int x = sizeof(a);
8532 // x = sizeof(b); <-- specifically this line
8533 // x = sizeof(c);
8534 // };
8535 // };
8536 // };
8537 // }
8538 // foo('a')
8539 if (CallOpWasAlreadyTransformed)
8540 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8541 NewParamDeclArray[I]);
8542 // Add to Params array, so these parameters can be used to create
8543 // the newly transformed call operator.
8544 Params.push_back(NewParamDeclArray[I]);
8545 }
8546 }
8547
8548 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008549 return ExprError();
8550
Eli Friedmand564afb2012-09-19 01:18:11 +00008551 // Create the local class that will describe the lambda.
8552 CXXRecordDecl *Class
8553 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008554 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008555 /*KnownDependent=*/false,
8556 E->getCaptureDefault());
8557
Eli Friedmand564afb2012-09-19 01:18:11 +00008558 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8559
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008560 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008561 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008562 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008563 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008564 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008565 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008566 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008567
Faisal Vali2cba1332013-10-23 06:44:28 +00008568 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8569
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008570 return getDerived().TransformLambdaScope(E, NewCallOperator,
8571 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008572}
8573
8574template<typename Derived>
8575ExprResult
8576TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008577 CXXMethodDecl *CallOperator,
8578 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008579 bool Invalid = false;
8580
Douglas Gregorb4328232012-02-14 00:00:48 +00008581 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008582 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8583 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008584
Faisal Vali2b391ab2013-09-26 19:54:12 +00008585 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008586 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008587 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008588 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008589 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008590 E->hasExplicitParameters(),
8591 E->hasExplicitResultType(),
8592 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008593
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008594 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008595 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008596 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008597 CEnd = E->capture_end();
8598 C != CEnd; ++C) {
8599 // When we hit the first implicit capture, tell Sema that we've finished
8600 // the list of explicit captures.
8601 if (!FinishedExplicitCaptures && C->isImplicit()) {
8602 getSema().finishLambdaExplicitCaptures(LSI);
8603 FinishedExplicitCaptures = true;
8604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008605
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008606 // Capturing 'this' is trivial.
8607 if (C->capturesThis()) {
8608 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8609 continue;
8610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008611
Richard Smithba71c082013-05-16 06:20:58 +00008612 // Rebuild init-captures, including the implied field declaration.
8613 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008614
8615 InitCaptureInfoTy InitExprTypePair =
8616 InitCaptureExprsAndTypes[C - E->capture_begin()];
8617 ExprResult Init = InitExprTypePair.first;
8618 QualType InitQualType = InitExprTypePair.second;
8619 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008620 Invalid = true;
8621 continue;
8622 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008623 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008624 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8625 OldVD->getLocation(), InitExprTypePair.second,
8626 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008627 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008628 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008629 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008630 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008631 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008632 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008633 continue;
8634 }
8635
8636 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8637
Douglas Gregor3e308b12012-02-14 19:27:52 +00008638 // Determine the capture kind for Sema.
8639 Sema::TryCaptureKind Kind
8640 = C->isImplicit()? Sema::TryCapture_Implicit
8641 : C->getCaptureKind() == LCK_ByCopy
8642 ? Sema::TryCapture_ExplicitByVal
8643 : Sema::TryCapture_ExplicitByRef;
8644 SourceLocation EllipsisLoc;
8645 if (C->isPackExpansion()) {
8646 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8647 bool ShouldExpand = false;
8648 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008649 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008650 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8651 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008652 Unexpanded,
8653 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008654 NumExpansions)) {
8655 Invalid = true;
8656 continue;
8657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008658
Douglas Gregor3e308b12012-02-14 19:27:52 +00008659 if (ShouldExpand) {
8660 // The transform has determined that we should perform an expansion;
8661 // transform and capture each of the arguments.
8662 // expansion of the pattern. Do so.
8663 VarDecl *Pack = C->getCapturedVar();
8664 for (unsigned I = 0; I != *NumExpansions; ++I) {
8665 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8666 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008667 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008668 Pack));
8669 if (!CapturedVar) {
8670 Invalid = true;
8671 continue;
8672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008673
Douglas Gregor3e308b12012-02-14 19:27:52 +00008674 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008675 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8676 }
Richard Smith9467be42014-06-06 17:33:35 +00008677
8678 // FIXME: Retain a pack expansion if RetainExpansion is true.
8679
Douglas Gregor3e308b12012-02-14 19:27:52 +00008680 continue;
8681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008682
Douglas Gregor3e308b12012-02-14 19:27:52 +00008683 EllipsisLoc = C->getEllipsisLoc();
8684 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008685
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008686 // Transform the captured variable.
8687 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008688 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008689 C->getCapturedVar()));
8690 if (!CapturedVar) {
8691 Invalid = true;
8692 continue;
8693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008694
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008695 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008696 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008697 }
8698 if (!FinishedExplicitCaptures)
8699 getSema().finishLambdaExplicitCaptures(LSI);
8700
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008701
8702 // Enter a new evaluation context to insulate the lambda from any
8703 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008704 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008705
8706 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008707 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008708 /*IsInstantiation=*/true);
8709 return ExprError();
8710 }
8711
8712 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008713 StmtResult Body = getDerived().TransformStmt(E->getBody());
8714 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008715 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008716 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008717 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008718 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008719
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008720 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008721 /*CurScope=*/nullptr,
8722 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008723}
8724
8725template<typename Derived>
8726ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008727TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008728 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008729 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8730 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008732
Douglas Gregora16548e2009-08-11 05:31:07 +00008733 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008734 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008735 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008736 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008737 &ArgumentChanged))
8738 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008739
Douglas Gregora16548e2009-08-11 05:31:07 +00008740 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008741 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008742 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008743 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008744
Douglas Gregora16548e2009-08-11 05:31:07 +00008745 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008746 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008747 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008748 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008749 E->getRParenLoc());
8750}
Mike Stump11289f42009-09-09 15:08:12 +00008751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008753ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008754TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008755 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008756 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008757 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008758 Expr *OldBase;
8759 QualType BaseType;
8760 QualType ObjectType;
8761 if (!E->isImplicitAccess()) {
8762 OldBase = E->getBase();
8763 Base = getDerived().TransformExpr(OldBase);
8764 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008766
John McCall2d74de92009-12-01 22:10:20 +00008767 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008768 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008769 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008770 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008771 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008772 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008773 ObjectTy,
8774 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008775 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008776 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008777
John McCallba7bf592010-08-24 05:47:05 +00008778 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008779 BaseType = ((Expr*) Base.get())->getType();
8780 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008781 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008782 BaseType = getDerived().TransformType(E->getBaseType());
8783 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8784 }
Mike Stump11289f42009-09-09 15:08:12 +00008785
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008786 // Transform the first part of the nested-name-specifier that qualifies
8787 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008788 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008789 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008790 E->getFirstQualifierFoundInScope(),
8791 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008792
Douglas Gregore16af532011-02-28 18:50:33 +00008793 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008794 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008795 QualifierLoc
8796 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8797 ObjectType,
8798 FirstQualifierInScope);
8799 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008800 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008801 }
Mike Stump11289f42009-09-09 15:08:12 +00008802
Abramo Bagnara7945c982012-01-27 09:46:47 +00008803 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8804
John McCall31f82722010-11-12 08:19:04 +00008805 // TODO: If this is a conversion-function-id, verify that the
8806 // destination type name (if present) resolves the same way after
8807 // instantiation as it did in the local scope.
8808
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008809 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008810 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008811 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008813
John McCall2d74de92009-12-01 22:10:20 +00008814 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008815 // This is a reference to a member without an explicitly-specified
8816 // template argument list. Optimize for this common case.
8817 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008818 Base.get() == OldBase &&
8819 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008820 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008821 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008822 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008823 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008824
John McCallb268a282010-08-23 23:25:46 +00008825 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008826 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008827 E->isArrow(),
8828 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008829 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008830 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008831 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008832 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008833 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008834 }
8835
John McCall6b51f282009-11-23 01:53:49 +00008836 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008837 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8838 E->getNumTemplateArgs(),
8839 TransArgs))
8840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008841
John McCallb268a282010-08-23 23:25:46 +00008842 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008843 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008844 E->isArrow(),
8845 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008846 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008847 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008848 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008849 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008850 &TransArgs);
8851}
8852
8853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008855TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008856 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008857 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008858 QualType BaseType;
8859 if (!Old->isImplicitAccess()) {
8860 Base = getDerived().TransformExpr(Old->getBase());
8861 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008862 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008863 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008864 Old->isArrow());
8865 if (Base.isInvalid())
8866 return ExprError();
8867 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008868 } else {
8869 BaseType = getDerived().TransformType(Old->getBaseType());
8870 }
John McCall10eae182009-11-30 22:42:35 +00008871
Douglas Gregor0da1d432011-02-28 20:01:57 +00008872 NestedNameSpecifierLoc QualifierLoc;
8873 if (Old->getQualifierLoc()) {
8874 QualifierLoc
8875 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8876 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008877 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008878 }
8879
Abramo Bagnara7945c982012-01-27 09:46:47 +00008880 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8881
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008882 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008883 Sema::LookupOrdinaryName);
8884
8885 // Transform all the decls.
8886 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8887 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008888 NamedDecl *InstD = static_cast<NamedDecl*>(
8889 getDerived().TransformDecl(Old->getMemberLoc(),
8890 *I));
John McCall84d87672009-12-10 09:41:52 +00008891 if (!InstD) {
8892 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8893 // This can happen because of dependent hiding.
8894 if (isa<UsingShadowDecl>(*I))
8895 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008896 else {
8897 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008898 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008899 }
John McCall84d87672009-12-10 09:41:52 +00008900 }
John McCall10eae182009-11-30 22:42:35 +00008901
8902 // Expand using declarations.
8903 if (isa<UsingDecl>(InstD)) {
8904 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008905 for (auto *I : UD->shadows())
8906 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008907 continue;
8908 }
8909
8910 R.addDecl(InstD);
8911 }
8912
8913 R.resolveKind();
8914
Douglas Gregor9262f472010-04-27 18:19:34 +00008915 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008916 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008917 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008918 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008919 Old->getMemberLoc(),
8920 Old->getNamingClass()));
8921 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008922 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008923
Douglas Gregorda7be082010-04-27 16:10:10 +00008924 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008926
John McCall10eae182009-11-30 22:42:35 +00008927 TemplateArgumentListInfo TransArgs;
8928 if (Old->hasExplicitTemplateArgs()) {
8929 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8930 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008931 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8932 Old->getNumTemplateArgs(),
8933 TransArgs))
8934 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008935 }
John McCall38836f02010-01-15 08:34:02 +00008936
8937 // FIXME: to do this check properly, we will need to preserve the
8938 // first-qualifier-in-scope here, just in case we had a dependent
8939 // base (and therefore couldn't do the check) and a
8940 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008941 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008942
John McCallb268a282010-08-23 23:25:46 +00008943 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008944 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008945 Old->getOperatorLoc(),
8946 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008947 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008948 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008949 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008950 R,
8951 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008952 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00008953}
8954
8955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008956ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008957TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008958 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008959 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8960 if (SubExpr.isInvalid())
8961 return ExprError();
8962
8963 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008964 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008965
8966 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8967}
8968
8969template<typename Derived>
8970ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008971TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008972 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8973 if (Pattern.isInvalid())
8974 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008975
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008976 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008977 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008978
Douglas Gregorb8840002011-01-14 21:20:45 +00008979 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8980 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008981}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008982
8983template<typename Derived>
8984ExprResult
8985TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8986 // If E is not value-dependent, then nothing will change when we transform it.
8987 // Note: This is an instantiation-centric view.
8988 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008989 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008990
8991 // Note: None of the implementations of TryExpandParameterPacks can ever
8992 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008993 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008994 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8995 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008996 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008997 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008998 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008999 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009000 ShouldExpand, RetainExpansion,
9001 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009002 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009003
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009004 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009005 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009006
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009007 NamedDecl *Pack = E->getPack();
9008 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009009 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009010 Pack));
9011 if (!Pack)
9012 return ExprError();
9013 }
9014
Chad Rosier1dcde962012-08-08 18:46:20 +00009015
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009016 // We now know the length of the parameter pack, so build a new expression
9017 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009018 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9019 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009020 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009021}
9022
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009023template<typename Derived>
9024ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009025TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9026 SubstNonTypeTemplateParmPackExpr *E) {
9027 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009028 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009029}
9030
9031template<typename Derived>
9032ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009033TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9034 SubstNonTypeTemplateParmExpr *E) {
9035 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009036 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009037}
9038
9039template<typename Derived>
9040ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009041TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9042 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009043 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009044}
9045
9046template<typename Derived>
9047ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009048TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9049 MaterializeTemporaryExpr *E) {
9050 return getDerived().TransformExpr(E->GetTemporaryExpr());
9051}
Chad Rosier1dcde962012-08-08 18:46:20 +00009052
Douglas Gregorfe314812011-06-21 17:03:29 +00009053template<typename Derived>
9054ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009055TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9056 CXXStdInitializerListExpr *E) {
9057 return getDerived().TransformExpr(E->getSubExpr());
9058}
9059
9060template<typename Derived>
9061ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009062TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009063 return SemaRef.MaybeBindToTemporary(E);
9064}
9065
9066template<typename Derived>
9067ExprResult
9068TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009069 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009070}
9071
9072template<typename Derived>
9073ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009074TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9075 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9076 if (SubExpr.isInvalid())
9077 return ExprError();
9078
9079 if (!getDerived().AlwaysRebuild() &&
9080 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009081 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009082
9083 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009084}
9085
9086template<typename Derived>
9087ExprResult
9088TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9089 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009090 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009091 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009092 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009093 /*IsCall=*/false, Elements, &ArgChanged))
9094 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
Ted Kremeneke65b0862012-03-06 20:05:56 +00009096 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9097 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009098
Ted Kremeneke65b0862012-03-06 20:05:56 +00009099 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9100 Elements.data(),
9101 Elements.size());
9102}
9103
9104template<typename Derived>
9105ExprResult
9106TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009107 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009108 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009109 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009110 bool ArgChanged = false;
9111 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9112 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009113
Ted Kremeneke65b0862012-03-06 20:05:56 +00009114 if (OrigElement.isPackExpansion()) {
9115 // This key/value element is a pack expansion.
9116 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9117 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9118 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9119 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9120
9121 // Determine whether the set of unexpanded parameter packs can
9122 // and should be expanded.
9123 bool Expand = true;
9124 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009125 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9126 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009127 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9128 OrigElement.Value->getLocEnd());
9129 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9130 PatternRange,
9131 Unexpanded,
9132 Expand, RetainExpansion,
9133 NumExpansions))
9134 return ExprError();
9135
9136 if (!Expand) {
9137 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009138 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009139 // expansion.
9140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9141 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9142 if (Key.isInvalid())
9143 return ExprError();
9144
9145 if (Key.get() != OrigElement.Key)
9146 ArgChanged = true;
9147
9148 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9149 if (Value.isInvalid())
9150 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009151
Ted Kremeneke65b0862012-03-06 20:05:56 +00009152 if (Value.get() != OrigElement.Value)
9153 ArgChanged = true;
9154
Chad Rosier1dcde962012-08-08 18:46:20 +00009155 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009156 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9157 };
9158 Elements.push_back(Expansion);
9159 continue;
9160 }
9161
9162 // Record right away that the argument was changed. This needs
9163 // to happen even if the array expands to nothing.
9164 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009165
Ted Kremeneke65b0862012-03-06 20:05:56 +00009166 // The transform has determined that we should perform an elementwise
9167 // expansion of the pattern. Do so.
9168 for (unsigned I = 0; I != *NumExpansions; ++I) {
9169 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9170 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9171 if (Key.isInvalid())
9172 return ExprError();
9173
9174 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9175 if (Value.isInvalid())
9176 return ExprError();
9177
Chad Rosier1dcde962012-08-08 18:46:20 +00009178 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009179 Key.get(), Value.get(), SourceLocation(), NumExpansions
9180 };
9181
9182 // If any unexpanded parameter packs remain, we still have a
9183 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009184 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009185 if (Key.get()->containsUnexpandedParameterPack() ||
9186 Value.get()->containsUnexpandedParameterPack())
9187 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009188
Ted Kremeneke65b0862012-03-06 20:05:56 +00009189 Elements.push_back(Element);
9190 }
9191
Richard Smith9467be42014-06-06 17:33:35 +00009192 // FIXME: Retain a pack expansion if RetainExpansion is true.
9193
Ted Kremeneke65b0862012-03-06 20:05:56 +00009194 // We've finished with this pack expansion.
9195 continue;
9196 }
9197
9198 // Transform and check key.
9199 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9200 if (Key.isInvalid())
9201 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009202
Ted Kremeneke65b0862012-03-06 20:05:56 +00009203 if (Key.get() != OrigElement.Key)
9204 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
Ted Kremeneke65b0862012-03-06 20:05:56 +00009206 // Transform and check value.
9207 ExprResult Value
9208 = getDerived().TransformExpr(OrigElement.Value);
9209 if (Value.isInvalid())
9210 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009211
Ted Kremeneke65b0862012-03-06 20:05:56 +00009212 if (Value.get() != OrigElement.Value)
9213 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009214
9215 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009216 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009217 };
9218 Elements.push_back(Element);
9219 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009220
Ted Kremeneke65b0862012-03-06 20:05:56 +00009221 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9222 return SemaRef.MaybeBindToTemporary(E);
9223
9224 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9225 Elements.data(),
9226 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009227}
9228
Mike Stump11289f42009-09-09 15:08:12 +00009229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009231TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009232 TypeSourceInfo *EncodedTypeInfo
9233 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9234 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009236
Douglas Gregora16548e2009-08-11 05:31:07 +00009237 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009238 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009239 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009240
9241 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009242 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009243 E->getRParenLoc());
9244}
Mike Stump11289f42009-09-09 15:08:12 +00009245
Douglas Gregora16548e2009-08-11 05:31:07 +00009246template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009247ExprResult TreeTransform<Derived>::
9248TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009249 // This is a kind of implicit conversion, and it needs to get dropped
9250 // and recomputed for the same general reasons that ImplicitCastExprs
9251 // do, as well a more specific one: this expression is only valid when
9252 // it appears *immediately* as an argument expression.
9253 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009254}
9255
9256template<typename Derived>
9257ExprResult TreeTransform<Derived>::
9258TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009259 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009260 = getDerived().TransformType(E->getTypeInfoAsWritten());
9261 if (!TSInfo)
9262 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009263
John McCall31168b02011-06-15 23:02:42 +00009264 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009265 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009266 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009267
John McCall31168b02011-06-15 23:02:42 +00009268 if (!getDerived().AlwaysRebuild() &&
9269 TSInfo == E->getTypeInfoAsWritten() &&
9270 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009271 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009272
John McCall31168b02011-06-15 23:02:42 +00009273 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009274 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009275 Result.get());
9276}
9277
9278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009281 // Transform arguments.
9282 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009283 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009284 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009285 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009286 &ArgChanged))
9287 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009288
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009289 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9290 // Class message: transform the receiver type.
9291 TypeSourceInfo *ReceiverTypeInfo
9292 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9293 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009294 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009295
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009296 // If nothing changed, just retain the existing message send.
9297 if (!getDerived().AlwaysRebuild() &&
9298 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009299 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009300
9301 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009302 SmallVector<SourceLocation, 16> SelLocs;
9303 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009304 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9305 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009306 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009307 E->getMethodDecl(),
9308 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009309 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009310 E->getRightLoc());
9311 }
9312
9313 // Instance message: transform the receiver
9314 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9315 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009316 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009317 = getDerived().TransformExpr(E->getInstanceReceiver());
9318 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009319 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009320
9321 // If nothing changed, just retain the existing message send.
9322 if (!getDerived().AlwaysRebuild() &&
9323 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009324 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009325
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009326 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009327 SmallVector<SourceLocation, 16> SelLocs;
9328 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009329 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009330 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009331 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009332 E->getMethodDecl(),
9333 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009334 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009335 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009336}
9337
Mike Stump11289f42009-09-09 15:08:12 +00009338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009340TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009341 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009342}
9343
Mike Stump11289f42009-09-09 15:08:12 +00009344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009346TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009347 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009348}
9349
Mike Stump11289f42009-09-09 15:08:12 +00009350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009352TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009353 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009354 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009355 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009356 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009357
9358 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009359
Douglas Gregord51d90d2010-04-26 20:11:03 +00009360 // If nothing changed, just retain the existing expression.
9361 if (!getDerived().AlwaysRebuild() &&
9362 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009363 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009364
John McCallb268a282010-08-23 23:25:46 +00009365 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009366 E->getLocation(),
9367 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009368}
9369
Mike Stump11289f42009-09-09 15:08:12 +00009370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009372TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009373 // 'super' and types never change. Property never changes. Just
9374 // retain the existing expression.
9375 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009376 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009377
Douglas Gregor9faee212010-04-26 20:47:02 +00009378 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009379 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009380 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009381 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009382
Douglas Gregor9faee212010-04-26 20:47:02 +00009383 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009384
Douglas Gregor9faee212010-04-26 20:47:02 +00009385 // If nothing changed, just retain the existing expression.
9386 if (!getDerived().AlwaysRebuild() &&
9387 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009388 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009389
John McCallb7bd14f2010-12-02 01:19:52 +00009390 if (E->isExplicitProperty())
9391 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9392 E->getExplicitProperty(),
9393 E->getLocation());
9394
9395 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009396 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009397 E->getImplicitPropertyGetter(),
9398 E->getImplicitPropertySetter(),
9399 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009400}
9401
Mike Stump11289f42009-09-09 15:08:12 +00009402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009403ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009404TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9405 // Transform the base expression.
9406 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9407 if (Base.isInvalid())
9408 return ExprError();
9409
9410 // Transform the key expression.
9411 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9412 if (Key.isInvalid())
9413 return ExprError();
9414
9415 // If nothing changed, just retain the existing expression.
9416 if (!getDerived().AlwaysRebuild() &&
9417 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009418 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009419
Chad Rosier1dcde962012-08-08 18:46:20 +00009420 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009421 Base.get(), Key.get(),
9422 E->getAtIndexMethodDecl(),
9423 E->setAtIndexMethodDecl());
9424}
9425
9426template<typename Derived>
9427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009428TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009429 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009430 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009431 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009432 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009433
Douglas Gregord51d90d2010-04-26 20:11:03 +00009434 // If nothing changed, just retain the existing expression.
9435 if (!getDerived().AlwaysRebuild() &&
9436 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009437 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009438
John McCallb268a282010-08-23 23:25:46 +00009439 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009440 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009441 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009442}
9443
Mike Stump11289f42009-09-09 15:08:12 +00009444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009446TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009447 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009448 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009449 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009450 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009451 SubExprs, &ArgumentChanged))
9452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009453
Douglas Gregora16548e2009-08-11 05:31:07 +00009454 if (!getDerived().AlwaysRebuild() &&
9455 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009456 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009457
Douglas Gregora16548e2009-08-11 05:31:07 +00009458 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009459 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009460 E->getRParenLoc());
9461}
9462
Mike Stump11289f42009-09-09 15:08:12 +00009463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009464ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009465TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9466 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9467 if (SrcExpr.isInvalid())
9468 return ExprError();
9469
9470 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9471 if (!Type)
9472 return ExprError();
9473
9474 if (!getDerived().AlwaysRebuild() &&
9475 Type == E->getTypeSourceInfo() &&
9476 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009477 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009478
9479 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9480 SrcExpr.get(), Type,
9481 E->getRParenLoc());
9482}
9483
9484template<typename Derived>
9485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009486TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009487 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009488
Craig Topperc3ec1492014-05-26 06:22:03 +00009489 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009490 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9491
9492 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009493 blockScope->TheDecl->setBlockMissingReturnType(
9494 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009495
Chris Lattner01cf8db2011-07-20 06:58:45 +00009496 SmallVector<ParmVarDecl*, 4> params;
9497 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009498
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009499 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009500 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9501 oldBlock->param_begin(),
9502 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009503 nullptr, paramTypes, &params)) {
9504 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009505 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009506 }
John McCall490112f2011-02-04 18:33:18 +00009507
Jordan Rosea0a86be2013-03-08 22:25:36 +00009508 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009509 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009510 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009511
Jordan Rose5c382722013-03-08 21:51:21 +00009512 QualType functionType =
9513 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009514 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009515 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009516
9517 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009518 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009519 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009520
9521 if (!oldBlock->blockMissingReturnType()) {
9522 blockScope->HasImplicitReturnType = false;
9523 blockScope->ReturnType = exprResultType;
9524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009525
John McCall3882ace2011-01-05 12:14:39 +00009526 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009527 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009528 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009529 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009530 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009531 }
John McCall3882ace2011-01-05 12:14:39 +00009532
John McCall490112f2011-02-04 18:33:18 +00009533#ifndef NDEBUG
9534 // In builds with assertions, make sure that we captured everything we
9535 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009536 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009537 for (const auto &I : oldBlock->captures()) {
9538 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009539
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009540 // Ignore parameter packs.
9541 if (isa<ParmVarDecl>(oldCapture) &&
9542 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9543 continue;
John McCall490112f2011-02-04 18:33:18 +00009544
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009545 VarDecl *newCapture =
9546 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9547 oldCapture));
9548 assert(blockScope->CaptureMap.count(newCapture));
9549 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009550 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009551 }
9552#endif
9553
9554 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009555 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009556}
9557
Mike Stump11289f42009-09-09 15:08:12 +00009558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009559ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009560TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009561 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009562}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009563
9564template<typename Derived>
9565ExprResult
9566TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009567 QualType RetTy = getDerived().TransformType(E->getType());
9568 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009569 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009570 SubExprs.reserve(E->getNumSubExprs());
9571 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9572 SubExprs, &ArgumentChanged))
9573 return ExprError();
9574
9575 if (!getDerived().AlwaysRebuild() &&
9576 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009577 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009578
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009579 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009580 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009581}
Chad Rosier1dcde962012-08-08 18:46:20 +00009582
Douglas Gregora16548e2009-08-11 05:31:07 +00009583//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009584// Type reconstruction
9585//===----------------------------------------------------------------------===//
9586
Mike Stump11289f42009-09-09 15:08:12 +00009587template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009588QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9589 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009590 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009591 getDerived().getBaseEntity());
9592}
9593
Mike Stump11289f42009-09-09 15:08:12 +00009594template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009595QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9596 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009597 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009598 getDerived().getBaseEntity());
9599}
9600
Mike Stump11289f42009-09-09 15:08:12 +00009601template<typename Derived>
9602QualType
John McCall70dd5f62009-10-30 00:06:24 +00009603TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9604 bool WrittenAsLValue,
9605 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009606 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009607 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009608}
9609
9610template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009611QualType
John McCall70dd5f62009-10-30 00:06:24 +00009612TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9613 QualType ClassType,
9614 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009615 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9616 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009617}
9618
9619template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009620QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009621TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9622 ArrayType::ArraySizeModifier SizeMod,
9623 const llvm::APInt *Size,
9624 Expr *SizeExpr,
9625 unsigned IndexTypeQuals,
9626 SourceRange BracketsRange) {
9627 if (SizeExpr || !Size)
9628 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9629 IndexTypeQuals, BracketsRange,
9630 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009631
9632 QualType Types[] = {
9633 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9634 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9635 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009636 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009637 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009638 QualType SizeType;
9639 for (unsigned I = 0; I != NumTypes; ++I)
9640 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9641 SizeType = Types[I];
9642 break;
9643 }
Mike Stump11289f42009-09-09 15:08:12 +00009644
Eli Friedman9562f392012-01-25 23:20:27 +00009645 // Note that we can return a VariableArrayType here in the case where
9646 // the element type was a dependent VariableArrayType.
9647 IntegerLiteral *ArraySize
9648 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9649 /*FIXME*/BracketsRange.getBegin());
9650 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009651 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009652 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009653}
Mike Stump11289f42009-09-09 15:08:12 +00009654
Douglas Gregord6ff3322009-08-04 16:50:30 +00009655template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009656QualType
9657TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009658 ArrayType::ArraySizeModifier SizeMod,
9659 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009660 unsigned IndexTypeQuals,
9661 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009662 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009663 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009664}
9665
9666template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009667QualType
Mike Stump11289f42009-09-09 15:08:12 +00009668TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009669 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009670 unsigned IndexTypeQuals,
9671 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009672 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009673 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009674}
Mike Stump11289f42009-09-09 15:08:12 +00009675
Douglas Gregord6ff3322009-08-04 16:50:30 +00009676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009677QualType
9678TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009679 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009680 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009681 unsigned IndexTypeQuals,
9682 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009683 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009684 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009685 IndexTypeQuals, BracketsRange);
9686}
9687
9688template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009689QualType
9690TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009691 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009692 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009693 unsigned IndexTypeQuals,
9694 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009695 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009696 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009697 IndexTypeQuals, BracketsRange);
9698}
9699
9700template<typename Derived>
9701QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009702 unsigned NumElements,
9703 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009704 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009705 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009706}
Mike Stump11289f42009-09-09 15:08:12 +00009707
Douglas Gregord6ff3322009-08-04 16:50:30 +00009708template<typename Derived>
9709QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9710 unsigned NumElements,
9711 SourceLocation AttributeLoc) {
9712 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9713 NumElements, true);
9714 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009715 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9716 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009717 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009718}
Mike Stump11289f42009-09-09 15:08:12 +00009719
Douglas Gregord6ff3322009-08-04 16:50:30 +00009720template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009721QualType
9722TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009723 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009724 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009725 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009726}
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregord6ff3322009-08-04 16:50:30 +00009728template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009729QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9730 QualType T,
9731 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009732 const FunctionProtoType::ExtProtoInfo &EPI) {
9733 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009734 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009735 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009736 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009737}
Mike Stump11289f42009-09-09 15:08:12 +00009738
Douglas Gregord6ff3322009-08-04 16:50:30 +00009739template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009740QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9741 return SemaRef.Context.getFunctionNoProtoType(T);
9742}
9743
9744template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009745QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9746 assert(D && "no decl found");
9747 if (D->isInvalidDecl()) return QualType();
9748
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009749 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009750 TypeDecl *Ty;
9751 if (isa<UsingDecl>(D)) {
9752 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009753 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009754 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9755
9756 // A valid resolved using typename decl points to exactly one type decl.
9757 assert(++Using->shadow_begin() == Using->shadow_end());
9758 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009759
John McCallb96ec562009-12-04 22:46:56 +00009760 } else {
9761 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9762 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9763 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9764 }
9765
9766 return SemaRef.Context.getTypeDeclType(Ty);
9767}
9768
9769template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009770QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9771 SourceLocation Loc) {
9772 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009773}
9774
9775template<typename Derived>
9776QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9777 return SemaRef.Context.getTypeOfType(Underlying);
9778}
9779
9780template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009781QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9782 SourceLocation Loc) {
9783 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009784}
9785
9786template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009787QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9788 UnaryTransformType::UTTKind UKind,
9789 SourceLocation Loc) {
9790 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9791}
9792
9793template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009794QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009795 TemplateName Template,
9796 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009797 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009798 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009799}
Mike Stump11289f42009-09-09 15:08:12 +00009800
Douglas Gregor1135c352009-08-06 05:28:30 +00009801template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009802QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9803 SourceLocation KWLoc) {
9804 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9805}
9806
9807template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009808TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009809TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009810 bool TemplateKW,
9811 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009812 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009813 Template);
9814}
9815
9816template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009817TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009818TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9819 const IdentifierInfo &Name,
9820 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009821 QualType ObjectType,
9822 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009823 UnqualifiedId TemplateName;
9824 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009825 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009826 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009827 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009828 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009829 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009830 /*EnteringContext=*/false,
9831 Template);
John McCall31f82722010-11-12 08:19:04 +00009832 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009833}
Mike Stump11289f42009-09-09 15:08:12 +00009834
Douglas Gregora16548e2009-08-11 05:31:07 +00009835template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009836TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009837TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009838 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009839 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009840 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009841 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009842 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009843 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009844 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009845 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009846 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009847 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009848 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009849 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009850 /*EnteringContext=*/false,
9851 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009852 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009853}
Chad Rosier1dcde962012-08-08 18:46:20 +00009854
Douglas Gregor71395fa2009-11-04 00:56:37 +00009855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009856ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009857TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9858 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009859 Expr *OrigCallee,
9860 Expr *First,
9861 Expr *Second) {
9862 Expr *Callee = OrigCallee->IgnoreParenCasts();
9863 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009864
Douglas Gregora16548e2009-08-11 05:31:07 +00009865 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009866 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009867 if (!First->getType()->isOverloadableType() &&
9868 !Second->getType()->isOverloadableType())
9869 return getSema().CreateBuiltinArraySubscriptExpr(First,
9870 Callee->getLocStart(),
9871 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009872 } else if (Op == OO_Arrow) {
9873 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009874 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9875 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009876 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009877 // The argument is not of overloadable type, so try to create a
9878 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009879 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009880 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009881
John McCallb268a282010-08-23 23:25:46 +00009882 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009883 }
9884 } else {
John McCallb268a282010-08-23 23:25:46 +00009885 if (!First->getType()->isOverloadableType() &&
9886 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009887 // Neither of the arguments is an overloadable type, so try to
9888 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009889 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009890 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009891 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009892 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009894
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009895 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009896 }
9897 }
Mike Stump11289f42009-09-09 15:08:12 +00009898
9899 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009900 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009901 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009902
John McCallb268a282010-08-23 23:25:46 +00009903 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009904 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009905 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009906 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009907 // If we've resolved this to a particular non-member function, just call
9908 // that function. If we resolved it to a member function,
9909 // CreateOverloaded* will find that function for us.
9910 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9911 if (!isa<CXXMethodDecl>(ND))
9912 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009913 }
Mike Stump11289f42009-09-09 15:08:12 +00009914
Douglas Gregora16548e2009-08-11 05:31:07 +00009915 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009916 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009917 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009918
Douglas Gregora16548e2009-08-11 05:31:07 +00009919 // Create the overloaded operator invocation for unary operators.
9920 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009921 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009922 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009923 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009924 }
Mike Stump11289f42009-09-09 15:08:12 +00009925
Douglas Gregore9d62932011-07-15 16:25:15 +00009926 if (Op == OO_Subscript) {
9927 SourceLocation LBrace;
9928 SourceLocation RBrace;
9929
9930 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9931 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9932 LBrace = SourceLocation::getFromRawEncoding(
9933 NameLoc.CXXOperatorName.BeginOpNameLoc);
9934 RBrace = SourceLocation::getFromRawEncoding(
9935 NameLoc.CXXOperatorName.EndOpNameLoc);
9936 } else {
9937 LBrace = Callee->getLocStart();
9938 RBrace = OpLoc;
9939 }
9940
9941 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9942 First, Second);
9943 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009944
Douglas Gregora16548e2009-08-11 05:31:07 +00009945 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009946 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009947 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009948 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9949 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009951
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009952 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009953}
Mike Stump11289f42009-09-09 15:08:12 +00009954
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009955template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009956ExprResult
John McCallb268a282010-08-23 23:25:46 +00009957TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009958 SourceLocation OperatorLoc,
9959 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009960 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009961 TypeSourceInfo *ScopeType,
9962 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009963 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009964 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009965 QualType BaseType = Base->getType();
9966 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009967 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009968 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009969 !BaseType->getAs<PointerType>()->getPointeeType()
9970 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009971 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009972 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009973 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009974 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009975 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009976 /*FIXME?*/true);
9977 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009978
Douglas Gregor678f90d2010-02-25 01:56:36 +00009979 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009980 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9981 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9982 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9983 NameInfo.setNamedTypeInfo(DestroyedType);
9984
Richard Smith8e4a3862012-05-15 06:15:11 +00009985 // The scope type is now known to be a valid nested name specifier
9986 // component. Tack it on to the end of the nested name specifier.
9987 if (ScopeType)
9988 SS.Extend(SemaRef.Context, SourceLocation(),
9989 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009990
Abramo Bagnara7945c982012-01-27 09:46:47 +00009991 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009992 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009993 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009994 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00009995 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009996 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009997 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009998}
9999
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010000template<typename Derived>
10001StmtResult
10002TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010003 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010004 CapturedDecl *CD = S->getCapturedDecl();
10005 unsigned NumParams = CD->getNumParams();
10006 unsigned ContextParamPos = CD->getContextParamPosition();
10007 SmallVector<Sema::CapturedParamNameType, 4> Params;
10008 for (unsigned I = 0; I < NumParams; ++I) {
10009 if (I != ContextParamPos) {
10010 Params.push_back(
10011 std::make_pair(
10012 CD->getParam(I)->getName(),
10013 getDerived().TransformType(CD->getParam(I)->getType())));
10014 } else {
10015 Params.push_back(std::make_pair(StringRef(), QualType()));
10016 }
10017 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010018 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010019 S->getCapturedRegionKind(), Params);
Wei Pan17fbf6e2013-05-04 03:59:06 +000010020 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
10021
10022 if (Body.isInvalid()) {
10023 getSema().ActOnCapturedRegionError();
10024 return StmtError();
10025 }
10026
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010027 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010028}
10029
Douglas Gregord6ff3322009-08-04 16:50:30 +000010030} // end namespace clang
10031
10032#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H