blob: 9dfa8b73e0dd2fb1d8c3fe79ca9afb63d343df15 [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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000347 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
Hans Wennborge113c202014-09-18 16:01:32 +0000548 unsigned ThisTypeQuals);
Douglas Gregor3024f072012-04-16 07:05:22 +0000549
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
Nico Weberc153d242014-07-28 00:02:09 +0000563 QualType TransformDependentTemplateSpecializationType(
564 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
565 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566
John McCall58f10c32010-03-11 09:03:00 +0000567 /// \brief Transforms the parameters of a function type into the
568 /// given vectors.
569 ///
570 /// The result vectors should be kept in sync; null entries in the
571 /// variables vector are acceptable.
572 ///
573 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000574 bool TransformFunctionTypeParams(SourceLocation Loc,
575 ParmVarDecl **Params, unsigned NumParams,
576 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000577 SmallVectorImpl<QualType> &PTypes,
578 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000579
580 /// \brief Transforms a single function-type parameter. Return null
581 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000582 ///
583 /// \param indexAdjustment - A number to add to the parameter's
584 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000585 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000586 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000587 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000588 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000589
John McCall31f82722010-11-12 08:19:04 +0000590 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000591
John McCalldadc5752010-08-24 06:29:42 +0000592 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
593 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000594
595 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000596 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000597 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
598 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000599
Faisal Vali2cba1332013-10-23 06:44:28 +0000600 TemplateParameterList *TransformTemplateParameterList(
601 TemplateParameterList *TPL) {
602 return TPL;
603 }
604
Richard Smithdb2630f2012-10-21 03:28:35 +0000605 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000608 bool IsAddressOfOperand,
609 TypeSourceInfo **RecoveryTSI);
610
611 ExprResult TransformParenDependentScopeDeclRefExpr(
612 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
613 TypeSourceInfo **RecoveryTSI);
614
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000615 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000616
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
618// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000619#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000620 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000621 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000622#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000624 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000625#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000626#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000627
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000628#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000629 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000630 OMPClause *Transform ## Class(Class *S);
631#include "clang/Basic/OpenMPKinds.def"
632
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 /// \brief Build a new pointer type given its pointee type.
634 ///
635 /// By default, performs semantic analysis when building the pointer type.
636 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
639 /// \brief Build a new block pointer type given its pointee type.
640 ///
Mike Stump11289f42009-09-09 15:08:12 +0000641 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000643 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 ///
John McCall70dd5f62009-10-30 00:06:24 +0000647 /// By default, performs semantic analysis when building the
648 /// reference type. Subclasses may override this routine to provide
649 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000650 ///
John McCall70dd5f62009-10-30 00:06:24 +0000651 /// \param LValue whether the type was written with an lvalue sigil
652 /// or an rvalue sigil.
653 QualType RebuildReferenceType(QualType ReferentType,
654 bool LValue,
655 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000656
Douglas Gregord6ff3322009-08-04 16:50:30 +0000657 /// \brief Build a new member pointer type given the pointee type and the
658 /// class type it refers into.
659 ///
660 /// By default, performs semantic analysis when building the member pointer
661 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000662 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
663 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000664
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// \brief Build a new array type given the element type, size
666 /// modifier, size of the array (if known), size expression, and index type
667 /// qualifiers.
668 ///
669 /// By default, performs semantic analysis when building the array type.
670 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000671 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672 QualType RebuildArrayType(QualType ElementType,
673 ArrayType::ArraySizeModifier SizeMod,
674 const llvm::APInt *Size,
675 Expr *SizeExpr,
676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new constant array type given the element type, size
680 /// modifier, (known) size of the array, and index type qualifiers.
681 ///
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000684 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
686 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000689
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 /// \brief Build a new incomplete array type given the element type, size
691 /// modifier, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000695 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 /// size modifier, size expression, and index type qualifiers.
702 ///
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000705 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000707 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
710
Mike Stump11289f42009-09-09 15:08:12 +0000711 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 /// size modifier, size expression, and index type qualifiers.
713 ///
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000716 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000718 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 unsigned IndexTypeQuals,
720 SourceRange BracketsRange);
721
722 /// \brief Build a new vector type given the element type and
723 /// number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000727 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000728 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000729
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 /// \brief Build a new extended vector type given the element type and
731 /// number of elements.
732 ///
733 /// By default, performs semantic analysis when building the vector type.
734 /// Subclasses may override this routine to provide different behavior.
735 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
736 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000737
738 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// given the element type and number of elements.
740 ///
741 /// By default, performs semantic analysis when building the vector type.
742 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000743 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000744 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 /// \brief Build a new function type.
748 ///
749 /// By default, performs semantic analysis when building the function type.
750 /// Subclasses may override this routine to provide different behavior.
751 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000752 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000753 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000754
John McCall550e0c22009-10-21 00:40:46 +0000755 /// \brief Build a new unprototyped function type.
756 QualType RebuildFunctionNoProtoType(QualType ResultType);
757
John McCallb96ec562009-12-04 22:46:56 +0000758 /// \brief Rebuild an unresolved typename type, given the decl that
759 /// the UnresolvedUsingTypenameDecl was transformed to.
760 QualType RebuildUnresolvedUsingType(Decl *D);
761
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000763 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 return SemaRef.Context.getTypeDeclType(Typedef);
765 }
766
767 /// \brief Build a new class/struct/union type.
768 QualType RebuildRecordType(RecordDecl *Record) {
769 return SemaRef.Context.getTypeDeclType(Record);
770 }
771
772 /// \brief Build a new Enum type.
773 QualType RebuildEnumType(EnumDecl *Enum) {
774 return SemaRef.Context.getTypeDeclType(Enum);
775 }
John McCallfcc33b02009-09-05 00:15:47 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, performs semantic analysis when building the typeof type.
780 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000781 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000782
Mike Stump11289f42009-09-09 15:08:12 +0000783 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000784 ///
785 /// By default, builds a new TypeOfType with the given underlying type.
786 QualType RebuildTypeOfType(QualType Underlying);
787
Alexis Hunte852b102011-05-24 22:41:36 +0000788 /// \brief Build a new unary transform type.
789 QualType RebuildUnaryTransformType(QualType BaseType,
790 UnaryTransformType::UTTKind UKind,
791 SourceLocation Loc);
792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 ///
795 /// By default, performs semantic analysis when building the decltype type.
796 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000797 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000798
Richard Smith74aeef52013-04-26 16:15:35 +0000799 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000800 ///
801 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000802 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000803 // Note, IsDependent is always false here: we implicitly convert an 'auto'
804 // which has been deduced to a dependent type into an undeduced 'auto', so
805 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000806 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
807 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000808 }
809
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 /// \brief Build a new template specialization type.
811 ///
812 /// By default, performs semantic analysis when building the template
813 /// specialization type. Subclasses may override this routine to provide
814 /// different behavior.
815 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000816 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000817 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000818
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000819 /// \brief Build a new parenthesized type.
820 ///
821 /// By default, builds a new ParenType type from the inner type.
822 /// Subclasses may override this routine to provide different behavior.
823 QualType RebuildParenType(QualType InnerType) {
824 return SemaRef.Context.getParenType(InnerType);
825 }
826
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 /// \brief Build a new qualified name type.
828 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000829 /// By default, builds a new ElaboratedType type from the keyword,
830 /// the nested-name-specifier and the named type.
831 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000832 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
833 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000834 NestedNameSpecifierLoc QualifierLoc,
835 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000836 return SemaRef.Context.getElaboratedType(Keyword,
837 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000838 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000839 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000840
841 /// \brief Build a new typename type that refers to a template-id.
842 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000843 /// By default, builds a new DependentNameType type from the
844 /// nested-name-specifier and the given type. Subclasses may override
845 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000846 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 ElaboratedTypeKeyword Keyword,
848 NestedNameSpecifierLoc QualifierLoc,
849 const IdentifierInfo *Name,
850 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000851 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000852 // Rebuild the template name.
853 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000854 CXXScopeSpec SS;
855 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000856 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000857 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
858 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000859
Douglas Gregora7a795b2011-03-01 20:11:18 +0000860 if (InstName.isNull())
861 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000862
Douglas Gregora7a795b2011-03-01 20:11:18 +0000863 // If it's still dependent, make a dependent specialization.
864 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000865 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
866 QualifierLoc.getNestedNameSpecifier(),
867 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000868 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 // Otherwise, make an elaborated type wrapping a non-dependent
871 // specialization.
872 QualType T =
873 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
874 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000875
Craig Topperc3ec1492014-05-26 06:22:03 +0000876 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000877 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000878
879 return SemaRef.Context.getElaboratedType(Keyword,
880 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000881 T);
882 }
883
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884 /// \brief Build a new typename type that refers to an identifier.
885 ///
886 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000888 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000889 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 NestedNameSpecifierLoc QualifierLoc,
892 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000893 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000894 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000895 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000896
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000897 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000898 // If the name is still dependent, just build a new dependent name type.
899 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 return SemaRef.Context.getDependentNameType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000902 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000903 }
904
Abramo Bagnara6150c882010-05-11 21:36:43 +0000905 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000906 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000907 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000908
909 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
910
Abramo Bagnarad7548482010-05-19 21:37:53 +0000911 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000912 // into a non-dependent elaborated-type-specifier. Find the tag we're
913 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000914 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
916 if (!DC)
917 return QualType();
918
John McCallbf8c5192010-05-27 06:40:31 +0000919 if (SemaRef.RequireCompleteDeclContext(SS, DC))
920 return QualType();
921
Craig Topperc3ec1492014-05-26 06:22:03 +0000922 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 SemaRef.LookupQualifiedName(Result, DC);
924 switch (Result.getResultKind()) {
925 case LookupResult::NotFound:
926 case LookupResult::NotFoundInCurrentInstantiation:
927 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000928
Douglas Gregore677daf2010-03-31 22:19:08 +0000929 case LookupResult::Found:
930 Tag = Result.getAsSingle<TagDecl>();
931 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000932
Douglas Gregore677daf2010-03-31 22:19:08 +0000933 case LookupResult::FoundOverloaded:
934 case LookupResult::FoundUnresolvedValue:
935 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000936
Douglas Gregore677daf2010-03-31 22:19:08 +0000937 case LookupResult::Ambiguous:
938 // Let the LookupResult structure handle ambiguities.
939 return QualType();
940 }
941
942 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000943 // Check where the name exists but isn't a tag type and use that to emit
944 // better diagnostics.
945 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::Found:
949 case LookupResult::FoundOverloaded:
950 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000951 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000952 unsigned Kind = 0;
953 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000954 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
955 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000956 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
957 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
958 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000959 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000960 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000961 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000962 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000963 break;
964 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 return QualType();
966 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000967
Richard Trieucaa33d32011-06-10 03:11:26 +0000968 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
969 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000970 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000971 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
972 return QualType();
973 }
974
975 // Build the elaborated-type-specifier type.
976 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000977 return SemaRef.Context.getElaboratedType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000979 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregor822d0302011-01-12 17:07:58 +0000982 /// \brief Build a new pack expansion type.
983 ///
984 /// By default, builds a new PackExpansionType type from the given pattern.
985 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000986 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000987 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000988 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000989 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000990 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
991 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000992 }
993
Eli Friedman0dfb8892011-10-06 23:00:33 +0000994 /// \brief Build a new atomic type given its value type.
995 ///
996 /// By default, performs semantic analysis when building the atomic type.
997 /// Subclasses may override this routine to provide different behavior.
998 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
999
Douglas Gregor71dc5092009-08-06 06:41:21 +00001000 /// \brief Build a new template name given a nested name specifier, a flag
1001 /// indicating whether the "template" keyword was provided, and the template
1002 /// that the template name refers to.
1003 ///
1004 /// By default, builds the new template name directly. Subclasses may override
1005 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001006 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001007 bool TemplateKW,
1008 TemplateDecl *Template);
1009
Douglas Gregor71dc5092009-08-06 06:41:21 +00001010 /// \brief Build a new template name given a nested name specifier and the
1011 /// name that is referred to as a template.
1012 ///
1013 /// By default, performs semantic analysis to determine whether the name can
1014 /// be resolved to a specific template, then builds the appropriate kind of
1015 /// template name. Subclasses may override this routine to provide different
1016 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001017 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1018 const IdentifierInfo &Name,
1019 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001020 QualType ObjectType,
1021 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregor71395fa2009-11-04 00:56:37 +00001023 /// \brief Build a new template name given a nested name specifier and the
1024 /// overloaded operator name that is referred to as a template.
1025 ///
1026 /// By default, performs semantic analysis to determine whether the name can
1027 /// be resolved to a specific template, then builds the appropriate kind of
1028 /// template name. Subclasses may override this routine to provide different
1029 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001030 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001031 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001032 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001033 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001034
1035 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001036 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001037 ///
1038 /// By default, performs semantic analysis to determine whether the name can
1039 /// be resolved to a specific template, then builds the appropriate kind of
1040 /// template name. Subclasses may override this routine to provide different
1041 /// behavior.
1042 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1043 const TemplateArgument &ArgPack) {
1044 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1045 }
1046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new compound statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 MultiStmtArg Statements,
1053 SourceLocation RBraceLoc,
1054 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001055 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 IsStmtExpr);
1057 }
1058
1059 /// \brief Build a new case statement.
1060 ///
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001063 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001064 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001065 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001066 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001068 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001069 ColonLoc);
1070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Attach the body to a new case statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001077 getSema().ActOnCaseStmtBody(S, Body);
1078 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
Mike Stump11289f42009-09-09 15:08:12 +00001080
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /// \brief Build a new default statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Stmt *SubStmt) {
1088 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001089 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 }
Mike Stump11289f42009-09-09 15:08:12 +00001091
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 /// \brief Build a new label statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001096 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1097 SourceLocation ColonLoc, Stmt *SubStmt) {
1098 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 }
Mike Stump11289f42009-09-09 15:08:12 +00001100
Richard Smithc202b282012-04-14 00:33:13 +00001101 /// \brief Build a new label statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001105 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1106 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001107 Stmt *SubStmt) {
1108 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1109 }
1110
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 /// \brief Build a new "if" statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001116 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001117 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001118 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Start building a new switch statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001126 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001127 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001128 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001129 }
Mike Stump11289f42009-09-09 15:08:12 +00001130
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 /// \brief Attach the body to the switch statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001135 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001136 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001137 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 }
1139
1140 /// \brief Build a new while statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001144 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1145 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001146 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 }
Mike Stump11289f42009-09-09 15:08:12 +00001148
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 /// \brief Build a new do-while statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001153 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001154 SourceLocation WhileLoc, SourceLocation LParenLoc,
1155 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001156 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1157 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001158 }
1159
1160 /// \brief Build a new for statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001164 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001166 VarDecl *CondVar, Sema::FullExprArg Inc,
1167 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001168 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001169 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new goto statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001176 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1177 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001178 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001179 }
1180
1181 /// \brief Build a new indirect goto statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001186 SourceLocation StarLoc,
1187 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 /// \brief Build a new return statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001195 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001196 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 }
Mike Stump11289f42009-09-09 15:08:12 +00001198
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 /// \brief Build a new declaration statement.
1200 ///
1201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001203 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001204 SourceLocation StartLoc, SourceLocation EndLoc) {
1205 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001206 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Anders Carlssonaaeef072010-01-24 05:50:09 +00001209 /// \brief Build a new inline asm statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001213 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1214 bool IsVolatile, unsigned NumOutputs,
1215 unsigned NumInputs, IdentifierInfo **Names,
1216 MultiExprArg Constraints, MultiExprArg Exprs,
1217 Expr *AsmString, MultiExprArg Clobbers,
1218 SourceLocation RParenLoc) {
1219 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1220 NumInputs, Names, Constraints, Exprs,
1221 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001222 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001223
Chad Rosier32503022012-06-11 20:47:18 +00001224 /// \brief Build a new MS style inline asm statement.
1225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001228 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001229 ArrayRef<Token> AsmToks,
1230 StringRef AsmString,
1231 unsigned NumOutputs, unsigned NumInputs,
1232 ArrayRef<StringRef> Constraints,
1233 ArrayRef<StringRef> Clobbers,
1234 ArrayRef<Expr*> Exprs,
1235 SourceLocation EndLoc) {
1236 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1237 NumOutputs, NumInputs,
1238 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001239 }
1240
James Dennett2a4d13c2012-06-15 07:13:21 +00001241 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001246 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001247 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001248 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001249 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001250 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001251 }
1252
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001253 /// \brief Rebuild an Objective-C exception declaration.
1254 ///
1255 /// By default, performs semantic analysis to build the new declaration.
1256 /// Subclasses may override this routine to provide different behavior.
1257 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1258 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001259 return getSema().BuildObjCExceptionDecl(TInfo, T,
1260 ExceptionDecl->getInnerLocStart(),
1261 ExceptionDecl->getLocation(),
1262 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001264
James Dennett2a4d13c2012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001269 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001270 SourceLocation RParenLoc,
1271 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001272 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001273 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001274 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001276
James Dennett2a4d13c2012-06-15 07:13:21 +00001277 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001281 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001282 Stmt *Body) {
1283 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001285
James Dennett2a4d13c2012-06-15 07:13:21 +00001286 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001291 Expr *Operand) {
1292 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001293 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001294
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001295 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001299 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001300 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001301 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001302 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001303 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001304 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1305 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001306 }
1307
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001308 /// \brief Build a new OpenMP 'if' clause.
1309 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001310 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001311 /// Subclasses may override this routine to provide different behavior.
1312 OMPClause *RebuildOMPIfClause(Expr *Condition,
1313 SourceLocation StartLoc,
1314 SourceLocation LParenLoc,
1315 SourceLocation EndLoc) {
1316 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1317 LParenLoc, EndLoc);
1318 }
1319
Alexey Bataev3778b602014-07-17 07:32:53 +00001320 /// \brief Build a new OpenMP 'final' clause.
1321 ///
1322 /// By default, performs semantic analysis to build the new OpenMP clause.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1325 SourceLocation LParenLoc,
1326 SourceLocation EndLoc) {
1327 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1328 EndLoc);
1329 }
1330
Alexey Bataev568a8332014-03-06 06:15:19 +00001331 /// \brief Build a new OpenMP 'num_threads' clause.
1332 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001333 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1340 LParenLoc, EndLoc);
1341 }
1342
Alexey Bataev62c87d22014-03-21 04:51:18 +00001343 /// \brief Build a new OpenMP 'safelen' clause.
1344 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001345 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1351 }
1352
Alexander Musman8bd31e62014-05-27 15:12:19 +00001353 /// \brief Build a new OpenMP 'collapse' clause.
1354 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001355 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001356 /// Subclasses may override this routine to provide different behavior.
1357 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1361 EndLoc);
1362 }
1363
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001364 /// \brief Build a new OpenMP 'default' clause.
1365 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001366 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001367 /// Subclasses may override this routine to provide different behavior.
1368 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1369 SourceLocation KindKwLoc,
1370 SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1374 StartLoc, LParenLoc, EndLoc);
1375 }
1376
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001377 /// \brief Build a new OpenMP 'proc_bind' clause.
1378 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001379 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1382 SourceLocation KindKwLoc,
1383 SourceLocation StartLoc,
1384 SourceLocation LParenLoc,
1385 SourceLocation EndLoc) {
1386 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1387 StartLoc, LParenLoc, EndLoc);
1388 }
1389
Alexey Bataev56dafe82014-06-20 07:16:17 +00001390 /// \brief Build a new OpenMP 'schedule' clause.
1391 ///
1392 /// By default, performs semantic analysis to build the new OpenMP clause.
1393 /// Subclasses may override this routine to provide different behavior.
1394 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1395 Expr *ChunkSize,
1396 SourceLocation StartLoc,
1397 SourceLocation LParenLoc,
1398 SourceLocation KindLoc,
1399 SourceLocation CommaLoc,
1400 SourceLocation EndLoc) {
1401 return getSema().ActOnOpenMPScheduleClause(
1402 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1403 }
1404
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001405 /// \brief Build a new OpenMP 'private' clause.
1406 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001407 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001408 /// Subclasses may override this routine to provide different behavior.
1409 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1410 SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1414 EndLoc);
1415 }
1416
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001417 /// \brief Build a new OpenMP 'firstprivate' clause.
1418 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001419 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001420 /// Subclasses may override this routine to provide different behavior.
1421 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1422 SourceLocation StartLoc,
1423 SourceLocation LParenLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1426 EndLoc);
1427 }
1428
Alexander Musman1bb328c2014-06-04 13:06:39 +00001429 /// \brief Build a new OpenMP 'lastprivate' clause.
1430 ///
1431 /// By default, performs semantic analysis to build the new OpenMP clause.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1438 EndLoc);
1439 }
1440
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001441 /// \brief Build a new OpenMP 'shared' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001444 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001445 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1450 EndLoc);
1451 }
1452
Alexey Bataevc5e02582014-06-16 07:08:35 +00001453 /// \brief Build a new OpenMP 'reduction' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new statement.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1458 SourceLocation StartLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation ColonLoc,
1461 SourceLocation EndLoc,
1462 CXXScopeSpec &ReductionIdScopeSpec,
1463 const DeclarationNameInfo &ReductionId) {
1464 return getSema().ActOnOpenMPReductionClause(
1465 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1466 ReductionId);
1467 }
1468
Alexander Musman8dba6642014-04-22 13:09:42 +00001469 /// \brief Build a new OpenMP 'linear' clause.
1470 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001471 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001472 /// Subclasses may override this routine to provide different behavior.
1473 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation ColonLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1479 ColonLoc, EndLoc);
1480 }
1481
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001482 /// \brief Build a new OpenMP 'aligned' clause.
1483 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001484 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001485 /// Subclasses may override this routine to provide different behavior.
1486 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1487 SourceLocation StartLoc,
1488 SourceLocation LParenLoc,
1489 SourceLocation ColonLoc,
1490 SourceLocation EndLoc) {
1491 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1492 LParenLoc, ColonLoc, EndLoc);
1493 }
1494
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001495 /// \brief Build a new OpenMP 'copyin' clause.
1496 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001497 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001498 /// Subclasses may override this routine to provide different behavior.
1499 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1500 SourceLocation StartLoc,
1501 SourceLocation LParenLoc,
1502 SourceLocation EndLoc) {
1503 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1504 EndLoc);
1505 }
1506
Alexey Bataevbae9a792014-06-27 10:37:06 +00001507 /// \brief Build a new OpenMP 'copyprivate' clause.
1508 ///
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1512 SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1516 EndLoc);
1517 }
1518
Alexey Bataev6125da92014-07-21 11:26:11 +00001519 /// \brief Build a new OpenMP 'flush' pseudo clause.
1520 ///
1521 /// By default, performs semantic analysis to build the new OpenMP clause.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1528 EndLoc);
1529 }
1530
James Dennett2a4d13c2012-06-15 07:13:21 +00001531 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001532 ///
1533 /// By default, performs semantic analysis to build the new statement.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1536 Expr *object) {
1537 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1538 }
1539
James Dennett2a4d13c2012-06-15 07:13:21 +00001540 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001541 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001542 /// By default, performs semantic analysis to build the new statement.
1543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001544 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001545 Expr *Object, Stmt *Body) {
1546 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001547 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001548
James Dennett2a4d13c2012-06-15 07:13:21 +00001549 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1553 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1554 Stmt *Body) {
1555 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1556 }
John McCall53848232011-07-27 01:07:15 +00001557
Douglas Gregorf68a5082010-04-22 23:10:45 +00001558 /// \brief Build a new Objective-C fast enumeration statement.
1559 ///
1560 /// By default, performs semantic analysis to build the new statement.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001563 Stmt *Element,
1564 Expr *Collection,
1565 SourceLocation RParenLoc,
1566 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001567 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001568 Element,
John McCallb268a282010-08-23 23:25:46 +00001569 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001570 RParenLoc);
1571 if (ForEachStmt.isInvalid())
1572 return StmtError();
1573
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001574 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001576
Douglas Gregorebe10102009-08-20 07:17:43 +00001577 /// \brief Build a new C++ exception declaration.
1578 ///
1579 /// By default, performs semantic analysis to build the new decaration.
1580 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001581 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001582 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001583 SourceLocation StartLoc,
1584 SourceLocation IdLoc,
1585 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001586 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001587 StartLoc, IdLoc, Id);
1588 if (Var)
1589 getSema().CurContext->addDecl(Var);
1590 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001591 }
1592
1593 /// \brief Build a new C++ catch statement.
1594 ///
1595 /// By default, performs semantic analysis to build the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001598 VarDecl *ExceptionDecl,
1599 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001600 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1601 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001602 }
Mike Stump11289f42009-09-09 15:08:12 +00001603
Douglas Gregorebe10102009-08-20 07:17:43 +00001604 /// \brief Build a new C++ try statement.
1605 ///
1606 /// By default, performs semantic analysis to build the new statement.
1607 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001608 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1609 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001610 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001611 }
Mike Stump11289f42009-09-09 15:08:12 +00001612
Richard Smith02e85f32011-04-14 22:09:26 +00001613 /// \brief Build a new C++0x range-based for statement.
1614 ///
1615 /// By default, performs semantic analysis to build the new statement.
1616 /// Subclasses may override this routine to provide different behavior.
1617 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1618 SourceLocation ColonLoc,
1619 Stmt *Range, Stmt *BeginEnd,
1620 Expr *Cond, Expr *Inc,
1621 Stmt *LoopVar,
1622 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001623 // If we've just learned that the range is actually an Objective-C
1624 // collection, treat this as an Objective-C fast enumeration loop.
1625 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1626 if (RangeStmt->isSingleDecl()) {
1627 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001628 if (RangeVar->isInvalidDecl())
1629 return StmtError();
1630
Douglas Gregorf7106af2013-04-08 18:40:13 +00001631 Expr *RangeExpr = RangeVar->getInit();
1632 if (!RangeExpr->isTypeDependent() &&
1633 RangeExpr->getType()->isObjCObjectPointerType())
1634 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1635 RParenLoc);
1636 }
1637 }
1638 }
1639
Richard Smith02e85f32011-04-14 22:09:26 +00001640 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001641 Cond, Inc, LoopVar, RParenLoc,
1642 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001643 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001644
1645 /// \brief Build a new C++0x range-based for statement.
1646 ///
1647 /// By default, performs semantic analysis to build the new statement.
1648 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001649 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001650 bool IsIfExists,
1651 NestedNameSpecifierLoc QualifierLoc,
1652 DeclarationNameInfo NameInfo,
1653 Stmt *Nested) {
1654 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1655 QualifierLoc, NameInfo, Nested);
1656 }
1657
Richard Smith02e85f32011-04-14 22:09:26 +00001658 /// \brief Attach body to a C++0x range-based for statement.
1659 ///
1660 /// By default, performs semantic analysis to finish the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
1662 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1663 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001665
David Majnemerfad8f482013-10-15 09:33:02 +00001666 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001667 Stmt *TryBlock, Stmt *Handler) {
1668 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001669 }
1670
David Majnemerfad8f482013-10-15 09:33:02 +00001671 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001672 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001673 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001674 }
1675
David Majnemerfad8f482013-10-15 09:33:02 +00001676 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1677 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001678 }
1679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 /// \brief Build a new expression that references a declaration.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001685 LookupResult &R,
1686 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001687 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1688 }
1689
1690
1691 /// \brief Build a new expression that references a declaration.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001695 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001696 ValueDecl *VD,
1697 const DeclarationNameInfo &NameInfo,
1698 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001699 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001700 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001701
1702 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001703
1704 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 }
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001708 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001713 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
1715
Douglas Gregorad8a3362009-09-04 17:36:40 +00001716 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001720 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001721 SourceLocation OperatorLoc,
1722 bool isArrow,
1723 CXXScopeSpec &SS,
1724 TypeSourceInfo *ScopeType,
1725 SourceLocation CCLoc,
1726 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001727 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001728
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001730 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001733 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001734 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001735 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001736 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
Mike Stump11289f42009-09-09 15:08:12 +00001738
Douglas Gregor882211c2010-04-28 22:16:22 +00001739 /// \brief Build a new builtin offsetof expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001744 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001745 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001746 unsigned NumComponents,
1747 SourceLocation RParenLoc) {
1748 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1749 NumComponents, RParenLoc);
1750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001751
1752 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001753 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001757 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1758 SourceLocation OpLoc,
1759 UnaryExprOrTypeTrait ExprKind,
1760 SourceRange R) {
1761 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 }
1763
Peter Collingbournee190dee2011-03-11 19:24:49 +00001764 /// \brief Build a new sizeof, alignof or vec step expression with an
1765 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001766 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001769 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1770 UnaryExprOrTypeTrait ExprKind,
1771 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001773 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001776
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001777 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 }
Mike Stump11289f42009-09-09 15:08:12 +00001779
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001781 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001784 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001786 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001788 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001789 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 RBracketLoc);
1791 }
1792
1793 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001794 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001797 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001799 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001800 Expr *ExecConfig = nullptr) {
1801 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001802 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 }
1804
1805 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001806 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001810 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001811 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001812 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001813 const DeclarationNameInfo &MemberNameInfo,
1814 ValueDecl *Member,
1815 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001816 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001817 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001818 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1819 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001820 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001821 // We have a reference to an unnamed field. This is always the
1822 // base of an anonymous struct/union member access, i.e. the
1823 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001824 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001825 assert(Member->getType()->isRecordType() &&
1826 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001827
Richard Smithcab9a7d2011-10-26 19:06:56 +00001828 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001829 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001830 QualifierLoc.getNestedNameSpecifier(),
1831 FoundDecl, Member);
1832 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001833 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001834 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001835 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001836 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001837 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001838 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001839 cast<FieldDecl>(Member)->getType(),
1840 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001841 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001844 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001845 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001846
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001847 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001848 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001849
John McCall16df1e52010-03-30 21:47:33 +00001850 // FIXME: this involves duplicating earlier analysis in a lot of
1851 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001852 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001853 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001854 R.resolveKind();
1855
John McCallb268a282010-08-23 23:25:46 +00001856 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001857 SS, TemplateKWLoc,
1858 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001859 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001863 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001866 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001867 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001868 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001869 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 }
1871
1872 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001873 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001877 SourceLocation QuestionLoc,
1878 Expr *LHS,
1879 SourceLocation ColonLoc,
1880 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001881 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1882 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 }
1884
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001886 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001890 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001892 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001893 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001894 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 }
Mike Stump11289f42009-09-09 15:08:12 +00001896
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001898 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001901 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001902 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001904 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001905 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001906 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 }
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001910 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 SourceLocation OpLoc,
1915 SourceLocation AccessorLoc,
1916 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001917
John McCall10eae182009-11-30 22:42:35 +00001918 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001919 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001920 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001921 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001922 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001923 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001924 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001925 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 }
Mike Stump11289f42009-09-09 15:08:12 +00001927
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001929 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001932 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001933 MultiExprArg Inits,
1934 SourceLocation RBraceLoc,
1935 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001936 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001937 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001938 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001939 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001940
Douglas Gregord3d93062009-11-09 17:16:50 +00001941 // Patch in the result type we were given, which may have been computed
1942 // when the initial InitListExpr was built.
1943 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1944 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001945 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001949 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 MultiExprArg ArrayExprs,
1954 SourceLocation EqualOrColonLoc,
1955 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001956 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001959 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001962
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001963 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 }
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001967 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// By default, builds the implicit value initialization without performing
1969 /// any semantic analysis. Subclasses may override this routine to provide
1970 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001972 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 }
Mike Stump11289f42009-09-09 15:08:12 +00001974
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001976 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001980 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001981 SourceLocation RParenLoc) {
1982 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001983 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001984 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 }
1986
1987 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001988 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001991 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001992 MultiExprArg SubExprs,
1993 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001994 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 }
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001998 ///
1999 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// rather than attempting to map the label statement itself.
2001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002003 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002004 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 }
Mike Stump11289f42009-09-09 15:08:12 +00002006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002008 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002012 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002014 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// \brief Build a new __builtin_choose_expr expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002022 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 SourceLocation RParenLoc) {
2024 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002025 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 RParenLoc);
2027 }
Mike Stump11289f42009-09-09 15:08:12 +00002028
Peter Collingbourne91147592011-04-15 00:35:48 +00002029 /// \brief Build a new generic selection expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
2033 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2034 SourceLocation DefaultLoc,
2035 SourceLocation RParenLoc,
2036 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002037 ArrayRef<TypeSourceInfo *> Types,
2038 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002039 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002040 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002041 }
2042
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 /// \brief Build a new overloaded operator call expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// The semantic analysis provides the behavior of template instantiation,
2047 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002048 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 /// argument-dependent lookup, etc. Subclasses may override this routine to
2050 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002053 Expr *Callee,
2054 Expr *First,
2055 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002056
2057 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 /// reinterpret_cast.
2059 ///
2060 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002061 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 Stmt::StmtClass Class,
2065 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002066 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 SourceLocation RAngleLoc,
2068 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 SourceLocation RParenLoc) {
2071 switch (Class) {
2072 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002073 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002074 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002075 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076
2077 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002078 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002079 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002080 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002083 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002084 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002085 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002089 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002090 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002091 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002094 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 }
Mike Stump11289f42009-09-09 15:08:12 +00002097
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 /// \brief Build a new C++ static_cast expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002102 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002104 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 SourceLocation RAngleLoc,
2106 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002107 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002109 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002110 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002111 SourceRange(LAngleLoc, RAngleLoc),
2112 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 }
2114
2115 /// \brief Build a new C++ dynamic_cast expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002119 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002121 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 SourceLocation RAngleLoc,
2123 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002124 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002126 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002127 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002128 SourceRange(LAngleLoc, RAngleLoc),
2129 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 }
2131
2132 /// \brief Build a new C++ reinterpret_cast expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002138 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 SourceLocation RAngleLoc,
2140 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002141 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002143 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002144 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002145 SourceRange(LAngleLoc, RAngleLoc),
2146 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 }
2148
2149 /// \brief Build a new C++ const_cast expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002155 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 SourceLocation RAngleLoc,
2157 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002158 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002160 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002161 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002162 SourceRange(LAngleLoc, RAngleLoc),
2163 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 }
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 /// \brief Build a new C++ functional-style cast expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002170 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2171 SourceLocation LParenLoc,
2172 Expr *Sub,
2173 SourceLocation RParenLoc) {
2174 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002175 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 RParenLoc);
2177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 /// \brief Build a new C++ typeid(type) expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002184 SourceLocation TypeidLoc,
2185 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002187 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002188 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
Mike Stump11289f42009-09-09 15:08:12 +00002190
Francois Pichet9f4f2072010-09-08 12:20:18 +00002191
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 /// \brief Build a new C++ typeid(expr) expression.
2193 ///
2194 /// By default, performs semantic analysis to build the new expression.
2195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002197 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002198 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002200 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002201 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002202 }
2203
Francois Pichet9f4f2072010-09-08 12:20:18 +00002204 /// \brief Build a new C++ __uuidof(type) expression.
2205 ///
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
2208 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2209 SourceLocation TypeidLoc,
2210 TypeSourceInfo *Operand,
2211 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002212 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002213 RParenLoc);
2214 }
2215
2216 /// \brief Build a new C++ __uuidof(expr) expression.
2217 ///
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
2220 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2221 SourceLocation TypeidLoc,
2222 Expr *Operand,
2223 SourceLocation RParenLoc) {
2224 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2225 RParenLoc);
2226 }
2227
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 /// \brief Build a new C++ "this" expression.
2229 ///
2230 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002231 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002233 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002234 QualType ThisType,
2235 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002236 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002237 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 }
2239
2240 /// \brief Build a new C++ throw expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002244 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2245 bool IsThrownVariableInScope) {
2246 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
2248
2249 /// \brief Build a new C++ default-argument expression.
2250 ///
2251 /// By default, builds a new default-argument expression, which does not
2252 /// require any semantic analysis. Subclasses may override this routine to
2253 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002254 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002255 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002256 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 }
2258
Richard Smith852c9db2013-04-20 22:23:05 +00002259 /// \brief Build a new C++11 default-initialization expression.
2260 ///
2261 /// By default, builds a new default field initialization expression, which
2262 /// does not require any semantic analysis. Subclasses may override this
2263 /// routine to provide different behavior.
2264 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2265 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002266 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002267 }
2268
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// \brief Build a new C++ zero-initialization expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002273 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2274 SourceLocation LParenLoc,
2275 SourceLocation RParenLoc) {
2276 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002277 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 }
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 /// \brief Build a new C++ "new" expression.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002284 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002285 bool UseGlobal,
2286 SourceLocation PlacementLParen,
2287 MultiExprArg PlacementArgs,
2288 SourceLocation PlacementRParen,
2289 SourceRange TypeIdParens,
2290 QualType AllocatedType,
2291 TypeSourceInfo *AllocatedTypeInfo,
2292 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002293 SourceRange DirectInitRange,
2294 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002295 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002297 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002299 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002300 AllocatedType,
2301 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002302 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002303 DirectInitRange,
2304 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 }
Mike Stump11289f42009-09-09 15:08:12 +00002306
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 /// \brief Build a new C++ "delete" expression.
2308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002311 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 bool IsGlobalDelete,
2313 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002314 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002316 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 }
Mike Stump11289f42009-09-09 15:08:12 +00002318
Douglas Gregor29c42f22012-02-24 07:38:34 +00002319 /// \brief Build a new type trait expression.
2320 ///
2321 /// By default, performs semantic analysis to build the new expression.
2322 /// Subclasses may override this routine to provide different behavior.
2323 ExprResult RebuildTypeTrait(TypeTrait Trait,
2324 SourceLocation StartLoc,
2325 ArrayRef<TypeSourceInfo *> Args,
2326 SourceLocation RParenLoc) {
2327 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002329
John Wiegley6242b6a2011-04-28 00:16:57 +00002330 /// \brief Build a new array type trait expression.
2331 ///
2332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
2334 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2335 SourceLocation StartLoc,
2336 TypeSourceInfo *TSInfo,
2337 Expr *DimExpr,
2338 SourceLocation RParenLoc) {
2339 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2340 }
2341
John Wiegleyf9f65842011-04-25 06:54:41 +00002342 /// \brief Build a new expression trait expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
2346 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2347 SourceLocation StartLoc,
2348 Expr *Queried,
2349 SourceLocation RParenLoc) {
2350 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2351 }
2352
Mike Stump11289f42009-09-09 15:08:12 +00002353 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 /// expression.
2355 ///
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002358 ExprResult RebuildDependentScopeDeclRefExpr(
2359 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002360 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002361 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002362 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002363 bool IsAddressOfOperand,
2364 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002366 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002367
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002368 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002369 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2370 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002371
Reid Kleckner32506ed2014-06-12 23:03:48 +00002372 return getSema().BuildQualifiedDeclarationNameExpr(
2373 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 }
2375
2376 /// \brief Build a new template-id expression.
2377 ///
2378 /// By default, performs semantic analysis to build the new expression.
2379 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002380 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002381 SourceLocation TemplateKWLoc,
2382 LookupResult &R,
2383 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002384 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002385 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2386 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 }
2388
2389 /// \brief Build a new object-construction expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002394 SourceLocation Loc,
2395 CXXConstructorDecl *Constructor,
2396 bool IsElidable,
2397 MultiExprArg Args,
2398 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002399 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002400 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002401 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002402 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002403 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002404 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002405 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002406 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002407 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002408
Douglas Gregordb121ba2009-12-14 16:27:04 +00002409 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002410 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002411 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002412 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002413 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002414 RequiresZeroInit, ConstructKind,
2415 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 }
2417
2418 /// \brief Build a new object-construction expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002422 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2423 SourceLocation LParenLoc,
2424 MultiExprArg Args,
2425 SourceLocation RParenLoc) {
2426 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002428 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 RParenLoc);
2430 }
2431
2432 /// \brief Build a new object-construction expression.
2433 ///
2434 /// By default, performs semantic analysis to build the new expression.
2435 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002436 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2437 SourceLocation LParenLoc,
2438 MultiExprArg Args,
2439 SourceLocation RParenLoc) {
2440 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002442 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 RParenLoc);
2444 }
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 /// \brief Build a new member reference expression.
2447 ///
2448 /// By default, performs semantic analysis to build the new expression.
2449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002450 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002451 QualType BaseType,
2452 bool IsArrow,
2453 SourceLocation OperatorLoc,
2454 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002455 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002456 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002457 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002458 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002460 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002461
John McCallb268a282010-08-23 23:25:46 +00002462 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002463 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002464 SS, TemplateKWLoc,
2465 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002466 MemberNameInfo,
2467 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002468 }
2469
John McCall10eae182009-11-30 22:42:35 +00002470 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002471 ///
2472 /// By default, performs semantic analysis to build the new expression.
2473 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002474 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2475 SourceLocation OperatorLoc,
2476 bool IsArrow,
2477 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002478 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002479 NamedDecl *FirstQualifierInScope,
2480 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002481 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002482 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002483 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002484
John McCallb268a282010-08-23 23:25:46 +00002485 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002486 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002487 SS, TemplateKWLoc,
2488 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002489 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002490 }
Mike Stump11289f42009-09-09 15:08:12 +00002491
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002492 /// \brief Build a new noexcept expression.
2493 ///
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
2496 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2497 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2498 }
2499
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002500 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002501 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2502 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002503 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002504 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002505 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002506 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2507 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002508 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002509
2510 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2511 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002512 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002513 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002514
Patrick Beard0caa3942012-04-19 00:25:12 +00002515 /// \brief Build a new Objective-C boxed expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
2519 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2520 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002522
Ted Kremeneke65b0862012-03-06 20:05:56 +00002523 /// \brief Build a new Objective-C array literal.
2524 ///
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
2527 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2528 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002529 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002530 MultiExprArg(Elements, NumElements));
2531 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002532
2533 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002534 Expr *Base, Expr *Key,
2535 ObjCMethodDecl *getterMethod,
2536 ObjCMethodDecl *setterMethod) {
2537 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2538 getterMethod, setterMethod);
2539 }
2540
2541 /// \brief Build a new Objective-C dictionary literal.
2542 ///
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
2545 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2546 ObjCDictionaryElement *Elements,
2547 unsigned NumElements) {
2548 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2549 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002550
James Dennett2a4d13c2012-06-15 07:13:21 +00002551 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 ///
2553 /// By default, performs semantic analysis to build the new expression.
2554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002555 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002556 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002558 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002559 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002560
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002561 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002562 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002563 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002564 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002565 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002566 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002567 MultiExprArg Args,
2568 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002569 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2570 ReceiverTypeInfo->getType(),
2571 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002572 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002573 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002574 }
2575
2576 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002577 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002578 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002579 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002580 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002581 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002582 MultiExprArg Args,
2583 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002584 return SemaRef.BuildInstanceMessage(Receiver,
2585 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002586 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002587 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002588 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002589 }
2590
Douglas Gregord51d90d2010-04-26 20:11:03 +00002591 /// \brief Build a new Objective-C ivar reference expression.
2592 ///
2593 /// By default, performs semantic analysis to build the new expression.
2594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002595 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002596 SourceLocation IvarLoc,
2597 bool IsArrow, bool IsFreeIvar) {
2598 // FIXME: We lose track of the IsFreeIvar bit.
2599 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002600 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2601 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002602 /*FIXME:*/IvarLoc, IsArrow,
2603 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002604 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002605 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002606 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002607 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002608
2609 /// \brief Build a new Objective-C property reference expression.
2610 ///
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002613 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002614 ObjCPropertyDecl *Property,
2615 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002616 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002617 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2618 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2619 /*FIXME:*/PropertyLoc,
2620 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002621 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002622 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002623 NameInfo,
2624 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002625 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002626
John McCallb7bd14f2010-12-02 01:19:52 +00002627 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002628 ///
2629 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2632 ObjCMethodDecl *Getter,
2633 ObjCMethodDecl *Setter,
2634 SourceLocation PropertyLoc) {
2635 // Since these expressions can only be value-dependent, we do not
2636 // need to perform semantic analysis again.
2637 return Owned(
2638 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2639 VK_LValue, OK_ObjCProperty,
2640 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002641 }
2642
Douglas Gregord51d90d2010-04-26 20:11:03 +00002643 /// \brief Build a new Objective-C "isa" expression.
2644 ///
2645 /// By default, performs semantic analysis to build the new expression.
2646 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002647 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002648 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002649 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002650 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2651 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002652 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002653 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002654 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002655 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002656 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002658
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 /// \brief Build a new shuffle vector expression.
2660 ///
2661 /// By default, performs semantic analysis to build the new expression.
2662 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002663 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002664 MultiExprArg SubExprs,
2665 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002666 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002667 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2669 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2670 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002671 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002672
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002674 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002675 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2676 SemaRef.Context.BuiltinFnTy,
2677 VK_RValue, BuiltinLoc);
2678 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2679 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002680 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002681
2682 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002683 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002684 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002685 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002686
Douglas Gregora16548e2009-08-11 05:31:07 +00002687 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002688 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 }
John McCall31f82722010-11-12 08:19:04 +00002690
Hal Finkelc4d7c822013-09-18 03:29:45 +00002691 /// \brief Build a new convert vector expression.
2692 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2693 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2694 SourceLocation RParenLoc) {
2695 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2696 BuiltinLoc, RParenLoc);
2697 }
2698
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002699 /// \brief Build a new template argument pack expansion.
2700 ///
2701 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002702 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002703 /// different behavior.
2704 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002705 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002706 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002707 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002708 case TemplateArgument::Expression: {
2709 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002710 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2711 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002712 if (Result.isInvalid())
2713 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002714
Douglas Gregor98318c22011-01-03 21:37:45 +00002715 return TemplateArgumentLoc(Result.get(), Result.get());
2716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002717
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002718 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002719 return TemplateArgumentLoc(TemplateArgument(
2720 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002721 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002722 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002723 Pattern.getTemplateNameLoc(),
2724 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002725
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002726 case TemplateArgument::Null:
2727 case TemplateArgument::Integral:
2728 case TemplateArgument::Declaration:
2729 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002730 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002731 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002732 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002733
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002734 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002735 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002736 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002737 EllipsisLoc,
2738 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002739 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2740 Expansion);
2741 break;
2742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002743
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002744 return TemplateArgumentLoc();
2745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002746
Douglas Gregor968f23a2011-01-03 19:31:53 +00002747 /// \brief Build a new expression pack expansion.
2748 ///
2749 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002750 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002751 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002752 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002753 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002754 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002755 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002756
2757 /// \brief Build a new atomic operation expression.
2758 ///
2759 /// By default, performs semantic analysis to build the new expression.
2760 /// Subclasses may override this routine to provide different behavior.
2761 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2762 MultiExprArg SubExprs,
2763 QualType RetTy,
2764 AtomicExpr::AtomicOp Op,
2765 SourceLocation RParenLoc) {
2766 // Just create the expression; there is not any interesting semantic
2767 // analysis here because we can't actually build an AtomicExpr until
2768 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002769 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002770 RParenLoc);
2771 }
2772
John McCall31f82722010-11-12 08:19:04 +00002773private:
Douglas Gregor14454802011-02-25 02:25:35 +00002774 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2775 QualType ObjectType,
2776 NamedDecl *FirstQualifierInScope,
2777 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002778
2779 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2780 QualType ObjectType,
2781 NamedDecl *FirstQualifierInScope,
2782 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002783
2784 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2785 NamedDecl *FirstQualifierInScope,
2786 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002787};
Douglas Gregora16548e2009-08-11 05:31:07 +00002788
Douglas Gregorebe10102009-08-20 07:17:43 +00002789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002790StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002791 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002792 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002793
Douglas Gregorebe10102009-08-20 07:17:43 +00002794 switch (S->getStmtClass()) {
2795 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002796
Douglas Gregorebe10102009-08-20 07:17:43 +00002797 // Transform individual statement nodes
2798#define STMT(Node, Parent) \
2799 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002800#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002801#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002802#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002803
Douglas Gregorebe10102009-08-20 07:17:43 +00002804 // Transform expressions by calling TransformExpr.
2805#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002806#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002807#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002808#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002809 {
John McCalldadc5752010-08-24 06:29:42 +00002810 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002811 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002812 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002813
Richard Smith945f8d32013-01-14 22:39:08 +00002814 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002815 }
Mike Stump11289f42009-09-09 15:08:12 +00002816 }
2817
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002818 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002819}
Mike Stump11289f42009-09-09 15:08:12 +00002820
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002821template<typename Derived>
2822OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2823 if (!S)
2824 return S;
2825
2826 switch (S->getClauseKind()) {
2827 default: break;
2828 // Transform individual clause nodes
2829#define OPENMP_CLAUSE(Name, Class) \
2830 case OMPC_ ## Name : \
2831 return getDerived().Transform ## Class(cast<Class>(S));
2832#include "clang/Basic/OpenMPKinds.def"
2833 }
2834
2835 return S;
2836}
2837
Mike Stump11289f42009-09-09 15:08:12 +00002838
Douglas Gregore922c772009-08-04 22:27:00 +00002839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002840ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002841 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002842 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002843
2844 switch (E->getStmtClass()) {
2845 case Stmt::NoStmtClass: break;
2846#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002847#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002848#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002849 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002850#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002851 }
2852
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002853 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002854}
2855
2856template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002857ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002858 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002859 // Initializers are instantiated like expressions, except that various outer
2860 // layers are stripped.
2861 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002862 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002863
2864 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2865 Init = ExprTemp->getSubExpr();
2866
Richard Smithe6ca4752013-05-30 22:40:16 +00002867 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2868 Init = MTE->GetTemporaryExpr();
2869
Richard Smithd59b8322012-12-19 01:39:02 +00002870 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2871 Init = Binder->getSubExpr();
2872
2873 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2874 Init = ICE->getSubExprAsWritten();
2875
Richard Smithcc1b96d2013-06-12 22:31:48 +00002876 if (CXXStdInitializerListExpr *ILE =
2877 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002878 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002879
Richard Smithc6abd962014-07-25 01:12:44 +00002880 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002881 // InitListExprs. Other forms of copy-initialization will be a no-op if
2882 // the initializer is already the right type.
2883 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002884 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002885 return getDerived().TransformExpr(Init);
2886
2887 // Revert value-initialization back to empty parens.
2888 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2889 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002890 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002891 Parens.getEnd());
2892 }
2893
2894 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2895 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002896 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002897 SourceLocation());
2898
2899 // Revert initialization by constructor back to a parenthesized or braced list
2900 // of expressions. Any other form of initializer can just be reused directly.
2901 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002902 return getDerived().TransformExpr(Init);
2903
Richard Smithf8adcdc2014-07-17 05:12:35 +00002904 // If the initialization implicitly converted an initializer list to a
2905 // std::initializer_list object, unwrap the std::initializer_list too.
2906 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002907 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002908
Richard Smithd59b8322012-12-19 01:39:02 +00002909 SmallVector<Expr*, 8> NewArgs;
2910 bool ArgChanged = false;
2911 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002912 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002913 return ExprError();
2914
2915 // If this was list initialization, revert to list form.
2916 if (Construct->isListInitialization())
2917 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2918 Construct->getLocEnd(),
2919 Construct->getType());
2920
Richard Smithd59b8322012-12-19 01:39:02 +00002921 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002922 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002923 if (Parens.isInvalid()) {
2924 // This was a variable declaration's initialization for which no initializer
2925 // was specified.
2926 assert(NewArgs.empty() &&
2927 "no parens or braces but have direct init with arguments?");
2928 return ExprEmpty();
2929 }
Richard Smithd59b8322012-12-19 01:39:02 +00002930 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2931 Parens.getEnd());
2932}
2933
2934template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002935bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2936 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002937 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002938 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002939 bool *ArgChanged) {
2940 for (unsigned I = 0; I != NumInputs; ++I) {
2941 // If requested, drop call arguments that need to be dropped.
2942 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2943 if (ArgChanged)
2944 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002945
Douglas Gregora3efea12011-01-03 19:04:46 +00002946 break;
2947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Douglas Gregor968f23a2011-01-03 19:31:53 +00002949 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2950 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002951
Chris Lattner01cf8db2011-07-20 06:58:45 +00002952 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002953 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2954 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002955
Douglas Gregor968f23a2011-01-03 19:31:53 +00002956 // Determine whether the set of unexpanded parameter packs can and should
2957 // be expanded.
2958 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002959 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002960 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2961 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002962 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2963 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002964 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002965 Expand, RetainExpansion,
2966 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002967 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002968
Douglas Gregor968f23a2011-01-03 19:31:53 +00002969 if (!Expand) {
2970 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002971 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002972 // expansion.
2973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2974 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2975 if (OutPattern.isInvalid())
2976 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
2978 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002979 Expansion->getEllipsisLoc(),
2980 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002981 if (Out.isInvalid())
2982 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002983
Douglas Gregor968f23a2011-01-03 19:31:53 +00002984 if (ArgChanged)
2985 *ArgChanged = true;
2986 Outputs.push_back(Out.get());
2987 continue;
2988 }
John McCall542e7c62011-07-06 07:30:07 +00002989
2990 // Record right away that the argument was changed. This needs
2991 // to happen even if the array expands to nothing.
2992 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
Douglas Gregor968f23a2011-01-03 19:31:53 +00002994 // The transform has determined that we should perform an elementwise
2995 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002996 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002997 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2998 ExprResult Out = getDerived().TransformExpr(Pattern);
2999 if (Out.isInvalid())
3000 return true;
3001
Richard Smith9467be42014-06-06 17:33:35 +00003002 // FIXME: Can this happen? We should not try to expand the pack
3003 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003004 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003005 Out = getDerived().RebuildPackExpansion(
3006 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003007 if (Out.isInvalid())
3008 return true;
3009 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregor968f23a2011-01-03 19:31:53 +00003011 Outputs.push_back(Out.get());
3012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Richard Smith9467be42014-06-06 17:33:35 +00003014 // If we're supposed to retain a pack expansion, do so by temporarily
3015 // forgetting the partially-substituted parameter pack.
3016 if (RetainExpansion) {
3017 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3018
3019 ExprResult Out = getDerived().TransformExpr(Pattern);
3020 if (Out.isInvalid())
3021 return true;
3022
3023 Out = getDerived().RebuildPackExpansion(
3024 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3025 if (Out.isInvalid())
3026 return true;
3027
3028 Outputs.push_back(Out.get());
3029 }
3030
Douglas Gregor968f23a2011-01-03 19:31:53 +00003031 continue;
3032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003033
Richard Smithd59b8322012-12-19 01:39:02 +00003034 ExprResult Result =
3035 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3036 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003037 if (Result.isInvalid())
3038 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003039
Douglas Gregora3efea12011-01-03 19:04:46 +00003040 if (Result.get() != Inputs[I] && ArgChanged)
3041 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
3043 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003044 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
Douglas Gregora3efea12011-01-03 19:04:46 +00003046 return false;
3047}
3048
3049template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003050NestedNameSpecifierLoc
3051TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3052 NestedNameSpecifierLoc NNS,
3053 QualType ObjectType,
3054 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003055 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003056 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003057 Qualifier = Qualifier.getPrefix())
3058 Qualifiers.push_back(Qualifier);
3059
3060 CXXScopeSpec SS;
3061 while (!Qualifiers.empty()) {
3062 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3063 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
Douglas Gregor14454802011-02-25 02:25:35 +00003065 switch (QNNS->getKind()) {
3066 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003067 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003068 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003069 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003070 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003071 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003072 FirstQualifierInScope, false))
3073 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003074
Douglas Gregor14454802011-02-25 02:25:35 +00003075 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003076
Douglas Gregor14454802011-02-25 02:25:35 +00003077 case NestedNameSpecifier::Namespace: {
3078 NamespaceDecl *NS
3079 = cast_or_null<NamespaceDecl>(
3080 getDerived().TransformDecl(
3081 Q.getLocalBeginLoc(),
3082 QNNS->getAsNamespace()));
3083 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3084 break;
3085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor14454802011-02-25 02:25:35 +00003087 case NestedNameSpecifier::NamespaceAlias: {
3088 NamespaceAliasDecl *Alias
3089 = cast_or_null<NamespaceAliasDecl>(
3090 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3091 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003092 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003093 Q.getLocalEndLoc());
3094 break;
3095 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003096
Douglas Gregor14454802011-02-25 02:25:35 +00003097 case NestedNameSpecifier::Global:
3098 // There is no meaningful transformation that one could perform on the
3099 // global scope.
3100 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3101 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003102
Douglas Gregor14454802011-02-25 02:25:35 +00003103 case NestedNameSpecifier::TypeSpecWithTemplate:
3104 case NestedNameSpecifier::TypeSpec: {
3105 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3106 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003107
Douglas Gregor14454802011-02-25 02:25:35 +00003108 if (!TL)
3109 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
Douglas Gregor14454802011-02-25 02:25:35 +00003111 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003112 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003113 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003114 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003115 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003116 if (TL.getType()->isEnumeralType())
3117 SemaRef.Diag(TL.getBeginLoc(),
3118 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003119 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3120 Q.getLocalEndLoc());
3121 break;
3122 }
Richard Trieude756fb2011-05-07 01:36:37 +00003123 // If the nested-name-specifier is an invalid type def, don't emit an
3124 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003125 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3126 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003127 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003128 << TL.getType() << SS.getRange();
3129 }
Douglas Gregor14454802011-02-25 02:25:35 +00003130 return NestedNameSpecifierLoc();
3131 }
Douglas Gregore16af532011-02-28 18:50:33 +00003132 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003133
Douglas Gregore16af532011-02-28 18:50:33 +00003134 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003135 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003136 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003137 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003138
Douglas Gregor14454802011-02-25 02:25:35 +00003139 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003140 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003141 !getDerived().AlwaysRebuild())
3142 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
3144 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003145 // nested-name-specifier, do so.
3146 if (SS.location_size() == NNS.getDataLength() &&
3147 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3148 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3149
3150 // Allocate new nested-name-specifier location information.
3151 return SS.getWithLocInContext(SemaRef.Context);
3152}
3153
3154template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003155DeclarationNameInfo
3156TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003157::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003158 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003159 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003160 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003161
3162 switch (Name.getNameKind()) {
3163 case DeclarationName::Identifier:
3164 case DeclarationName::ObjCZeroArgSelector:
3165 case DeclarationName::ObjCOneArgSelector:
3166 case DeclarationName::ObjCMultiArgSelector:
3167 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003168 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003169 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003170 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003171
Douglas Gregorf816bd72009-09-03 22:13:48 +00003172 case DeclarationName::CXXConstructorName:
3173 case DeclarationName::CXXDestructorName:
3174 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003175 TypeSourceInfo *NewTInfo;
3176 CanQualType NewCanTy;
3177 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003178 NewTInfo = getDerived().TransformType(OldTInfo);
3179 if (!NewTInfo)
3180 return DeclarationNameInfo();
3181 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003182 }
3183 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003184 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003185 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003186 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003187 if (NewT.isNull())
3188 return DeclarationNameInfo();
3189 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3190 }
Mike Stump11289f42009-09-09 15:08:12 +00003191
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003192 DeclarationName NewName
3193 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3194 NewCanTy);
3195 DeclarationNameInfo NewNameInfo(NameInfo);
3196 NewNameInfo.setName(NewName);
3197 NewNameInfo.setNamedTypeInfo(NewTInfo);
3198 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003199 }
Mike Stump11289f42009-09-09 15:08:12 +00003200 }
3201
David Blaikie83d382b2011-09-23 05:06:16 +00003202 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003203}
3204
3205template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003206TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003207TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3208 TemplateName Name,
3209 SourceLocation NameLoc,
3210 QualType ObjectType,
3211 NamedDecl *FirstQualifierInScope) {
3212 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3213 TemplateDecl *Template = QTN->getTemplateDecl();
3214 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003215
Douglas Gregor9db53502011-03-02 18:07:45 +00003216 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003217 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003218 Template));
3219 if (!TransTemplate)
3220 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregor9db53502011-03-02 18:07:45 +00003222 if (!getDerived().AlwaysRebuild() &&
3223 SS.getScopeRep() == QTN->getQualifier() &&
3224 TransTemplate == Template)
3225 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003226
Douglas Gregor9db53502011-03-02 18:07:45 +00003227 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3228 TransTemplate);
3229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregor9db53502011-03-02 18:07:45 +00003231 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3232 if (SS.getScopeRep()) {
3233 // These apply to the scope specifier, not the template.
3234 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003235 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003236 }
3237
Douglas Gregor9db53502011-03-02 18:07:45 +00003238 if (!getDerived().AlwaysRebuild() &&
3239 SS.getScopeRep() == DTN->getQualifier() &&
3240 ObjectType.isNull())
3241 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003242
Douglas Gregor9db53502011-03-02 18:07:45 +00003243 if (DTN->isIdentifier()) {
3244 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003245 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003246 NameLoc,
3247 ObjectType,
3248 FirstQualifierInScope);
3249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregor9db53502011-03-02 18:07:45 +00003251 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3252 ObjectType);
3253 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003254
Douglas Gregor9db53502011-03-02 18:07:45 +00003255 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3256 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003257 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003258 Template));
3259 if (!TransTemplate)
3260 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003261
Douglas Gregor9db53502011-03-02 18:07:45 +00003262 if (!getDerived().AlwaysRebuild() &&
3263 TransTemplate == Template)
3264 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregor9db53502011-03-02 18:07:45 +00003266 return TemplateName(TransTemplate);
3267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Douglas Gregor9db53502011-03-02 18:07:45 +00003269 if (SubstTemplateTemplateParmPackStorage *SubstPack
3270 = Name.getAsSubstTemplateTemplateParmPack()) {
3271 TemplateTemplateParmDecl *TransParam
3272 = cast_or_null<TemplateTemplateParmDecl>(
3273 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3274 if (!TransParam)
3275 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor9db53502011-03-02 18:07:45 +00003277 if (!getDerived().AlwaysRebuild() &&
3278 TransParam == SubstPack->getParameterPack())
3279 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
3281 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003282 SubstPack->getArgumentPack());
3283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
Douglas Gregor9db53502011-03-02 18:07:45 +00003285 // These should be getting filtered out before they reach the AST.
3286 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003287}
3288
3289template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003290void TreeTransform<Derived>::InventTemplateArgumentLoc(
3291 const TemplateArgument &Arg,
3292 TemplateArgumentLoc &Output) {
3293 SourceLocation Loc = getDerived().getBaseLocation();
3294 switch (Arg.getKind()) {
3295 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003296 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003297 break;
3298
3299 case TemplateArgument::Type:
3300 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003301 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003302
John McCall0ad16662009-10-29 08:12:44 +00003303 break;
3304
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003305 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003306 case TemplateArgument::TemplateExpansion: {
3307 NestedNameSpecifierLocBuilder Builder;
3308 TemplateName Template = Arg.getAsTemplate();
3309 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3310 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3311 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3312 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor9d802122011-03-02 17:09:35 +00003314 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003315 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003316 Builder.getWithLocInContext(SemaRef.Context),
3317 Loc);
3318 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003319 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003320 Builder.getWithLocInContext(SemaRef.Context),
3321 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003322
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003323 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003324 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003325
John McCall0ad16662009-10-29 08:12:44 +00003326 case TemplateArgument::Expression:
3327 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3328 break;
3329
3330 case TemplateArgument::Declaration:
3331 case TemplateArgument::Integral:
3332 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003333 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003334 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003335 break;
3336 }
3337}
3338
3339template<typename Derived>
3340bool TreeTransform<Derived>::TransformTemplateArgument(
3341 const TemplateArgumentLoc &Input,
3342 TemplateArgumentLoc &Output) {
3343 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003344 switch (Arg.getKind()) {
3345 case TemplateArgument::Null:
3346 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003347 case TemplateArgument::Pack:
3348 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003349 case TemplateArgument::NullPtr:
3350 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003351
Douglas Gregore922c772009-08-04 22:27:00 +00003352 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003353 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003354 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003355 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003356
3357 DI = getDerived().TransformType(DI);
3358 if (!DI) return true;
3359
3360 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3361 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003362 }
Mike Stump11289f42009-09-09 15:08:12 +00003363
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003364 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003365 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3366 if (QualifierLoc) {
3367 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3368 if (!QualifierLoc)
3369 return true;
3370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Douglas Gregordf846d12011-03-02 18:46:51 +00003372 CXXScopeSpec SS;
3373 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003374 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003375 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3376 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003377 if (Template.isNull())
3378 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor9d802122011-03-02 17:09:35 +00003380 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003381 Input.getTemplateNameLoc());
3382 return false;
3383 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003384
3385 case TemplateArgument::TemplateExpansion:
3386 llvm_unreachable("Caller should expand pack expansions");
3387
Douglas Gregore922c772009-08-04 22:27:00 +00003388 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003389 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003390 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003391 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003392
John McCall0ad16662009-10-29 08:12:44 +00003393 Expr *InputExpr = Input.getSourceExpression();
3394 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3395
Chris Lattnercdb591a2011-04-25 20:37:58 +00003396 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003397 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003398 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003399 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003400 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003401 }
Douglas Gregore922c772009-08-04 22:27:00 +00003402 }
Mike Stump11289f42009-09-09 15:08:12 +00003403
Douglas Gregore922c772009-08-04 22:27:00 +00003404 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003405 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003406}
3407
Douglas Gregorfe921a72010-12-20 23:36:19 +00003408/// \brief Iterator adaptor that invents template argument location information
3409/// for each of the template arguments in its underlying iterator.
3410template<typename Derived, typename InputIterator>
3411class TemplateArgumentLocInventIterator {
3412 TreeTransform<Derived> &Self;
3413 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregorfe921a72010-12-20 23:36:19 +00003415public:
3416 typedef TemplateArgumentLoc value_type;
3417 typedef TemplateArgumentLoc reference;
3418 typedef typename std::iterator_traits<InputIterator>::difference_type
3419 difference_type;
3420 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
Douglas Gregorfe921a72010-12-20 23:36:19 +00003422 class pointer {
3423 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Douglas Gregorfe921a72010-12-20 23:36:19 +00003425 public:
3426 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregorfe921a72010-12-20 23:36:19 +00003428 const TemplateArgumentLoc *operator->() const { return &Arg; }
3429 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregorfe921a72010-12-20 23:36:19 +00003431 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregorfe921a72010-12-20 23:36:19 +00003433 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3434 InputIterator Iter)
3435 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003436
Douglas Gregorfe921a72010-12-20 23:36:19 +00003437 TemplateArgumentLocInventIterator &operator++() {
3438 ++Iter;
3439 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregorfe921a72010-12-20 23:36:19 +00003442 TemplateArgumentLocInventIterator operator++(int) {
3443 TemplateArgumentLocInventIterator Old(*this);
3444 ++(*this);
3445 return Old;
3446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregorfe921a72010-12-20 23:36:19 +00003448 reference operator*() const {
3449 TemplateArgumentLoc Result;
3450 Self.InventTemplateArgumentLoc(*Iter, Result);
3451 return Result;
3452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregorfe921a72010-12-20 23:36:19 +00003454 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregorfe921a72010-12-20 23:36:19 +00003456 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3457 const TemplateArgumentLocInventIterator &Y) {
3458 return X.Iter == Y.Iter;
3459 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003460
Douglas Gregorfe921a72010-12-20 23:36:19 +00003461 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3462 const TemplateArgumentLocInventIterator &Y) {
3463 return X.Iter != Y.Iter;
3464 }
3465};
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor42cafa82010-12-20 17:42:22 +00003467template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003468template<typename InputIterator>
3469bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3470 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003471 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003472 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003473 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003474 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003475
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003476 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3477 // Unpack argument packs, which we translate them into separate
3478 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003479 // FIXME: We could do much better if we could guarantee that the
3480 // TemplateArgumentLocInfo for the pack expansion would be usable for
3481 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003482 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003483 TemplateArgument::pack_iterator>
3484 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003485 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003486 In.getArgument().pack_begin()),
3487 PackLocIterator(*this,
3488 In.getArgument().pack_end()),
3489 Outputs))
3490 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003491
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003492 continue;
3493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003495 if (In.getArgument().isPackExpansion()) {
3496 // We have a pack expansion, for which we will be substituting into
3497 // the pattern.
3498 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003499 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003500 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003501 = getSema().getTemplateArgumentPackExpansionPattern(
3502 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
Chris Lattner01cf8db2011-07-20 06:58:45 +00003504 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003505 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3506 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003508 // Determine whether the set of unexpanded parameter packs can and should
3509 // be expanded.
3510 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003511 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003512 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003513 if (getDerived().TryExpandParameterPacks(Ellipsis,
3514 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003515 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003516 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003517 RetainExpansion,
3518 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003519 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003521 if (!Expand) {
3522 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003523 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003524 // expansion.
3525 TemplateArgumentLoc OutPattern;
3526 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3527 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3528 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003530 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3531 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003532 if (Out.getArgument().isNull())
3533 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003535 Outputs.addArgument(Out);
3536 continue;
3537 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003538
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003539 // The transform has determined that we should perform an elementwise
3540 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003541 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003542 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3543
3544 if (getDerived().TransformTemplateArgument(Pattern, Out))
3545 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003546
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003547 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003548 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3549 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003550 if (Out.getArgument().isNull())
3551 return true;
3552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003554 Outputs.addArgument(Out);
3555 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003556
Douglas Gregor48d24112011-01-10 20:53:55 +00003557 // If we're supposed to retain a pack expansion, do so by temporarily
3558 // forgetting the partially-substituted parameter pack.
3559 if (RetainExpansion) {
3560 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor48d24112011-01-10 20:53:55 +00003562 if (getDerived().TransformTemplateArgument(Pattern, Out))
3563 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003565 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3566 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003567 if (Out.getArgument().isNull())
3568 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003569
Douglas Gregor48d24112011-01-10 20:53:55 +00003570 Outputs.addArgument(Out);
3571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003573 continue;
3574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
3576 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003577 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003578 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
Douglas Gregor42cafa82010-12-20 17:42:22 +00003580 Outputs.addArgument(Out);
3581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003582
Douglas Gregor42cafa82010-12-20 17:42:22 +00003583 return false;
3584
3585}
3586
Douglas Gregord6ff3322009-08-04 16:50:30 +00003587//===----------------------------------------------------------------------===//
3588// Type transformation
3589//===----------------------------------------------------------------------===//
3590
3591template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003592QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003593 if (getDerived().AlreadyTransformed(T))
3594 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003595
John McCall550e0c22009-10-21 00:40:46 +00003596 // Temporary workaround. All of these transformations should
3597 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003598 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3599 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
John McCall31f82722010-11-12 08:19:04 +00003601 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003602
John McCall550e0c22009-10-21 00:40:46 +00003603 if (!NewDI)
3604 return QualType();
3605
3606 return NewDI->getType();
3607}
3608
3609template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003610TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003611 // Refine the base location to the type's location.
3612 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3613 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003614 if (getDerived().AlreadyTransformed(DI->getType()))
3615 return DI;
3616
3617 TypeLocBuilder TLB;
3618
3619 TypeLoc TL = DI->getTypeLoc();
3620 TLB.reserve(TL.getFullDataSize());
3621
John McCall31f82722010-11-12 08:19:04 +00003622 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003623 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003624 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003625
John McCallbcd03502009-12-07 02:54:59 +00003626 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003627}
3628
3629template<typename Derived>
3630QualType
John McCall31f82722010-11-12 08:19:04 +00003631TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003632 switch (T.getTypeLocClass()) {
3633#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003634#define TYPELOC(CLASS, PARENT) \
3635 case TypeLoc::CLASS: \
3636 return getDerived().Transform##CLASS##Type(TLB, \
3637 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003638#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003639 }
Mike Stump11289f42009-09-09 15:08:12 +00003640
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003641 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003642}
3643
3644/// FIXME: By default, this routine adds type qualifiers only to types
3645/// that can have qualifiers, and silently suppresses those qualifiers
3646/// that are not permitted (e.g., qualifiers on reference or function
3647/// types). This is the right thing for template instantiation, but
3648/// probably not for other clients.
3649template<typename Derived>
3650QualType
3651TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003652 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003653 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003654
John McCall31f82722010-11-12 08:19:04 +00003655 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003656 if (Result.isNull())
3657 return QualType();
3658
3659 // Silently suppress qualifiers if the result type can't be qualified.
3660 // FIXME: this is the right thing for template instantiation, but
3661 // probably not for other clients.
3662 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003663 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003664
John McCall31168b02011-06-15 23:02:42 +00003665 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003666 // resulting type.
3667 if (Quals.hasObjCLifetime()) {
3668 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3669 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003670 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003671 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003672 // A lifetime qualifier applied to a substituted template parameter
3673 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003674 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003675 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003676 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3677 QualType Replacement = SubstTypeParam->getReplacementType();
3678 Qualifiers Qs = Replacement.getQualifiers();
3679 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003680 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003681 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3682 Qs);
3683 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003684 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003685 Replacement);
3686 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003687 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3688 // 'auto' types behave the same way as template parameters.
3689 QualType Deduced = AutoTy->getDeducedType();
3690 Qualifiers Qs = Deduced.getQualifiers();
3691 Qs.removeObjCLifetime();
3692 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3693 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003694 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3695 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003696 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003697 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003698 // Otherwise, complain about the addition of a qualifier to an
3699 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003700 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003701 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003702 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003703
Douglas Gregore46db902011-06-17 22:11:49 +00003704 Quals.removeObjCLifetime();
3705 }
3706 }
3707 }
John McCallcb0f89a2010-06-05 06:41:15 +00003708 if (!Quals.empty()) {
3709 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003710 // BuildQualifiedType might not add qualifiers if they are invalid.
3711 if (Result.hasLocalQualifiers())
3712 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003713 // No location information to preserve.
3714 }
John McCall550e0c22009-10-21 00:40:46 +00003715
3716 return Result;
3717}
3718
Douglas Gregor14454802011-02-25 02:25:35 +00003719template<typename Derived>
3720TypeLoc
3721TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3722 QualType ObjectType,
3723 NamedDecl *UnqualLookup,
3724 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003725 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003726 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003728 TypeSourceInfo *TSI =
3729 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3730 if (TSI)
3731 return TSI->getTypeLoc();
3732 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003733}
3734
Douglas Gregor579c15f2011-03-02 18:32:08 +00003735template<typename Derived>
3736TypeSourceInfo *
3737TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3738 QualType ObjectType,
3739 NamedDecl *UnqualLookup,
3740 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003741 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003742 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003744 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3745 UnqualLookup, SS);
3746}
3747
3748template <typename Derived>
3749TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3750 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3751 CXXScopeSpec &SS) {
3752 QualType T = TL.getType();
3753 assert(!getDerived().AlreadyTransformed(T));
3754
Douglas Gregor579c15f2011-03-02 18:32:08 +00003755 TypeLocBuilder TLB;
3756 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003757
Douglas Gregor579c15f2011-03-02 18:32:08 +00003758 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003759 TemplateSpecializationTypeLoc SpecTL =
3760 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
Douglas Gregor579c15f2011-03-02 18:32:08 +00003762 TemplateName Template
3763 = getDerived().TransformTemplateName(SS,
3764 SpecTL.getTypePtr()->getTemplateName(),
3765 SpecTL.getTemplateNameLoc(),
3766 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003767 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003768 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
3770 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003771 Template);
3772 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003773 DependentTemplateSpecializationTypeLoc SpecTL =
3774 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003775
Douglas Gregor579c15f2011-03-02 18:32:08 +00003776 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003777 = getDerived().RebuildTemplateName(SS,
3778 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003779 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003780 ObjectType, UnqualLookup);
3781 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003782 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003783
3784 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003785 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003786 Template,
3787 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003788 } else {
3789 // Nothing special needs to be done for these.
3790 Result = getDerived().TransformType(TLB, TL);
3791 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003792
3793 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003794 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003795
Douglas Gregor579c15f2011-03-02 18:32:08 +00003796 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3797}
3798
John McCall550e0c22009-10-21 00:40:46 +00003799template <class TyLoc> static inline
3800QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3801 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3802 NewT.setNameLoc(T.getNameLoc());
3803 return T.getType();
3804}
3805
John McCall550e0c22009-10-21 00:40:46 +00003806template<typename Derived>
3807QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003808 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003809 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3810 NewT.setBuiltinLoc(T.getBuiltinLoc());
3811 if (T.needsExtraLocalData())
3812 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3813 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003814}
Mike Stump11289f42009-09-09 15:08:12 +00003815
Douglas Gregord6ff3322009-08-04 16:50:30 +00003816template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003817QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003818 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003819 // FIXME: recurse?
3820 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003821}
Mike Stump11289f42009-09-09 15:08:12 +00003822
Reid Kleckner0503a872013-12-05 01:23:43 +00003823template <typename Derived>
3824QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3825 AdjustedTypeLoc TL) {
3826 // Adjustments applied during transformation are handled elsewhere.
3827 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3828}
3829
Douglas Gregord6ff3322009-08-04 16:50:30 +00003830template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003831QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3832 DecayedTypeLoc TL) {
3833 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3834 if (OriginalType.isNull())
3835 return QualType();
3836
3837 QualType Result = TL.getType();
3838 if (getDerived().AlwaysRebuild() ||
3839 OriginalType != TL.getOriginalLoc().getType())
3840 Result = SemaRef.Context.getDecayedType(OriginalType);
3841 TLB.push<DecayedTypeLoc>(Result);
3842 // Nothing to set for DecayedTypeLoc.
3843 return Result;
3844}
3845
3846template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003847QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003848 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003849 QualType PointeeType
3850 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003851 if (PointeeType.isNull())
3852 return QualType();
3853
3854 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003855 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003856 // A dependent pointer type 'T *' has is being transformed such
3857 // that an Objective-C class type is being replaced for 'T'. The
3858 // resulting pointer type is an ObjCObjectPointerType, not a
3859 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003860 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003861
John McCall8b07ec22010-05-15 11:32:37 +00003862 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3863 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003864 return Result;
3865 }
John McCall31f82722010-11-12 08:19:04 +00003866
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003867 if (getDerived().AlwaysRebuild() ||
3868 PointeeType != TL.getPointeeLoc().getType()) {
3869 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3870 if (Result.isNull())
3871 return QualType();
3872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003873
John McCall31168b02011-06-15 23:02:42 +00003874 // Objective-C ARC can add lifetime qualifiers to the type that we're
3875 // pointing to.
3876 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003878 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3879 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003880 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003881}
Mike Stump11289f42009-09-09 15:08:12 +00003882
3883template<typename Derived>
3884QualType
John McCall550e0c22009-10-21 00:40:46 +00003885TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003886 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003887 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003888 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3889 if (PointeeType.isNull())
3890 return QualType();
3891
3892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 PointeeType != TL.getPointeeLoc().getType()) {
3895 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003896 TL.getSigilLoc());
3897 if (Result.isNull())
3898 return QualType();
3899 }
3900
Douglas Gregor049211a2010-04-22 16:50:51 +00003901 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003902 NewT.setSigilLoc(TL.getSigilLoc());
3903 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003904}
3905
John McCall70dd5f62009-10-30 00:06:24 +00003906/// Transforms a reference type. Note that somewhat paradoxically we
3907/// don't care whether the type itself is an l-value type or an r-value
3908/// type; we only care if the type was *written* as an l-value type
3909/// or an r-value type.
3910template<typename Derived>
3911QualType
3912TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003913 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003914 const ReferenceType *T = TL.getTypePtr();
3915
3916 // Note that this works with the pointee-as-written.
3917 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3918 if (PointeeType.isNull())
3919 return QualType();
3920
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 PointeeType != T->getPointeeTypeAsWritten()) {
3924 Result = getDerived().RebuildReferenceType(PointeeType,
3925 T->isSpelledAsLValue(),
3926 TL.getSigilLoc());
3927 if (Result.isNull())
3928 return QualType();
3929 }
3930
John McCall31168b02011-06-15 23:02:42 +00003931 // Objective-C ARC can add lifetime qualifiers to the type that we're
3932 // referring to.
3933 TLB.TypeWasModifiedSafely(
3934 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3935
John McCall70dd5f62009-10-30 00:06:24 +00003936 // r-value references can be rebuilt as l-value references.
3937 ReferenceTypeLoc NewTL;
3938 if (isa<LValueReferenceType>(Result))
3939 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3940 else
3941 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3942 NewTL.setSigilLoc(TL.getSigilLoc());
3943
3944 return Result;
3945}
3946
Mike Stump11289f42009-09-09 15:08:12 +00003947template<typename Derived>
3948QualType
John McCall550e0c22009-10-21 00:40:46 +00003949TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003950 LValueReferenceTypeLoc TL) {
3951 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952}
3953
Mike Stump11289f42009-09-09 15:08:12 +00003954template<typename Derived>
3955QualType
John McCall550e0c22009-10-21 00:40:46 +00003956TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003957 RValueReferenceTypeLoc TL) {
3958 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003959}
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregord6ff3322009-08-04 16:50:30 +00003961template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003962QualType
John McCall550e0c22009-10-21 00:40:46 +00003963TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003964 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003965 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003966 if (PointeeType.isNull())
3967 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003968
Abramo Bagnara509357842011-03-05 14:42:21 +00003969 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003970 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003971 if (OldClsTInfo) {
3972 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3973 if (!NewClsTInfo)
3974 return QualType();
3975 }
3976
3977 const MemberPointerType *T = TL.getTypePtr();
3978 QualType OldClsType = QualType(T->getClass(), 0);
3979 QualType NewClsType;
3980 if (NewClsTInfo)
3981 NewClsType = NewClsTInfo->getType();
3982 else {
3983 NewClsType = getDerived().TransformType(OldClsType);
3984 if (NewClsType.isNull())
3985 return QualType();
3986 }
Mike Stump11289f42009-09-09 15:08:12 +00003987
John McCall550e0c22009-10-21 00:40:46 +00003988 QualType Result = TL.getType();
3989 if (getDerived().AlwaysRebuild() ||
3990 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003991 NewClsType != OldClsType) {
3992 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003993 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003994 if (Result.isNull())
3995 return QualType();
3996 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003997
Reid Kleckner0503a872013-12-05 01:23:43 +00003998 // If we had to adjust the pointee type when building a member pointer, make
3999 // sure to push TypeLoc info for it.
4000 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4001 if (MPT && PointeeType != MPT->getPointeeType()) {
4002 assert(isa<AdjustedType>(MPT->getPointeeType()));
4003 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4004 }
4005
John McCall550e0c22009-10-21 00:40:46 +00004006 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4007 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004008 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004009
4010 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011}
4012
Mike Stump11289f42009-09-09 15:08:12 +00004013template<typename Derived>
4014QualType
John McCall550e0c22009-10-21 00:40:46 +00004015TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004017 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004018 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019 if (ElementType.isNull())
4020 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004021
John McCall550e0c22009-10-21 00:40:46 +00004022 QualType Result = TL.getType();
4023 if (getDerived().AlwaysRebuild() ||
4024 ElementType != T->getElementType()) {
4025 Result = getDerived().RebuildConstantArrayType(ElementType,
4026 T->getSizeModifier(),
4027 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004028 T->getIndexTypeCVRQualifiers(),
4029 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004030 if (Result.isNull())
4031 return QualType();
4032 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004033
4034 // We might have either a ConstantArrayType or a VariableArrayType now:
4035 // a ConstantArrayType is allowed to have an element type which is a
4036 // VariableArrayType if the type is dependent. Fortunately, all array
4037 // types have the same location layout.
4038 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004039 NewTL.setLBracketLoc(TL.getLBracketLoc());
4040 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004041
John McCall550e0c22009-10-21 00:40:46 +00004042 Expr *Size = TL.getSizeExpr();
4043 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004044 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4045 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004046 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4047 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004048 }
4049 NewTL.setSizeExpr(Size);
4050
4051 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052}
Mike Stump11289f42009-09-09 15:08:12 +00004053
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004056 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004057 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004058 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004059 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004060 if (ElementType.isNull())
4061 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004062
John McCall550e0c22009-10-21 00:40:46 +00004063 QualType Result = TL.getType();
4064 if (getDerived().AlwaysRebuild() ||
4065 ElementType != T->getElementType()) {
4066 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004067 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004068 T->getIndexTypeCVRQualifiers(),
4069 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004070 if (Result.isNull())
4071 return QualType();
4072 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004073
John McCall550e0c22009-10-21 00:40:46 +00004074 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4075 NewTL.setLBracketLoc(TL.getLBracketLoc());
4076 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004077 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004078
4079 return Result;
4080}
4081
4082template<typename Derived>
4083QualType
4084TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004086 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004087 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4088 if (ElementType.isNull())
4089 return QualType();
4090
John McCalldadc5752010-08-24 06:29:42 +00004091 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004092 = getDerived().TransformExpr(T->getSizeExpr());
4093 if (SizeResult.isInvalid())
4094 return QualType();
4095
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004096 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004097
4098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
4100 ElementType != T->getElementType() ||
4101 Size != T->getSizeExpr()) {
4102 Result = getDerived().RebuildVariableArrayType(ElementType,
4103 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004104 Size,
John McCall550e0c22009-10-21 00:40:46 +00004105 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004106 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004107 if (Result.isNull())
4108 return QualType();
4109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004110
Serge Pavlov774c6d02014-02-06 03:49:11 +00004111 // We might have constant size array now, but fortunately it has the same
4112 // location layout.
4113 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004114 NewTL.setLBracketLoc(TL.getLBracketLoc());
4115 NewTL.setRBracketLoc(TL.getRBracketLoc());
4116 NewTL.setSizeExpr(Size);
4117
4118 return Result;
4119}
4120
4121template<typename Derived>
4122QualType
4123TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004124 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004125 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004126 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4127 if (ElementType.isNull())
4128 return QualType();
4129
Richard Smith764d2fe2011-12-20 02:08:33 +00004130 // Array bounds are constant expressions.
4131 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4132 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004133
John McCall33ddac02011-01-19 10:06:00 +00004134 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4135 Expr *origSize = TL.getSizeExpr();
4136 if (!origSize) origSize = T->getSizeExpr();
4137
4138 ExprResult sizeResult
4139 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004140 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004141 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004142 return QualType();
4143
John McCall33ddac02011-01-19 10:06:00 +00004144 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004145
4146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() ||
4148 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004149 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004150 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4151 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004152 size,
John McCall550e0c22009-10-21 00:40:46 +00004153 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004154 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004155 if (Result.isNull())
4156 return QualType();
4157 }
John McCall550e0c22009-10-21 00:40:46 +00004158
4159 // We might have any sort of array type now, but fortunately they
4160 // all have the same location layout.
4161 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4162 NewTL.setLBracketLoc(TL.getLBracketLoc());
4163 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004164 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004165
4166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
4169template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004170QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004171 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004172 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004173 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004174
4175 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004176 QualType ElementType = getDerived().TransformType(T->getElementType());
4177 if (ElementType.isNull())
4178 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004179
Richard Smith764d2fe2011-12-20 02:08:33 +00004180 // Vector sizes are constant expressions.
4181 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4182 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004183
John McCalldadc5752010-08-24 06:29:42 +00004184 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004185 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 if (Size.isInvalid())
4187 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004188
John McCall550e0c22009-10-21 00:40:46 +00004189 QualType Result = TL.getType();
4190 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004191 ElementType != T->getElementType() ||
4192 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004193 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004194 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004196 if (Result.isNull())
4197 return QualType();
4198 }
John McCall550e0c22009-10-21 00:40:46 +00004199
4200 // Result might be dependent or not.
4201 if (isa<DependentSizedExtVectorType>(Result)) {
4202 DependentSizedExtVectorTypeLoc NewTL
4203 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4204 NewTL.setNameLoc(TL.getNameLoc());
4205 } else {
4206 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4208 }
4209
4210 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004211}
Mike Stump11289f42009-09-09 15:08:12 +00004212
4213template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004214QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004215 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004216 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004217 QualType ElementType = getDerived().TransformType(T->getElementType());
4218 if (ElementType.isNull())
4219 return QualType();
4220
John McCall550e0c22009-10-21 00:40:46 +00004221 QualType Result = TL.getType();
4222 if (getDerived().AlwaysRebuild() ||
4223 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004224 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004225 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004226 if (Result.isNull())
4227 return QualType();
4228 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004229
John McCall550e0c22009-10-21 00:40:46 +00004230 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4231 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004232
John McCall550e0c22009-10-21 00:40:46 +00004233 return Result;
4234}
4235
4236template<typename Derived>
4237QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004238 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004239 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004240 QualType ElementType = getDerived().TransformType(T->getElementType());
4241 if (ElementType.isNull())
4242 return QualType();
4243
4244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 ElementType != T->getElementType()) {
4247 Result = getDerived().RebuildExtVectorType(ElementType,
4248 T->getNumElements(),
4249 /*FIXME*/ SourceLocation());
4250 if (Result.isNull())
4251 return QualType();
4252 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004253
John McCall550e0c22009-10-21 00:40:46 +00004254 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4255 NewTL.setNameLoc(TL.getNameLoc());
4256
4257 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004258}
Mike Stump11289f42009-09-09 15:08:12 +00004259
David Blaikie05785d12013-02-20 22:23:23 +00004260template <typename Derived>
4261ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4262 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4263 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004264 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004265 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
Douglas Gregor715e4612011-01-14 22:40:04 +00004267 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004268 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004269 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004270 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004271 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004272
Douglas Gregor715e4612011-01-14 22:40:04 +00004273 TypeLocBuilder TLB;
4274 TypeLoc NewTL = OldDI->getTypeLoc();
4275 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004276
4277 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004278 OldExpansionTL.getPatternLoc());
4279 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004280 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004281
4282 Result = RebuildPackExpansionType(Result,
4283 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004284 OldExpansionTL.getEllipsisLoc(),
4285 NumExpansions);
4286 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004287 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004288
Douglas Gregor715e4612011-01-14 22:40:04 +00004289 PackExpansionTypeLoc NewExpansionTL
4290 = TLB.push<PackExpansionTypeLoc>(Result);
4291 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4292 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4293 } else
4294 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004295 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004296 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004297
John McCall8fb0d9d2011-05-01 22:35:37 +00004298 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004299 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004300
4301 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4302 OldParm->getDeclContext(),
4303 OldParm->getInnerLocStart(),
4304 OldParm->getLocation(),
4305 OldParm->getIdentifier(),
4306 NewDI->getType(),
4307 NewDI,
4308 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004309 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004310 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4311 OldParm->getFunctionScopeIndex() + indexAdjustment);
4312 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004313}
4314
4315template<typename Derived>
4316bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004317 TransformFunctionTypeParams(SourceLocation Loc,
4318 ParmVarDecl **Params, unsigned NumParams,
4319 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004320 SmallVectorImpl<QualType> &OutParamTypes,
4321 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004322 int indexAdjustment = 0;
4323
Douglas Gregordd472162011-01-07 00:20:55 +00004324 for (unsigned i = 0; i != NumParams; ++i) {
4325 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004326 assert(OldParm->getFunctionScopeIndex() == i);
4327
David Blaikie05785d12013-02-20 22:23:23 +00004328 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004329 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004330 if (OldParm->isParameterPack()) {
4331 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004332 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004333
Douglas Gregor5499af42011-01-05 23:12:31 +00004334 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004335 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004336 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004337 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4338 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004339 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4340
Douglas Gregor5499af42011-01-05 23:12:31 +00004341 // Determine whether we should expand the parameter packs.
4342 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004343 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004344 Optional<unsigned> OrigNumExpansions =
4345 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004346 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004347 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4348 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004349 Unexpanded,
4350 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004351 RetainExpansion,
4352 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004353 return true;
4354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004355
Douglas Gregor5499af42011-01-05 23:12:31 +00004356 if (ShouldExpand) {
4357 // Expand the function parameter pack into multiple, separate
4358 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004359 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004360 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004362 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004363 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004364 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004365 OrigNumExpansions,
4366 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004367 if (!NewParm)
4368 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004369
Douglas Gregordd472162011-01-07 00:20:55 +00004370 OutParamTypes.push_back(NewParm->getType());
4371 if (PVars)
4372 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004373 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004374
4375 // If we're supposed to retain a pack expansion, do so by temporarily
4376 // forgetting the partially-substituted parameter pack.
4377 if (RetainExpansion) {
4378 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004379 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004380 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004381 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004382 OrigNumExpansions,
4383 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004384 if (!NewParm)
4385 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004386
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004387 OutParamTypes.push_back(NewParm->getType());
4388 if (PVars)
4389 PVars->push_back(NewParm);
4390 }
4391
John McCall8fb0d9d2011-05-01 22:35:37 +00004392 // The next parameter should have the same adjustment as the
4393 // last thing we pushed, but we post-incremented indexAdjustment
4394 // on every push. Also, if we push nothing, the adjustment should
4395 // go down by one.
4396 indexAdjustment--;
4397
Douglas Gregor5499af42011-01-05 23:12:31 +00004398 // We're done with the pack expansion.
4399 continue;
4400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
4402 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004403 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004404 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4405 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004406 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004407 NumExpansions,
4408 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004409 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004410 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004411 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004412 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004413
John McCall58f10c32010-03-11 09:03:00 +00004414 if (!NewParm)
4415 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004416
Douglas Gregordd472162011-01-07 00:20:55 +00004417 OutParamTypes.push_back(NewParm->getType());
4418 if (PVars)
4419 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004420 continue;
4421 }
John McCall58f10c32010-03-11 09:03:00 +00004422
4423 // Deal with the possibility that we don't have a parameter
4424 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004425 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004426 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004427 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004428 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004429 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004430 = dyn_cast<PackExpansionType>(OldType)) {
4431 // We have a function parameter pack that may need to be expanded.
4432 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004433 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004434 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004435
Douglas Gregor5499af42011-01-05 23:12:31 +00004436 // Determine whether we should expand the parameter packs.
4437 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004438 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004439 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004440 Unexpanded,
4441 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004442 RetainExpansion,
4443 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004444 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004446
Douglas Gregor5499af42011-01-05 23:12:31 +00004447 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004448 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004449 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004450 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004451 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4452 QualType NewType = getDerived().TransformType(Pattern);
4453 if (NewType.isNull())
4454 return true;
John McCall58f10c32010-03-11 09:03:00 +00004455
Douglas Gregordd472162011-01-07 00:20:55 +00004456 OutParamTypes.push_back(NewType);
4457 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004458 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004460
Douglas Gregor5499af42011-01-05 23:12:31 +00004461 // We're done with the pack expansion.
4462 continue;
4463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004464
Douglas Gregor48d24112011-01-10 20:53:55 +00004465 // If we're supposed to retain a pack expansion, do so by temporarily
4466 // forgetting the partially-substituted parameter pack.
4467 if (RetainExpansion) {
4468 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4469 QualType NewType = getDerived().TransformType(Pattern);
4470 if (NewType.isNull())
4471 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004472
Douglas Gregor48d24112011-01-10 20:53:55 +00004473 OutParamTypes.push_back(NewType);
4474 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004475 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004476 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004477
Chad Rosier1dcde962012-08-08 18:46:20 +00004478 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004479 // expansion.
4480 OldType = Expansion->getPattern();
4481 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004482 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4483 NewType = getDerived().TransformType(OldType);
4484 } else {
4485 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004486 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004487
Douglas Gregor5499af42011-01-05 23:12:31 +00004488 if (NewType.isNull())
4489 return true;
4490
4491 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004492 NewType = getSema().Context.getPackExpansionType(NewType,
4493 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004494
Douglas Gregordd472162011-01-07 00:20:55 +00004495 OutParamTypes.push_back(NewType);
4496 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004497 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004498 }
4499
John McCall8fb0d9d2011-05-01 22:35:37 +00004500#ifndef NDEBUG
4501 if (PVars) {
4502 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4503 if (ParmVarDecl *parm = (*PVars)[i])
4504 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004505 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004506#endif
4507
4508 return false;
4509}
John McCall58f10c32010-03-11 09:03:00 +00004510
4511template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004512QualType
John McCall550e0c22009-10-21 00:40:46 +00004513TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004514 FunctionProtoTypeLoc TL) {
Hans Wennborge113c202014-09-18 16:01:32 +00004515 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004516}
4517
Hans Wennborge113c202014-09-18 16:01:32 +00004518template<typename Derived>
4519QualType
4520TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4521 FunctionProtoTypeLoc TL,
4522 CXXRecordDecl *ThisContext,
4523 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004524 // Transform the parameters and return type.
4525 //
Richard Smithf623c962012-04-17 00:58:00 +00004526 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004527 // When the function has a trailing return type, we instantiate the
4528 // parameters before the return type, since the return type can then refer
4529 // to the parameters themselves (via decltype, sizeof, etc.).
4530 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004531 SmallVector<QualType, 4> ParamTypes;
4532 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004533 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004534
Douglas Gregor7fb25412010-10-01 18:44:50 +00004535 QualType ResultType;
4536
Richard Smith1226c602012-08-14 22:51:13 +00004537 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004538 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004539 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004540 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004541 return QualType();
4542
Douglas Gregor3024f072012-04-16 07:05:22 +00004543 {
4544 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004545 // If a declaration declares a member function or member function
4546 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004547 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004548 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004549 // declarator.
4550 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004551
Alp Toker42a16a62014-01-25 23:51:36 +00004552 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004553 if (ResultType.isNull())
4554 return QualType();
4555 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004556 }
4557 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004558 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004559 if (ResultType.isNull())
4560 return QualType();
4561
Alp Toker9cacbab2014-01-20 20:26:09 +00004562 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004563 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004564 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004565 return QualType();
4566 }
4567
Hans Wennborge113c202014-09-18 16:01:32 +00004568 // FIXME: Need to transform the exception-specification too.
Richard Smithf623c962012-04-17 00:58:00 +00004569
John McCall550e0c22009-10-21 00:40:46 +00004570 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004571 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004572 T->getNumParams() != ParamTypes.size() ||
4573 !std::equal(T->param_type_begin(), T->param_type_end(),
Hans Wennborge113c202014-09-18 16:01:32 +00004574 ParamTypes.begin())) {
4575 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4576 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004577 if (Result.isNull())
4578 return QualType();
4579 }
Mike Stump11289f42009-09-09 15:08:12 +00004580
John McCall550e0c22009-10-21 00:40:46 +00004581 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004582 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004583 NewTL.setLParenLoc(TL.getLParenLoc());
4584 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004585 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004586 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4587 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004588
4589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregord6ff3322009-08-04 16:50:30 +00004592template<typename Derived>
4593QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004594 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004595 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004596 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004597 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004598 if (ResultType.isNull())
4599 return QualType();
4600
4601 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004602 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004603 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4604
4605 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004606 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004607 NewTL.setLParenLoc(TL.getLParenLoc());
4608 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004609 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
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
John McCallb96ec562009-12-04 22:46:56 +00004614template<typename Derived> QualType
4615TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004616 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004617 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004618 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004619 if (!D)
4620 return QualType();
4621
4622 QualType Result = TL.getType();
4623 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4624 Result = getDerived().RebuildUnresolvedUsingType(D);
4625 if (Result.isNull())
4626 return QualType();
4627 }
4628
4629 // We might get an arbitrary type spec type back. We should at
4630 // least always get a type spec type, though.
4631 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4632 NewTL.setNameLoc(TL.getNameLoc());
4633
4634 return Result;
4635}
4636
Douglas Gregord6ff3322009-08-04 16:50:30 +00004637template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004638QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004639 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004640 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004641 TypedefNameDecl *Typedef
4642 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4643 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004644 if (!Typedef)
4645 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004646
John McCall550e0c22009-10-21 00:40:46 +00004647 QualType Result = TL.getType();
4648 if (getDerived().AlwaysRebuild() ||
4649 Typedef != T->getDecl()) {
4650 Result = getDerived().RebuildTypedefType(Typedef);
4651 if (Result.isNull())
4652 return QualType();
4653 }
Mike Stump11289f42009-09-09 15:08:12 +00004654
John McCall550e0c22009-10-21 00:40:46 +00004655 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4656 NewTL.setNameLoc(TL.getNameLoc());
4657
4658 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659}
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregord6ff3322009-08-04 16:50:30 +00004661template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004662QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004663 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004664 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004665 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4666 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004667
John McCalldadc5752010-08-24 06:29:42 +00004668 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004669 if (E.isInvalid())
4670 return QualType();
4671
Eli Friedmane4f22df2012-02-29 04:03:55 +00004672 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4673 if (E.isInvalid())
4674 return QualType();
4675
John McCall550e0c22009-10-21 00:40:46 +00004676 QualType Result = TL.getType();
4677 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004678 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004679 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004680 if (Result.isNull())
4681 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004682 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004683 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004684
John McCall550e0c22009-10-21 00:40:46 +00004685 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004686 NewTL.setTypeofLoc(TL.getTypeofLoc());
4687 NewTL.setLParenLoc(TL.getLParenLoc());
4688 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004689
4690 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004691}
Mike Stump11289f42009-09-09 15:08:12 +00004692
4693template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004694QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004695 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004696 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4697 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4698 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004700
John McCall550e0c22009-10-21 00:40:46 +00004701 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004702 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4703 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004704 if (Result.isNull())
4705 return QualType();
4706 }
Mike Stump11289f42009-09-09 15:08:12 +00004707
John McCall550e0c22009-10-21 00:40:46 +00004708 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004709 NewTL.setTypeofLoc(TL.getTypeofLoc());
4710 NewTL.setLParenLoc(TL.getLParenLoc());
4711 NewTL.setRParenLoc(TL.getRParenLoc());
4712 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004713
4714 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004715}
Mike Stump11289f42009-09-09 15:08:12 +00004716
4717template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004718QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004719 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004720 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004721
Douglas Gregore922c772009-08-04 22:27:00 +00004722 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004723 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4724 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004725
John McCalldadc5752010-08-24 06:29:42 +00004726 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004727 if (E.isInvalid())
4728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004729
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004730 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004731 if (E.isInvalid())
4732 return QualType();
4733
John McCall550e0c22009-10-21 00:40:46 +00004734 QualType Result = TL.getType();
4735 if (getDerived().AlwaysRebuild() ||
4736 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004737 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004738 if (Result.isNull())
4739 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004740 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004741 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004742
John McCall550e0c22009-10-21 00:40:46 +00004743 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4744 NewTL.setNameLoc(TL.getNameLoc());
4745
4746 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004747}
4748
4749template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004750QualType TreeTransform<Derived>::TransformUnaryTransformType(
4751 TypeLocBuilder &TLB,
4752 UnaryTransformTypeLoc TL) {
4753 QualType Result = TL.getType();
4754 if (Result->isDependentType()) {
4755 const UnaryTransformType *T = TL.getTypePtr();
4756 QualType NewBase =
4757 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4758 Result = getDerived().RebuildUnaryTransformType(NewBase,
4759 T->getUTTKind(),
4760 TL.getKWLoc());
4761 if (Result.isNull())
4762 return QualType();
4763 }
4764
4765 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4766 NewTL.setKWLoc(TL.getKWLoc());
4767 NewTL.setParensRange(TL.getParensRange());
4768 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4769 return Result;
4770}
4771
4772template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004773QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4774 AutoTypeLoc TL) {
4775 const AutoType *T = TL.getTypePtr();
4776 QualType OldDeduced = T->getDeducedType();
4777 QualType NewDeduced;
4778 if (!OldDeduced.isNull()) {
4779 NewDeduced = getDerived().TransformType(OldDeduced);
4780 if (NewDeduced.isNull())
4781 return QualType();
4782 }
4783
4784 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004785 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4786 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004787 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004788 if (Result.isNull())
4789 return QualType();
4790 }
4791
4792 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4793 NewTL.setNameLoc(TL.getNameLoc());
4794
4795 return Result;
4796}
4797
4798template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004799QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004800 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004801 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004802 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004803 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4804 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004805 if (!Record)
4806 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004807
John McCall550e0c22009-10-21 00:40:46 +00004808 QualType Result = TL.getType();
4809 if (getDerived().AlwaysRebuild() ||
4810 Record != T->getDecl()) {
4811 Result = getDerived().RebuildRecordType(Record);
4812 if (Result.isNull())
4813 return QualType();
4814 }
Mike Stump11289f42009-09-09 15:08:12 +00004815
John McCall550e0c22009-10-21 00:40:46 +00004816 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4817 NewTL.setNameLoc(TL.getNameLoc());
4818
4819 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004820}
Mike Stump11289f42009-09-09 15:08:12 +00004821
4822template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004823QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004824 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004825 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004826 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004827 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4828 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004829 if (!Enum)
4830 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004831
John McCall550e0c22009-10-21 00:40:46 +00004832 QualType Result = TL.getType();
4833 if (getDerived().AlwaysRebuild() ||
4834 Enum != T->getDecl()) {
4835 Result = getDerived().RebuildEnumType(Enum);
4836 if (Result.isNull())
4837 return QualType();
4838 }
Mike Stump11289f42009-09-09 15:08:12 +00004839
John McCall550e0c22009-10-21 00:40:46 +00004840 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4841 NewTL.setNameLoc(TL.getNameLoc());
4842
4843 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004844}
John McCallfcc33b02009-09-05 00:15:47 +00004845
John McCalle78aac42010-03-10 03:28:59 +00004846template<typename Derived>
4847QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4848 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004849 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004850 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4851 TL.getTypePtr()->getDecl());
4852 if (!D) return QualType();
4853
4854 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4855 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4856 return T;
4857}
4858
Douglas Gregord6ff3322009-08-04 16:50:30 +00004859template<typename Derived>
4860QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004861 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004862 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004863 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004864}
4865
Mike Stump11289f42009-09-09 15:08:12 +00004866template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004867QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004868 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004869 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004870 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004871
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004872 // Substitute into the replacement type, which itself might involve something
4873 // that needs to be transformed. This only tends to occur with default
4874 // template arguments of template template parameters.
4875 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4876 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4877 if (Replacement.isNull())
4878 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004879
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004880 // Always canonicalize the replacement type.
4881 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4882 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004883 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004884 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004885
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004886 // Propagate type-source information.
4887 SubstTemplateTypeParmTypeLoc NewTL
4888 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4889 NewTL.setNameLoc(TL.getNameLoc());
4890 return Result;
4891
John McCallcebee162009-10-18 09:09:24 +00004892}
4893
4894template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004895QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4896 TypeLocBuilder &TLB,
4897 SubstTemplateTypeParmPackTypeLoc TL) {
4898 return TransformTypeSpecType(TLB, TL);
4899}
4900
4901template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004902QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004903 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004904 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004905 const TemplateSpecializationType *T = TL.getTypePtr();
4906
Douglas Gregordf846d12011-03-02 18:46:51 +00004907 // The nested-name-specifier never matters in a TemplateSpecializationType,
4908 // because we can't have a dependent nested-name-specifier anyway.
4909 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004910 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004911 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4912 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004913 if (Template.isNull())
4914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCall31f82722010-11-12 08:19:04 +00004916 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4917}
4918
Eli Friedman0dfb8892011-10-06 23:00:33 +00004919template<typename Derived>
4920QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4921 AtomicTypeLoc TL) {
4922 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4923 if (ValueType.isNull())
4924 return QualType();
4925
4926 QualType Result = TL.getType();
4927 if (getDerived().AlwaysRebuild() ||
4928 ValueType != TL.getValueLoc().getType()) {
4929 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4930 if (Result.isNull())
4931 return QualType();
4932 }
4933
4934 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4935 NewTL.setKWLoc(TL.getKWLoc());
4936 NewTL.setLParenLoc(TL.getLParenLoc());
4937 NewTL.setRParenLoc(TL.getRParenLoc());
4938
4939 return Result;
4940}
4941
Chad Rosier1dcde962012-08-08 18:46:20 +00004942 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004943 /// container that provides a \c getArgLoc() member function.
4944 ///
4945 /// This iterator is intended to be used with the iterator form of
4946 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4947 template<typename ArgLocContainer>
4948 class TemplateArgumentLocContainerIterator {
4949 ArgLocContainer *Container;
4950 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004951
Douglas Gregorfe921a72010-12-20 23:36:19 +00004952 public:
4953 typedef TemplateArgumentLoc value_type;
4954 typedef TemplateArgumentLoc reference;
4955 typedef int difference_type;
4956 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004957
Douglas Gregorfe921a72010-12-20 23:36:19 +00004958 class pointer {
4959 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004960
Douglas Gregorfe921a72010-12-20 23:36:19 +00004961 public:
4962 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004963
Douglas Gregorfe921a72010-12-20 23:36:19 +00004964 const TemplateArgumentLoc *operator->() const {
4965 return &Arg;
4966 }
4967 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004968
4969
Douglas Gregorfe921a72010-12-20 23:36:19 +00004970 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
Douglas Gregorfe921a72010-12-20 23:36:19 +00004972 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4973 unsigned Index)
4974 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004975
Douglas Gregorfe921a72010-12-20 23:36:19 +00004976 TemplateArgumentLocContainerIterator &operator++() {
4977 ++Index;
4978 return *this;
4979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004980
Douglas Gregorfe921a72010-12-20 23:36:19 +00004981 TemplateArgumentLocContainerIterator operator++(int) {
4982 TemplateArgumentLocContainerIterator Old(*this);
4983 ++(*this);
4984 return Old;
4985 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004986
Douglas Gregorfe921a72010-12-20 23:36:19 +00004987 TemplateArgumentLoc operator*() const {
4988 return Container->getArgLoc(Index);
4989 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004990
Douglas Gregorfe921a72010-12-20 23:36:19 +00004991 pointer operator->() const {
4992 return pointer(Container->getArgLoc(Index));
4993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004994
Douglas Gregorfe921a72010-12-20 23:36:19 +00004995 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004996 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004997 return X.Container == Y.Container && X.Index == Y.Index;
4998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004999
Douglas Gregorfe921a72010-12-20 23:36:19 +00005000 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005001 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005002 return !(X == Y);
5003 }
5004 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005005
5006
John McCall31f82722010-11-12 08:19:04 +00005007template <typename Derived>
5008QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5009 TypeLocBuilder &TLB,
5010 TemplateSpecializationTypeLoc TL,
5011 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005012 TemplateArgumentListInfo NewTemplateArgs;
5013 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5014 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005015 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5016 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005017 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005018 ArgIterator(TL, TL.getNumArgs()),
5019 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005020 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005021
John McCall0ad16662009-10-29 08:12:44 +00005022 // FIXME: maybe don't rebuild if all the template arguments are the same.
5023
5024 QualType Result =
5025 getDerived().RebuildTemplateSpecializationType(Template,
5026 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005027 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005028
5029 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005030 // Specializations of template template parameters are represented as
5031 // TemplateSpecializationTypes, and substitution of type alias templates
5032 // within a dependent context can transform them into
5033 // DependentTemplateSpecializationTypes.
5034 if (isa<DependentTemplateSpecializationType>(Result)) {
5035 DependentTemplateSpecializationTypeLoc NewTL
5036 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005037 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005038 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005039 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005040 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005041 NewTL.setLAngleLoc(TL.getLAngleLoc());
5042 NewTL.setRAngleLoc(TL.getRAngleLoc());
5043 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5044 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5045 return Result;
5046 }
5047
John McCall0ad16662009-10-29 08:12:44 +00005048 TemplateSpecializationTypeLoc NewTL
5049 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005050 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005051 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5052 NewTL.setLAngleLoc(TL.getLAngleLoc());
5053 NewTL.setRAngleLoc(TL.getRAngleLoc());
5054 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5055 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005056 }
Mike Stump11289f42009-09-09 15:08:12 +00005057
John McCall0ad16662009-10-29 08:12:44 +00005058 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005059}
Mike Stump11289f42009-09-09 15:08:12 +00005060
Douglas Gregor5a064722011-02-28 17:23:35 +00005061template <typename Derived>
5062QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5063 TypeLocBuilder &TLB,
5064 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005065 TemplateName Template,
5066 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005067 TemplateArgumentListInfo NewTemplateArgs;
5068 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5069 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5070 typedef TemplateArgumentLocContainerIterator<
5071 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005072 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005073 ArgIterator(TL, TL.getNumArgs()),
5074 NewTemplateArgs))
5075 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005076
Douglas Gregor5a064722011-02-28 17:23:35 +00005077 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005078
Douglas Gregor5a064722011-02-28 17:23:35 +00005079 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5080 QualType Result
5081 = getSema().Context.getDependentTemplateSpecializationType(
5082 TL.getTypePtr()->getKeyword(),
5083 DTN->getQualifier(),
5084 DTN->getIdentifier(),
5085 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005086
Douglas Gregor5a064722011-02-28 17:23:35 +00005087 DependentTemplateSpecializationTypeLoc NewTL
5088 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005089 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005090 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005091 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005092 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005093 NewTL.setLAngleLoc(TL.getLAngleLoc());
5094 NewTL.setRAngleLoc(TL.getRAngleLoc());
5095 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5096 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5097 return Result;
5098 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005099
5100 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005101 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005102 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005103 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005104
Douglas Gregor5a064722011-02-28 17:23:35 +00005105 if (!Result.isNull()) {
5106 /// FIXME: Wrap this in an elaborated-type-specifier?
5107 TemplateSpecializationTypeLoc NewTL
5108 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005109 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005110 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005111 NewTL.setLAngleLoc(TL.getLAngleLoc());
5112 NewTL.setRAngleLoc(TL.getRAngleLoc());
5113 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5114 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005116
Douglas Gregor5a064722011-02-28 17:23:35 +00005117 return Result;
5118}
5119
Mike Stump11289f42009-09-09 15:08:12 +00005120template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005121QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005122TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005123 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005124 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005125
Douglas Gregor844cb502011-03-01 18:12:44 +00005126 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005127 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005128 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005129 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005130 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5131 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005132 return QualType();
5133 }
Mike Stump11289f42009-09-09 15:08:12 +00005134
John McCall31f82722010-11-12 08:19:04 +00005135 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5136 if (NamedT.isNull())
5137 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005138
Richard Smith3f1b5d02011-05-05 21:57:07 +00005139 // C++0x [dcl.type.elab]p2:
5140 // If the identifier resolves to a typedef-name or the simple-template-id
5141 // resolves to an alias template specialization, the
5142 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005143 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5144 if (const TemplateSpecializationType *TST =
5145 NamedT->getAs<TemplateSpecializationType>()) {
5146 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005147 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5148 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005149 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5150 diag::err_tag_reference_non_tag) << 4;
5151 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5152 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005153 }
5154 }
5155
John McCall550e0c22009-10-21 00:40:46 +00005156 QualType Result = TL.getType();
5157 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005158 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005159 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005160 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005161 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005162 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005163 if (Result.isNull())
5164 return QualType();
5165 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005166
Abramo Bagnara6150c882010-05-11 21:36:43 +00005167 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005168 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005169 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005171}
Mike Stump11289f42009-09-09 15:08:12 +00005172
5173template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005174QualType TreeTransform<Derived>::TransformAttributedType(
5175 TypeLocBuilder &TLB,
5176 AttributedTypeLoc TL) {
5177 const AttributedType *oldType = TL.getTypePtr();
5178 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5179 if (modifiedType.isNull())
5180 return QualType();
5181
5182 QualType result = TL.getType();
5183
5184 // FIXME: dependent operand expressions?
5185 if (getDerived().AlwaysRebuild() ||
5186 modifiedType != oldType->getModifiedType()) {
5187 // TODO: this is really lame; we should really be rebuilding the
5188 // equivalent type from first principles.
5189 QualType equivalentType
5190 = getDerived().TransformType(oldType->getEquivalentType());
5191 if (equivalentType.isNull())
5192 return QualType();
5193 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5194 modifiedType,
5195 equivalentType);
5196 }
5197
5198 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5199 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5200 if (TL.hasAttrOperand())
5201 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5202 if (TL.hasAttrExprOperand())
5203 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5204 else if (TL.hasAttrEnumOperand())
5205 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5206
5207 return result;
5208}
5209
5210template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005211QualType
5212TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5213 ParenTypeLoc TL) {
5214 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5215 if (Inner.isNull())
5216 return QualType();
5217
5218 QualType Result = TL.getType();
5219 if (getDerived().AlwaysRebuild() ||
5220 Inner != TL.getInnerLoc().getType()) {
5221 Result = getDerived().RebuildParenType(Inner);
5222 if (Result.isNull())
5223 return QualType();
5224 }
5225
5226 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5227 NewTL.setLParenLoc(TL.getLParenLoc());
5228 NewTL.setRParenLoc(TL.getRParenLoc());
5229 return Result;
5230}
5231
5232template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005233QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005234 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005235 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005236
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005237 NestedNameSpecifierLoc QualifierLoc
5238 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5239 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005240 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005241
John McCallc392f372010-06-11 00:33:02 +00005242 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005243 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005244 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005245 QualifierLoc,
5246 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005247 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005248 if (Result.isNull())
5249 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005250
Abramo Bagnarad7548482010-05-19 21:37:53 +00005251 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5252 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005253 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5254
Abramo Bagnarad7548482010-05-19 21:37:53 +00005255 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005256 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005257 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005258 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005259 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005260 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005261 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005262 NewTL.setNameLoc(TL.getNameLoc());
5263 }
John McCall550e0c22009-10-21 00:40:46 +00005264 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265}
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregord6ff3322009-08-04 16:50:30 +00005267template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005268QualType TreeTransform<Derived>::
5269 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005270 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005271 NestedNameSpecifierLoc QualifierLoc;
5272 if (TL.getQualifierLoc()) {
5273 QualifierLoc
5274 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5275 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005276 return QualType();
5277 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005278
John McCall31f82722010-11-12 08:19:04 +00005279 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005280 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005281}
5282
5283template<typename Derived>
5284QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005285TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5286 DependentTemplateSpecializationTypeLoc TL,
5287 NestedNameSpecifierLoc QualifierLoc) {
5288 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005289
Douglas Gregora7a795b2011-03-01 20:11:18 +00005290 TemplateArgumentListInfo NewTemplateArgs;
5291 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5292 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005293
Douglas Gregora7a795b2011-03-01 20:11:18 +00005294 typedef TemplateArgumentLocContainerIterator<
5295 DependentTemplateSpecializationTypeLoc> ArgIterator;
5296 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5297 ArgIterator(TL, TL.getNumArgs()),
5298 NewTemplateArgs))
5299 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
Douglas Gregora7a795b2011-03-01 20:11:18 +00005301 QualType Result
5302 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5303 QualifierLoc,
5304 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005305 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005306 NewTemplateArgs);
5307 if (Result.isNull())
5308 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005309
Douglas Gregora7a795b2011-03-01 20:11:18 +00005310 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5311 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
Douglas Gregora7a795b2011-03-01 20:11:18 +00005313 // Copy information relevant to the template specialization.
5314 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005315 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005316 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005317 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005318 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5319 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005320 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005321 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005322
Douglas Gregora7a795b2011-03-01 20:11:18 +00005323 // Copy information relevant to the elaborated type.
5324 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005325 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005326 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005327 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5328 DependentTemplateSpecializationTypeLoc SpecTL
5329 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005330 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005331 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005332 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005333 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005334 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5335 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005336 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005337 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005338 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005339 TemplateSpecializationTypeLoc SpecTL
5340 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005341 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005342 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005343 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5344 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005345 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005346 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005347 }
5348 return Result;
5349}
5350
5351template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005352QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5353 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005354 QualType Pattern
5355 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005356 if (Pattern.isNull())
5357 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005358
5359 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005360 if (getDerived().AlwaysRebuild() ||
5361 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005362 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005363 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005364 TL.getEllipsisLoc(),
5365 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005366 if (Result.isNull())
5367 return QualType();
5368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005369
Douglas Gregor822d0302011-01-12 17:07:58 +00005370 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5371 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5372 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005373}
5374
5375template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005376QualType
5377TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005378 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005379 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005380 TLB.pushFullCopy(TL);
5381 return TL.getType();
5382}
5383
5384template<typename Derived>
5385QualType
5386TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005387 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005388 // ObjCObjectType is never dependent.
5389 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005390 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
5393template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005394QualType
5395TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005396 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005397 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005398 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005399 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005400}
5401
Douglas Gregord6ff3322009-08-04 16:50:30 +00005402//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005403// Statement transformation
5404//===----------------------------------------------------------------------===//
5405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005406StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005407TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005408 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005409}
5410
5411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005412StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005413TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5414 return getDerived().TransformCompoundStmt(S, false);
5415}
5416
5417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005418StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005419TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005420 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005421 Sema::CompoundScopeRAII CompoundScope(getSema());
5422
John McCall1ababa62010-08-27 19:56:05 +00005423 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005424 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005425 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005426 for (auto *B : S->body()) {
5427 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005428 if (Result.isInvalid()) {
5429 // Immediately fail if this was a DeclStmt, since it's very
5430 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005431 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005432 return StmtError();
5433
5434 // Otherwise, just keep processing substatements and fail later.
5435 SubStmtInvalid = true;
5436 continue;
5437 }
Mike Stump11289f42009-09-09 15:08:12 +00005438
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005439 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005440 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 }
Mike Stump11289f42009-09-09 15:08:12 +00005442
John McCall1ababa62010-08-27 19:56:05 +00005443 if (SubStmtInvalid)
5444 return StmtError();
5445
Douglas Gregorebe10102009-08-20 07:17:43 +00005446 if (!getDerived().AlwaysRebuild() &&
5447 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005448 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005449
5450 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005451 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005452 S->getRBracLoc(),
5453 IsStmtExpr);
5454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregorebe10102009-08-20 07:17:43 +00005456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005457StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005458TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005459 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005460 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005461 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5462 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005463
Eli Friedman06577382009-11-19 03:14:00 +00005464 // Transform the left-hand case value.
5465 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005466 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005467 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005468 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005469
Eli Friedman06577382009-11-19 03:14:00 +00005470 // Transform the right-hand case value (for the GNU case-range extension).
5471 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005472 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005473 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005474 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005475 }
Mike Stump11289f42009-09-09 15:08:12 +00005476
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 // Build the case statement.
5478 // Case statements are always rebuilt so that they will attached to their
5479 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005480 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005481 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005482 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005483 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005484 S->getColonLoc());
5485 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregorebe10102009-08-20 07:17:43 +00005488 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005489 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005492
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005494 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005495}
5496
5497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005498StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005499TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005500 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005501 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005502 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005503 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005504
Douglas Gregorebe10102009-08-20 07:17:43 +00005505 // Default statements are always rebuilt
5506 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005507 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005508}
Mike Stump11289f42009-09-09 15:08:12 +00005509
Douglas Gregorebe10102009-08-20 07:17:43 +00005510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005511StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005512TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005513 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005514 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005516
Chris Lattnercab02a62011-02-17 20:34:02 +00005517 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5518 S->getDecl());
5519 if (!LD)
5520 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005521
5522
Douglas Gregorebe10102009-08-20 07:17:43 +00005523 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005524 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005525 cast<LabelDecl>(LD), SourceLocation(),
5526 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005527}
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregorebe10102009-08-20 07:17:43 +00005529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005530StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005531TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5532 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5533 if (SubStmt.isInvalid())
5534 return StmtError();
5535
5536 // TODO: transform attributes
5537 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5538 return S;
5539
5540 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5541 S->getAttrs(),
5542 SubStmt.get());
5543}
5544
5545template<typename Derived>
5546StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005547TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005548 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005549 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005550 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005551 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005552 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005553 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005554 getDerived().TransformDefinition(
5555 S->getConditionVariable()->getLocation(),
5556 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005557 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005558 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005559 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005560 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005561
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005562 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005563 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005564
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005565 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005566 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005567 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005568 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005569 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005570 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005571
John McCallb268a282010-08-23 23:25:46 +00005572 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005573 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005575
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005576 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005577 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005579
Douglas Gregorebe10102009-08-20 07:17:43 +00005580 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005581 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005582 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregorebe10102009-08-20 07:17:43 +00005585 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005586 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005587 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005588 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005589
Douglas Gregorebe10102009-08-20 07:17:43 +00005590 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005591 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005592 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 Then.get() == S->getThen() &&
5594 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005595 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005597 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005598 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005599 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005600}
5601
5602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005603StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005604TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005606 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005607 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005608 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005609 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005610 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005611 getDerived().TransformDefinition(
5612 S->getConditionVariable()->getLocation(),
5613 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005614 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005616 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005617 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005618
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005619 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005620 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005621 }
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregorebe10102009-08-20 07:17:43 +00005623 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005624 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005625 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005626 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005627 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005628 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005629
Douglas Gregorebe10102009-08-20 07:17:43 +00005630 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005631 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005632 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005633 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregorebe10102009-08-20 07:17:43 +00005635 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005636 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5637 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005638}
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregorebe10102009-08-20 07:17:43 +00005640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005642TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005643 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005644 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005645 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005646 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005647 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005648 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005649 getDerived().TransformDefinition(
5650 S->getConditionVariable()->getLocation(),
5651 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005652 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005653 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005654 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005655 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005656
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005657 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005659
5660 if (S->getCond()) {
5661 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005662 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5663 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005664 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005665 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005666 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005667 Cond = CondE;
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 body
John McCalldadc5752010-08-24 06:29:42 +00005676 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005677 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005678 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005681 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005682 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005684 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005686 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005687 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005688}
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregorebe10102009-08-20 07:17:43 +00005690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005691StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005692TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005693 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005694 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005695 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005696 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005698 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005699 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005700 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005701 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005702
Douglas Gregorebe10102009-08-20 07:17:43 +00005703 if (!getDerived().AlwaysRebuild() &&
5704 Cond.get() == S->getCond() &&
5705 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005706 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005707
John McCallb268a282010-08-23 23:25:46 +00005708 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5709 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 S->getRParenLoc());
5711}
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregorebe10102009-08-20 07:17:43 +00005713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005714StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005715TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005716 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005717 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005718 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005719 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregorebe10102009-08-20 07:17:43 +00005721 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005722 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005723 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005724 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005725 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005726 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005727 getDerived().TransformDefinition(
5728 S->getConditionVariable()->getLocation(),
5729 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005730 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005732 } else {
5733 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005735 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005737
5738 if (S->getCond()) {
5739 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005740 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5741 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005742 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005743 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005744 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005745
John McCallb268a282010-08-23 23:25:46 +00005746 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005747 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005748 }
Mike Stump11289f42009-09-09 15:08:12 +00005749
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005750 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005751 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005752 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005753
Douglas Gregorebe10102009-08-20 07:17:43 +00005754 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005755 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005756 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005757 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005758
Richard Smith945f8d32013-01-14 22:39:08 +00005759 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005760 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005762
Douglas Gregorebe10102009-08-20 07:17:43 +00005763 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005764 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005765 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005766 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregorebe10102009-08-20 07:17:43 +00005768 if (!getDerived().AlwaysRebuild() &&
5769 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005770 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005771 Inc.get() == S->getInc() &&
5772 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005773 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregorebe10102009-08-20 07:17:43 +00005775 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005776 Init.get(), FullCond, ConditionVar,
5777 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005778}
5779
5780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005781StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005782TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005783 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5784 S->getLabel());
5785 if (!LD)
5786 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005787
Douglas Gregorebe10102009-08-20 07:17:43 +00005788 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005789 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005790 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005791}
5792
5793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005794StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005795TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005796 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005797 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005799 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregorebe10102009-08-20 07:17:43 +00005801 if (!getDerived().AlwaysRebuild() &&
5802 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005803 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005804
5805 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005806 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005807}
5808
5809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005810StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005811TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005812 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005813}
Mike Stump11289f42009-09-09 15:08:12 +00005814
Douglas Gregorebe10102009-08-20 07:17:43 +00005815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005816StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005817TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005818 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005819}
Mike Stump11289f42009-09-09 15:08:12 +00005820
Douglas Gregorebe10102009-08-20 07:17:43 +00005821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005822StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005823TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00005824 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
5825 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00005826 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005827 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005828
Mike Stump11289f42009-09-09 15:08:12 +00005829 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005830 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005831 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005832}
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregorebe10102009-08-20 07:17:43 +00005834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005836TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005838 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005839 for (auto *D : S->decls()) {
5840 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005841 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005842 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005843
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005844 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005845 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005846
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 Decls.push_back(Transformed);
5848 }
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005851 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005852
Rafael Espindolaab417692013-07-09 12:05:01 +00005853 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005854}
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregorebe10102009-08-20 07:17:43 +00005856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005857StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005858TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005859
Benjamin Kramerf0623432012-08-23 22:51:59 +00005860 SmallVector<Expr*, 8> Constraints;
5861 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005862 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005863
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005865 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005866
5867 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Anders Carlssonaaeef072010-01-24 05:50:09 +00005869 // Go through the outputs.
5870 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005871 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005872
Anders Carlssonaaeef072010-01-24 05:50:09 +00005873 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005874 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005875
Anders Carlssonaaeef072010-01-24 05:50:09 +00005876 // Transform the output expr.
5877 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005878 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005879 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
Anders Carlssonaaeef072010-01-24 05:50:09 +00005882 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005883
John McCallb268a282010-08-23 23:25:46 +00005884 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
Anders Carlssonaaeef072010-01-24 05:50:09 +00005887 // Go through the inputs.
5888 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005889 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005890
Anders Carlssonaaeef072010-01-24 05:50:09 +00005891 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005892 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005893
Anders Carlssonaaeef072010-01-24 05:50:09 +00005894 // Transform the input expr.
5895 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005896 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005897 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005899
Anders Carlssonaaeef072010-01-24 05:50:09 +00005900 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
John McCallb268a282010-08-23 23:25:46 +00005902 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005903 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
Anders Carlssonaaeef072010-01-24 05:50:09 +00005905 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005906 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005907
5908 // Go through the clobbers.
5909 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005910 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005911
5912 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005913 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005914 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5915 S->isVolatile(), S->getNumOutputs(),
5916 S->getNumInputs(), Names.data(),
5917 Constraints, Exprs, AsmString.get(),
5918 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005919}
5920
Chad Rosier32503022012-06-11 20:47:18 +00005921template<typename Derived>
5922StmtResult
5923TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005924 ArrayRef<Token> AsmToks =
5925 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005926
John McCallf413f5e2013-05-03 00:10:13 +00005927 bool HadError = false, HadChange = false;
5928
5929 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5930 SmallVector<Expr*, 8> TransformedExprs;
5931 TransformedExprs.reserve(SrcExprs.size());
5932 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5933 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5934 if (!Result.isUsable()) {
5935 HadError = true;
5936 } else {
5937 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005938 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005939 }
5940 }
5941
5942 if (HadError) return StmtError();
5943 if (!HadChange && !getDerived().AlwaysRebuild())
5944 return Owned(S);
5945
Chad Rosierb6f46c12012-08-15 16:53:30 +00005946 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005947 AsmToks, S->getAsmString(),
5948 S->getNumOutputs(), S->getNumInputs(),
5949 S->getAllConstraints(), S->getClobbers(),
5950 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005951}
Douglas Gregorebe10102009-08-20 07:17:43 +00005952
5953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005954StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005955TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005956 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005957 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005958 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005960
Douglas Gregor96c79492010-04-23 22:50:49 +00005961 // Transform the @catch statements (if present).
5962 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005963 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005964 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005965 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005966 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005968 if (Catch.get() != S->getCatchStmt(I))
5969 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005970 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005972
Douglas Gregor306de2f2010-04-22 23:59:56 +00005973 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005974 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005975 if (S->getFinallyStmt()) {
5976 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5977 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005979 }
5980
5981 // If nothing changed, just retain this statement.
5982 if (!getDerived().AlwaysRebuild() &&
5983 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005984 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005985 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005986 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005987
Douglas Gregor306de2f2010-04-22 23:59:56 +00005988 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005989 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005990 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005991}
Mike Stump11289f42009-09-09 15:08:12 +00005992
Douglas Gregorebe10102009-08-20 07:17:43 +00005993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005994StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005995TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005996 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005997 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005998 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005999 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006000 if (FromVar->getTypeSourceInfo()) {
6001 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6002 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006004 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006005
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006006 QualType T;
6007 if (TSInfo)
6008 T = TSInfo->getType();
6009 else {
6010 T = getDerived().TransformType(FromVar->getType());
6011 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006012 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006014
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006015 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6016 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
John McCalldadc5752010-08-24 06:29:42 +00006020 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006021 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006023
6024 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006025 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006026 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006027}
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregorebe10102009-08-20 07:17:43 +00006029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006030StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006031TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006032 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006033 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006034 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006036
Douglas Gregor306de2f2010-04-22 23:59:56 +00006037 // If nothing changed, just retain this statement.
6038 if (!getDerived().AlwaysRebuild() &&
6039 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006040 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006041
6042 // Build a new statement.
6043 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006044 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006045}
Mike Stump11289f42009-09-09 15:08:12 +00006046
Douglas Gregorebe10102009-08-20 07:17:43 +00006047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006048StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006049TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006050 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006051 if (S->getThrowExpr()) {
6052 Operand = getDerived().TransformExpr(S->getThrowExpr());
6053 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006056
Douglas Gregor2900c162010-04-22 21:44:01 +00006057 if (!getDerived().AlwaysRebuild() &&
6058 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006059 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006060
John McCallb268a282010-08-23 23:25:46 +00006061 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006062}
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregorebe10102009-08-20 07:17:43 +00006064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006065StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006066TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006067 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006068 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006069 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006070 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006072 Object =
6073 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6074 Object.get());
6075 if (Object.isInvalid())
6076 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
Douglas Gregor6148de72010-04-22 22:01:21 +00006078 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006079 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006080 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006081 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006082
Douglas Gregor6148de72010-04-22 22:01:21 +00006083 // If nothing change, just retain the current statement.
6084 if (!getDerived().AlwaysRebuild() &&
6085 Object.get() == S->getSynchExpr() &&
6086 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006087 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006088
6089 // Build a new statement.
6090 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006091 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006092}
6093
6094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006095StmtResult
John McCall31168b02011-06-15 23:02:42 +00006096TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6097 ObjCAutoreleasePoolStmt *S) {
6098 // Transform the body.
6099 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6100 if (Body.isInvalid())
6101 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006102
John McCall31168b02011-06-15 23:02:42 +00006103 // If nothing changed, just retain this statement.
6104 if (!getDerived().AlwaysRebuild() &&
6105 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006106 return S;
John McCall31168b02011-06-15 23:02:42 +00006107
6108 // Build a new statement.
6109 return getDerived().RebuildObjCAutoreleasePoolStmt(
6110 S->getAtLoc(), Body.get());
6111}
6112
6113template<typename Derived>
6114StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006115TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006116 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006117 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006118 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006119 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
Douglas Gregorf68a5082010-04-22 23:10:45 +00006122 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006123 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006124 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
Douglas Gregorf68a5082010-04-22 23:10:45 +00006127 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006128 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006129 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006131
Douglas Gregorf68a5082010-04-22 23:10:45 +00006132 // If nothing changed, just retain this statement.
6133 if (!getDerived().AlwaysRebuild() &&
6134 Element.get() == S->getElement() &&
6135 Collection.get() == S->getCollection() &&
6136 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006137 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006138
Douglas Gregorf68a5082010-04-22 23:10:45 +00006139 // Build a new statement.
6140 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006141 Element.get(),
6142 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006143 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006144 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006145}
6146
David Majnemer5f7efef2013-10-15 09:50:08 +00006147template <typename Derived>
6148StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006149 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006150 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006151 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6152 TypeSourceInfo *T =
6153 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006154 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006156
David Majnemer5f7efef2013-10-15 09:50:08 +00006157 Var = getDerived().RebuildExceptionDecl(
6158 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6159 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006160 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006161 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006162 }
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregorebe10102009-08-20 07:17:43 +00006164 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006165 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006166 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006167 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006168
David Majnemer5f7efef2013-10-15 09:50:08 +00006169 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006171 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006172
David Majnemer5f7efef2013-10-15 09:50:08 +00006173 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006174}
Mike Stump11289f42009-09-09 15:08:12 +00006175
David Majnemer5f7efef2013-10-15 09:50:08 +00006176template <typename Derived>
6177StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006179 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006180 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006181 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 // Transform the handlers.
6184 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006185 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006186 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006187 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006188 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006189 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregorebe10102009-08-20 07:17:43 +00006191 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006192 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006193 }
Mike Stump11289f42009-09-09 15:08:12 +00006194
David Majnemer5f7efef2013-10-15 09:50:08 +00006195 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006197 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006198
John McCallb268a282010-08-23 23:25:46 +00006199 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006200 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006201}
Mike Stump11289f42009-09-09 15:08:12 +00006202
Richard Smith02e85f32011-04-14 22:09:26 +00006203template<typename Derived>
6204StmtResult
6205TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6206 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6207 if (Range.isInvalid())
6208 return StmtError();
6209
6210 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6211 if (BeginEnd.isInvalid())
6212 return StmtError();
6213
6214 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6215 if (Cond.isInvalid())
6216 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006217 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006218 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006219 if (Cond.isInvalid())
6220 return StmtError();
6221 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006222 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006223
6224 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6225 if (Inc.isInvalid())
6226 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006227 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006228 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006229
6230 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6231 if (LoopVar.isInvalid())
6232 return StmtError();
6233
6234 StmtResult NewStmt = S;
6235 if (getDerived().AlwaysRebuild() ||
6236 Range.get() != S->getRangeStmt() ||
6237 BeginEnd.get() != S->getBeginEndStmt() ||
6238 Cond.get() != S->getCond() ||
6239 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006240 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006241 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6242 S->getColonLoc(), Range.get(),
6243 BeginEnd.get(), Cond.get(),
6244 Inc.get(), LoopVar.get(),
6245 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006246 if (NewStmt.isInvalid())
6247 return StmtError();
6248 }
Richard Smith02e85f32011-04-14 22:09:26 +00006249
6250 StmtResult Body = getDerived().TransformStmt(S->getBody());
6251 if (Body.isInvalid())
6252 return StmtError();
6253
6254 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6255 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006256 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006257 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6258 S->getColonLoc(), Range.get(),
6259 BeginEnd.get(), Cond.get(),
6260 Inc.get(), LoopVar.get(),
6261 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006262 if (NewStmt.isInvalid())
6263 return StmtError();
6264 }
Richard Smith02e85f32011-04-14 22:09:26 +00006265
6266 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006267 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006268
6269 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6270}
6271
John Wiegley1c0675e2011-04-28 01:08:34 +00006272template<typename Derived>
6273StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006274TreeTransform<Derived>::TransformMSDependentExistsStmt(
6275 MSDependentExistsStmt *S) {
6276 // Transform the nested-name-specifier, if any.
6277 NestedNameSpecifierLoc QualifierLoc;
6278 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006279 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006280 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6281 if (!QualifierLoc)
6282 return StmtError();
6283 }
6284
6285 // Transform the declaration name.
6286 DeclarationNameInfo NameInfo = S->getNameInfo();
6287 if (NameInfo.getName()) {
6288 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6289 if (!NameInfo.getName())
6290 return StmtError();
6291 }
6292
6293 // Check whether anything changed.
6294 if (!getDerived().AlwaysRebuild() &&
6295 QualifierLoc == S->getQualifierLoc() &&
6296 NameInfo.getName() == S->getNameInfo().getName())
6297 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006298
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006299 // Determine whether this name exists, if we can.
6300 CXXScopeSpec SS;
6301 SS.Adopt(QualifierLoc);
6302 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006303 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006304 case Sema::IER_Exists:
6305 if (S->isIfExists())
6306 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006307
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006308 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6309
6310 case Sema::IER_DoesNotExist:
6311 if (S->isIfNotExists())
6312 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006313
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006314 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006315
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006316 case Sema::IER_Dependent:
6317 Dependent = true;
6318 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006319
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006320 case Sema::IER_Error:
6321 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006323
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006324 // We need to continue with the instantiation, so do so now.
6325 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6326 if (SubStmt.isInvalid())
6327 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006328
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006329 // If we have resolved the name, just transform to the substatement.
6330 if (!Dependent)
6331 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006333 // The name is still dependent, so build a dependent expression again.
6334 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6335 S->isIfExists(),
6336 QualifierLoc,
6337 NameInfo,
6338 SubStmt.get());
6339}
6340
6341template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006342ExprResult
6343TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6344 NestedNameSpecifierLoc QualifierLoc;
6345 if (E->getQualifierLoc()) {
6346 QualifierLoc
6347 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6348 if (!QualifierLoc)
6349 return ExprError();
6350 }
6351
6352 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6353 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6354 if (!PD)
6355 return ExprError();
6356
6357 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6358 if (Base.isInvalid())
6359 return ExprError();
6360
6361 return new (SemaRef.getASTContext())
6362 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6363 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6364 QualifierLoc, E->getMemberLoc());
6365}
6366
David Majnemerfad8f482013-10-15 09:33:02 +00006367template <typename Derived>
6368StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006369 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006370 if (TryBlock.isInvalid())
6371 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006372
6373 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006374 if (Handler.isInvalid())
6375 return StmtError();
6376
David Majnemerfad8f482013-10-15 09:33:02 +00006377 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6378 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006379 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006380
Warren Huntf6be4cb2014-07-25 20:52:51 +00006381 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6382 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006383}
6384
David Majnemerfad8f482013-10-15 09:33:02 +00006385template <typename Derived>
6386StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006387 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006388 if (Block.isInvalid())
6389 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006390
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006391 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006392}
6393
David Majnemerfad8f482013-10-15 09:33:02 +00006394template <typename Derived>
6395StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006396 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006397 if (FilterExpr.isInvalid())
6398 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006399
David Majnemer7e755502013-10-15 09:30:14 +00006400 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006401 if (Block.isInvalid())
6402 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006403
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006404 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6405 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006406}
6407
David Majnemerfad8f482013-10-15 09:33:02 +00006408template <typename Derived>
6409StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6410 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006411 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6412 else
6413 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6414}
6415
Nico Weber9b982072014-07-07 00:12:30 +00006416template<typename Derived>
6417StmtResult
6418TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6419 return S;
6420}
6421
Alexander Musman64d33f12014-06-04 07:53:32 +00006422//===----------------------------------------------------------------------===//
6423// OpenMP directive transformation
6424//===----------------------------------------------------------------------===//
6425template <typename Derived>
6426StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6427 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006428
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006429 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006430 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006431 ArrayRef<OMPClause *> Clauses = D->clauses();
6432 TClauses.reserve(Clauses.size());
6433 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6434 I != E; ++I) {
6435 if (*I) {
6436 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006437 if (Clause)
6438 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006439 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006440 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006441 }
6442 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006443 StmtResult AssociatedStmt;
6444 if (D->hasAssociatedStmt()) {
6445 if (!D->getAssociatedStmt()) {
6446 return StmtError();
6447 }
6448 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6449 if (AssociatedStmt.isInvalid()) {
6450 return StmtError();
6451 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006452 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006453 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006454 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006455 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006456
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006457 // Transform directive name for 'omp critical' directive.
6458 DeclarationNameInfo DirName;
6459 if (D->getDirectiveKind() == OMPD_critical) {
6460 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6461 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6462 }
6463
Alexander Musman64d33f12014-06-04 07:53:32 +00006464 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006465 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6466 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006467}
6468
Alexander Musman64d33f12014-06-04 07:53:32 +00006469template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006470StmtResult
6471TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6472 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006473 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6474 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006475 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6476 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6477 return Res;
6478}
6479
Alexander Musman64d33f12014-06-04 07:53:32 +00006480template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006481StmtResult
6482TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6483 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006484 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6485 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006486 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6487 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006488 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006489}
6490
Alexey Bataevf29276e2014-06-18 04:14:57 +00006491template <typename Derived>
6492StmtResult
6493TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6494 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006495 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6496 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6498 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6499 return Res;
6500}
6501
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006502template <typename Derived>
6503StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006504TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6505 DeclarationNameInfo DirName;
6506 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6507 D->getLocStart());
6508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6509 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6510 return Res;
6511}
6512
6513template <typename Derived>
6514StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006515TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6516 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006517 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6518 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006519 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6520 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6521 return Res;
6522}
6523
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006524template <typename Derived>
6525StmtResult
6526TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6527 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006528 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6529 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006530 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6531 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6532 return Res;
6533}
6534
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006535template <typename Derived>
6536StmtResult
6537TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6538 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006539 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6540 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006541 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6542 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6543 return Res;
6544}
6545
Alexey Bataev4acb8592014-07-07 13:01:15 +00006546template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006547StmtResult
6548TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6549 DeclarationNameInfo DirName;
6550 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6551 D->getLocStart());
6552 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6553 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6554 return Res;
6555}
6556
6557template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006558StmtResult
6559TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6560 getDerived().getSema().StartOpenMPDSABlock(
6561 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6563 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6564 return Res;
6565}
6566
6567template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006568StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6569 OMPParallelForDirective *D) {
6570 DeclarationNameInfo DirName;
6571 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6572 nullptr, D->getLocStart());
6573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6574 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6575 return Res;
6576}
6577
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006578template <typename Derived>
6579StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6580 OMPParallelSectionsDirective *D) {
6581 DeclarationNameInfo DirName;
6582 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6583 nullptr, D->getLocStart());
6584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6585 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6586 return Res;
6587}
6588
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006589template <typename Derived>
6590StmtResult
6591TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6592 DeclarationNameInfo DirName;
6593 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6594 D->getLocStart());
6595 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6596 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6597 return Res;
6598}
6599
Alexey Bataev68446b72014-07-18 07:47:19 +00006600template <typename Derived>
6601StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6602 OMPTaskyieldDirective *D) {
6603 DeclarationNameInfo DirName;
6604 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6605 D->getLocStart());
6606 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6607 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6608 return Res;
6609}
6610
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006611template <typename Derived>
6612StmtResult
6613TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6614 DeclarationNameInfo DirName;
6615 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6616 D->getLocStart());
6617 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6618 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6619 return Res;
6620}
6621
Alexey Bataev2df347a2014-07-18 10:17:07 +00006622template <typename Derived>
6623StmtResult
6624TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6625 DeclarationNameInfo DirName;
6626 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6627 D->getLocStart());
6628 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6629 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6630 return Res;
6631}
6632
Alexey Bataev6125da92014-07-21 11:26:11 +00006633template <typename Derived>
6634StmtResult
6635TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6636 DeclarationNameInfo DirName;
6637 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6638 D->getLocStart());
6639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6640 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6641 return Res;
6642}
6643
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006644template <typename Derived>
6645StmtResult
6646TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6647 DeclarationNameInfo DirName;
6648 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6649 D->getLocStart());
6650 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6651 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6652 return Res;
6653}
6654
Alexey Bataev0162e452014-07-22 10:10:35 +00006655template <typename Derived>
6656StmtResult
6657TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6658 DeclarationNameInfo DirName;
6659 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6660 D->getLocStart());
6661 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6662 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6663 return Res;
6664}
6665
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006666template <typename Derived>
6667StmtResult
6668TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6669 DeclarationNameInfo DirName;
6670 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6671 D->getLocStart());
6672 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6673 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6674 return Res;
6675}
6676
Alexander Musman64d33f12014-06-04 07:53:32 +00006677//===----------------------------------------------------------------------===//
6678// OpenMP clause transformation
6679//===----------------------------------------------------------------------===//
6680template <typename Derived>
6681OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006682 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6683 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006684 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006685 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006686 C->getLParenLoc(), C->getLocEnd());
6687}
6688
Alexander Musman64d33f12014-06-04 07:53:32 +00006689template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006690OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6691 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6692 if (Cond.isInvalid())
6693 return nullptr;
6694 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6695 C->getLParenLoc(), C->getLocEnd());
6696}
6697
6698template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006699OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006700TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6701 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6702 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006703 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006704 return getDerived().RebuildOMPNumThreadsClause(
6705 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006706}
6707
Alexey Bataev62c87d22014-03-21 04:51:18 +00006708template <typename Derived>
6709OMPClause *
6710TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6711 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6712 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006713 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006714 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006715 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006716}
6717
Alexander Musman8bd31e62014-05-27 15:12:19 +00006718template <typename Derived>
6719OMPClause *
6720TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6721 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6722 if (E.isInvalid())
6723 return 0;
6724 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006725 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006726}
6727
Alexander Musman64d33f12014-06-04 07:53:32 +00006728template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006729OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006730TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006731 return getDerived().RebuildOMPDefaultClause(
6732 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6733 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006734}
6735
Alexander Musman64d33f12014-06-04 07:53:32 +00006736template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006737OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006738TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006739 return getDerived().RebuildOMPProcBindClause(
6740 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6741 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006742}
6743
Alexander Musman64d33f12014-06-04 07:53:32 +00006744template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006745OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006746TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6747 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6748 if (E.isInvalid())
6749 return nullptr;
6750 return getDerived().RebuildOMPScheduleClause(
6751 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6752 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6753}
6754
6755template <typename Derived>
6756OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006757TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6758 // No need to rebuild this clause, no template-dependent parameters.
6759 return C;
6760}
6761
6762template <typename Derived>
6763OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006764TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6765 // No need to rebuild this clause, no template-dependent parameters.
6766 return C;
6767}
6768
6769template <typename Derived>
6770OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006771TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6772 // No need to rebuild this clause, no template-dependent parameters.
6773 return C;
6774}
6775
6776template <typename Derived>
6777OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006778TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6779 // No need to rebuild this clause, no template-dependent parameters.
6780 return C;
6781}
6782
6783template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006784OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6785 // No need to rebuild this clause, no template-dependent parameters.
6786 return C;
6787}
6788
6789template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006790OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6791 // No need to rebuild this clause, no template-dependent parameters.
6792 return C;
6793}
6794
6795template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006796OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006797TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6798 // No need to rebuild this clause, no template-dependent parameters.
6799 return C;
6800}
6801
6802template <typename Derived>
6803OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006804TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6805 // No need to rebuild this clause, no template-dependent parameters.
6806 return C;
6807}
6808
6809template <typename Derived>
6810OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006811TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6812 // No need to rebuild this clause, no template-dependent parameters.
6813 return C;
6814}
6815
6816template <typename Derived>
6817OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006818TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006819 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006820 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006821 for (auto *VE : C->varlists()) {
6822 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006823 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006824 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006825 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006826 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006827 return getDerived().RebuildOMPPrivateClause(
6828 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006829}
6830
Alexander Musman64d33f12014-06-04 07:53:32 +00006831template <typename Derived>
6832OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6833 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006834 llvm::SmallVector<Expr *, 16> Vars;
6835 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006836 for (auto *VE : C->varlists()) {
6837 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006838 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006839 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006840 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006841 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006842 return getDerived().RebuildOMPFirstprivateClause(
6843 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006844}
6845
Alexander Musman64d33f12014-06-04 07:53:32 +00006846template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006847OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006848TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6849 llvm::SmallVector<Expr *, 16> Vars;
6850 Vars.reserve(C->varlist_size());
6851 for (auto *VE : C->varlists()) {
6852 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6853 if (EVar.isInvalid())
6854 return nullptr;
6855 Vars.push_back(EVar.get());
6856 }
6857 return getDerived().RebuildOMPLastprivateClause(
6858 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6859}
6860
6861template <typename Derived>
6862OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006863TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6864 llvm::SmallVector<Expr *, 16> Vars;
6865 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006866 for (auto *VE : C->varlists()) {
6867 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006868 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006869 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006870 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006871 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006872 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6873 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006874}
6875
Alexander Musman64d33f12014-06-04 07:53:32 +00006876template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006877OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006878TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6879 llvm::SmallVector<Expr *, 16> Vars;
6880 Vars.reserve(C->varlist_size());
6881 for (auto *VE : C->varlists()) {
6882 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6883 if (EVar.isInvalid())
6884 return nullptr;
6885 Vars.push_back(EVar.get());
6886 }
6887 CXXScopeSpec ReductionIdScopeSpec;
6888 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6889
6890 DeclarationNameInfo NameInfo = C->getNameInfo();
6891 if (NameInfo.getName()) {
6892 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6893 if (!NameInfo.getName())
6894 return nullptr;
6895 }
6896 return getDerived().RebuildOMPReductionClause(
6897 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6898 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6899}
6900
6901template <typename Derived>
6902OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006903TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6904 llvm::SmallVector<Expr *, 16> Vars;
6905 Vars.reserve(C->varlist_size());
6906 for (auto *VE : C->varlists()) {
6907 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6908 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006909 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006910 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006911 }
6912 ExprResult Step = getDerived().TransformExpr(C->getStep());
6913 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006914 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006915 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6916 C->getLParenLoc(),
6917 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006918}
6919
Alexander Musman64d33f12014-06-04 07:53:32 +00006920template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006921OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006922TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6923 llvm::SmallVector<Expr *, 16> Vars;
6924 Vars.reserve(C->varlist_size());
6925 for (auto *VE : C->varlists()) {
6926 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6927 if (EVar.isInvalid())
6928 return nullptr;
6929 Vars.push_back(EVar.get());
6930 }
6931 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6932 if (Alignment.isInvalid())
6933 return nullptr;
6934 return getDerived().RebuildOMPAlignedClause(
6935 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6936 C->getColonLoc(), C->getLocEnd());
6937}
6938
Alexander Musman64d33f12014-06-04 07:53:32 +00006939template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006940OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006941TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6942 llvm::SmallVector<Expr *, 16> Vars;
6943 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006944 for (auto *VE : C->varlists()) {
6945 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006946 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006947 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006948 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006949 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006950 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6951 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006952}
6953
Alexey Bataevbae9a792014-06-27 10:37:06 +00006954template <typename Derived>
6955OMPClause *
6956TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6957 llvm::SmallVector<Expr *, 16> Vars;
6958 Vars.reserve(C->varlist_size());
6959 for (auto *VE : C->varlists()) {
6960 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6961 if (EVar.isInvalid())
6962 return nullptr;
6963 Vars.push_back(EVar.get());
6964 }
6965 return getDerived().RebuildOMPCopyprivateClause(
6966 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6967}
6968
Alexey Bataev6125da92014-07-21 11:26:11 +00006969template <typename Derived>
6970OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6971 llvm::SmallVector<Expr *, 16> Vars;
6972 Vars.reserve(C->varlist_size());
6973 for (auto *VE : C->varlists()) {
6974 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6975 if (EVar.isInvalid())
6976 return nullptr;
6977 Vars.push_back(EVar.get());
6978 }
6979 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6980 C->getLParenLoc(), C->getLocEnd());
6981}
6982
Douglas Gregorebe10102009-08-20 07:17:43 +00006983//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006984// Expression transformation
6985//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006988TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006989 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006990}
Mike Stump11289f42009-09-09 15:08:12 +00006991
6992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006994TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006995 NestedNameSpecifierLoc QualifierLoc;
6996 if (E->getQualifierLoc()) {
6997 QualifierLoc
6998 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6999 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007000 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007001 }
John McCallce546572009-12-08 09:08:17 +00007002
7003 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007004 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7005 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007006 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007008
John McCall815039a2010-08-17 21:27:17 +00007009 DeclarationNameInfo NameInfo = E->getNameInfo();
7010 if (NameInfo.getName()) {
7011 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7012 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007013 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007014 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007015
7016 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007017 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007018 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007019 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007020 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007021
7022 // Mark it referenced in the new context regardless.
7023 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007024 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007025
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007026 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007027 }
John McCallce546572009-12-08 09:08:17 +00007028
Craig Topperc3ec1492014-05-26 06:22:03 +00007029 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007030 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007031 TemplateArgs = &TransArgs;
7032 TransArgs.setLAngleLoc(E->getLAngleLoc());
7033 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007034 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7035 E->getNumTemplateArgs(),
7036 TransArgs))
7037 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007038 }
7039
Chad Rosier1dcde962012-08-08 18:46:20 +00007040 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007041 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007042}
Mike Stump11289f42009-09-09 15:08:12 +00007043
Douglas Gregora16548e2009-08-11 05:31:07 +00007044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007046TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007047 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007048}
Mike Stump11289f42009-09-09 15:08:12 +00007049
Douglas Gregora16548e2009-08-11 05:31:07 +00007050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007052TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007053 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007054}
Mike Stump11289f42009-09-09 15:08:12 +00007055
Douglas Gregora16548e2009-08-11 05:31:07 +00007056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007058TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007059 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007060}
Mike Stump11289f42009-09-09 15:08:12 +00007061
Douglas Gregora16548e2009-08-11 05:31:07 +00007062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007064TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007065 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007066}
Mike Stump11289f42009-09-09 15:08:12 +00007067
Douglas Gregora16548e2009-08-11 05:31:07 +00007068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007070TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007071 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007072}
7073
7074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007075ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007076TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007077 if (FunctionDecl *FD = E->getDirectCallee())
7078 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007079 return SemaRef.MaybeBindToTemporary(E);
7080}
7081
7082template<typename Derived>
7083ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007084TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7085 ExprResult ControllingExpr =
7086 getDerived().TransformExpr(E->getControllingExpr());
7087 if (ControllingExpr.isInvalid())
7088 return ExprError();
7089
Chris Lattner01cf8db2011-07-20 06:58:45 +00007090 SmallVector<Expr *, 4> AssocExprs;
7091 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007092 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7093 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7094 if (TS) {
7095 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7096 if (!AssocType)
7097 return ExprError();
7098 AssocTypes.push_back(AssocType);
7099 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007100 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007101 }
7102
7103 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7104 if (AssocExpr.isInvalid())
7105 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007106 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007107 }
7108
7109 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7110 E->getDefaultLoc(),
7111 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007112 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007113 AssocTypes,
7114 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007115}
7116
7117template<typename Derived>
7118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007119TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007120 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007123
Douglas Gregora16548e2009-08-11 05:31:07 +00007124 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007125 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007126
John McCallb268a282010-08-23 23:25:46 +00007127 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 E->getRParen());
7129}
7130
Richard Smithdb2630f2012-10-21 03:28:35 +00007131/// \brief The operand of a unary address-of operator has special rules: it's
7132/// allowed to refer to a non-static member of a class even if there's no 'this'
7133/// object available.
7134template<typename Derived>
7135ExprResult
7136TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7137 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007138 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007139 else
7140 return getDerived().TransformExpr(E);
7141}
7142
Mike Stump11289f42009-09-09 15:08:12 +00007143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007144ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007145TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007146 ExprResult SubExpr;
7147 if (E->getOpcode() == UO_AddrOf)
7148 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7149 else
7150 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007153
Douglas Gregora16548e2009-08-11 05:31:07 +00007154 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007155 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007156
Douglas Gregora16548e2009-08-11 05:31:07 +00007157 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7158 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007159 SubExpr.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
Douglas Gregor882211c2010-04-28 22:16:22 +00007164TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7165 // Transform the type.
7166 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7167 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007168 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007169
Douglas Gregor882211c2010-04-28 22:16:22 +00007170 // Transform all of the components into components similar to what the
7171 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007172 // FIXME: It would be slightly more efficient in the non-dependent case to
7173 // just map FieldDecls, rather than requiring the rebuilder to look for
7174 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007175 // template code that we don't care.
7176 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007177 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007178 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007179 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007180 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7181 const Node &ON = E->getComponent(I);
7182 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007183 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007184 Comp.LocStart = ON.getSourceRange().getBegin();
7185 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007186 switch (ON.getKind()) {
7187 case Node::Array: {
7188 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007189 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007190 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007192
Douglas Gregor882211c2010-04-28 22:16:22 +00007193 ExprChanged = ExprChanged || Index.get() != FromIndex;
7194 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007195 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007196 break;
7197 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007198
Douglas Gregor882211c2010-04-28 22:16:22 +00007199 case Node::Field:
7200 case Node::Identifier:
7201 Comp.isBrackets = false;
7202 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007203 if (!Comp.U.IdentInfo)
7204 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007205
Douglas Gregor882211c2010-04-28 22:16:22 +00007206 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007207
Douglas Gregord1702062010-04-29 00:18:15 +00007208 case Node::Base:
7209 // Will be recomputed during the rebuild.
7210 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007211 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007212
Douglas Gregor882211c2010-04-28 22:16:22 +00007213 Components.push_back(Comp);
7214 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007215
Douglas Gregor882211c2010-04-28 22:16:22 +00007216 // If nothing changed, retain the existing expression.
7217 if (!getDerived().AlwaysRebuild() &&
7218 Type == E->getTypeSourceInfo() &&
7219 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007220 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007221
Douglas Gregor882211c2010-04-28 22:16:22 +00007222 // Build a new offsetof expression.
7223 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7224 Components.data(), Components.size(),
7225 E->getRParenLoc());
7226}
7227
7228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007229ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007230TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7231 assert(getDerived().AlreadyTransformed(E->getType()) &&
7232 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007233 return E;
John McCall8d69a212010-11-15 23:31:06 +00007234}
7235
7236template<typename Derived>
7237ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007238TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007239 // Rebuild the syntactic form. The original syntactic form has
7240 // opaque-value expressions in it, so strip those away and rebuild
7241 // the result. This is a really awful way of doing this, but the
7242 // better solution (rebuilding the semantic expressions and
7243 // rebinding OVEs as necessary) doesn't work; we'd need
7244 // TreeTransform to not strip away implicit conversions.
7245 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7246 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007247 if (result.isInvalid()) return ExprError();
7248
7249 // If that gives us a pseudo-object result back, the pseudo-object
7250 // expression must have been an lvalue-to-rvalue conversion which we
7251 // should reapply.
7252 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007253 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007254
7255 return result;
7256}
7257
7258template<typename Derived>
7259ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007260TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7261 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007262 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007263 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007264
John McCallbcd03502009-12-07 02:54:59 +00007265 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007266 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007268
John McCall4c98fd82009-11-04 07:28:41 +00007269 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007270 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007271
Peter Collingbournee190dee2011-03-11 19:24:49 +00007272 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7273 E->getKind(),
7274 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007275 }
Mike Stump11289f42009-09-09 15:08:12 +00007276
Eli Friedmane4f22df2012-02-29 04:03:55 +00007277 // C++0x [expr.sizeof]p1:
7278 // The operand is either an expression, which is an unevaluated operand
7279 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007280 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7281 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007282
Reid Kleckner32506ed2014-06-12 23:03:48 +00007283 // Try to recover if we have something like sizeof(T::X) where X is a type.
7284 // Notably, there must be *exactly* one set of parens if X is a type.
7285 TypeSourceInfo *RecoveryTSI = nullptr;
7286 ExprResult SubExpr;
7287 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7288 if (auto *DRE =
7289 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7290 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7291 PE, DRE, false, &RecoveryTSI);
7292 else
7293 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7294
7295 if (RecoveryTSI) {
7296 return getDerived().RebuildUnaryExprOrTypeTrait(
7297 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7298 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007300
Eli Friedmane4f22df2012-02-29 04:03:55 +00007301 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007302 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007303
Peter Collingbournee190dee2011-03-11 19:24:49 +00007304 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7305 E->getOperatorLoc(),
7306 E->getKind(),
7307 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007313 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007316
John McCalldadc5752010-08-24 06:29:42 +00007317 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007318 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007320
7321
Douglas Gregora16548e2009-08-11 05:31:07 +00007322 if (!getDerived().AlwaysRebuild() &&
7323 LHS.get() == E->getLHS() &&
7324 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007325 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007326
John McCallb268a282010-08-23 23:25:46 +00007327 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007328 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007329 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 E->getRBracketLoc());
7331}
Mike Stump11289f42009-09-09 15:08:12 +00007332
7333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007334ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007335TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007337 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007338 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007339 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007340
7341 // Transform arguments.
7342 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007343 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007344 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007345 &ArgChanged))
7346 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007347
Douglas Gregora16548e2009-08-11 05:31:07 +00007348 if (!getDerived().AlwaysRebuild() &&
7349 Callee.get() == E->getCallee() &&
7350 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007351 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007352
Douglas Gregora16548e2009-08-11 05:31:07 +00007353 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007354 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007356 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007357 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 E->getRParenLoc());
7359}
Mike Stump11289f42009-09-09 15:08:12 +00007360
7361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007363TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007364 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregorea972d32011-02-28 21:54:11 +00007368 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007369 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007370 QualifierLoc
7371 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007372
Douglas Gregorea972d32011-02-28 21:54:11 +00007373 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007374 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007375 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007376 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007377
Eli Friedman2cfcef62009-12-04 06:40:45 +00007378 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007379 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7380 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007381 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007383
John McCall16df1e52010-03-30 21:47:33 +00007384 NamedDecl *FoundDecl = E->getFoundDecl();
7385 if (FoundDecl == E->getMemberDecl()) {
7386 FoundDecl = Member;
7387 } else {
7388 FoundDecl = cast_or_null<NamedDecl>(
7389 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7390 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007391 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007392 }
7393
Douglas Gregora16548e2009-08-11 05:31:07 +00007394 if (!getDerived().AlwaysRebuild() &&
7395 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007396 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007397 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007398 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007399 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007400
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007401 // Mark it referenced in the new context regardless.
7402 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007403 SemaRef.MarkMemberReferenced(E);
7404
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007405 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007406 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007407
John McCall6b51f282009-11-23 01:53:49 +00007408 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007409 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007410 TransArgs.setLAngleLoc(E->getLAngleLoc());
7411 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007412 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7413 E->getNumTemplateArgs(),
7414 TransArgs))
7415 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007417
Douglas Gregora16548e2009-08-11 05:31:07 +00007418 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007419 SourceLocation FakeOperatorLoc =
7420 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007421
John McCall38836f02010-01-15 08:34:02 +00007422 // FIXME: to do this check properly, we will need to preserve the
7423 // first-qualifier-in-scope here, just in case we had a dependent
7424 // base (and therefore couldn't do the check) and a
7425 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007426 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007427
John McCallb268a282010-08-23 23:25:46 +00007428 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007430 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007431 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007432 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007433 Member,
John McCall16df1e52010-03-30 21:47:33 +00007434 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007435 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007436 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007437 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007438}
Mike Stump11289f42009-09-09 15:08:12 +00007439
Douglas Gregora16548e2009-08-11 05:31:07 +00007440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007442TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007443 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007444 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007446
John McCalldadc5752010-08-24 06:29:42 +00007447 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007448 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007450
Douglas Gregora16548e2009-08-11 05:31:07 +00007451 if (!getDerived().AlwaysRebuild() &&
7452 LHS.get() == E->getLHS() &&
7453 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007454 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007455
Lang Hames5de91cc2012-10-02 04:45:10 +00007456 Sema::FPContractStateRAII FPContractState(getSema());
7457 getSema().FPFeatures.fp_contract = E->isFPContractable();
7458
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007460 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007461}
7462
Mike Stump11289f42009-09-09 15:08:12 +00007463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007464ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007465TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007466 CompoundAssignOperator *E) {
7467 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007468}
Mike Stump11289f42009-09-09 15:08:12 +00007469
Douglas Gregora16548e2009-08-11 05:31:07 +00007470template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007471ExprResult TreeTransform<Derived>::
7472TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7473 // Just rebuild the common and RHS expressions and see whether we
7474 // get any changes.
7475
7476 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7477 if (commonExpr.isInvalid())
7478 return ExprError();
7479
7480 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7481 if (rhs.isInvalid())
7482 return ExprError();
7483
7484 if (!getDerived().AlwaysRebuild() &&
7485 commonExpr.get() == e->getCommon() &&
7486 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007487 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007488
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007489 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007490 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007491 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007492 e->getColonLoc(),
7493 rhs.get());
7494}
7495
7496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007497ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007498TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007499 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007500 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007502
John McCalldadc5752010-08-24 06:29:42 +00007503 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007504 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007506
John McCalldadc5752010-08-24 06:29:42 +00007507 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007508 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007510
Douglas Gregora16548e2009-08-11 05:31:07 +00007511 if (!getDerived().AlwaysRebuild() &&
7512 Cond.get() == E->getCond() &&
7513 LHS.get() == E->getLHS() &&
7514 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007515 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007516
John McCallb268a282010-08-23 23:25:46 +00007517 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007518 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007519 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007520 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007521 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007522}
Mike Stump11289f42009-09-09 15:08:12 +00007523
7524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007526TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007527 // Implicit casts are eliminated during transformation, since they
7528 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007529 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007530}
Mike Stump11289f42009-09-09 15:08:12 +00007531
Douglas Gregora16548e2009-08-11 05:31:07 +00007532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007534TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007535 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7536 if (!Type)
7537 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007538
John McCalldadc5752010-08-24 06:29:42 +00007539 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007540 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007543
Douglas Gregora16548e2009-08-11 05:31:07 +00007544 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007545 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007547 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007548
John McCall97513962010-01-15 18:39:57 +00007549 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007550 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007552 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007553}
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregora16548e2009-08-11 05:31:07 +00007555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007556ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007557TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007558 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7559 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7560 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007562
John McCalldadc5752010-08-24 06:29:42 +00007563 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007564 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007566
Douglas Gregora16548e2009-08-11 05:31:07 +00007567 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007568 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007570 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007571
John McCall5d7aa7f2010-01-19 22:33:45 +00007572 // Note: the expression type doesn't necessarily match the
7573 // type-as-written, but that's okay, because it should always be
7574 // derivable from the initializer.
7575
John McCalle15bbff2010-01-18 19:35:47 +00007576 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007578 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007579}
Mike Stump11289f42009-09-09 15:08:12 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007583TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007584 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007585 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007587
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 if (!getDerived().AlwaysRebuild() &&
7589 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007590 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007591
Douglas Gregora16548e2009-08-11 05:31:07 +00007592 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007593 SourceLocation FakeOperatorLoc =
7594 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007595 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 E->getAccessorLoc(),
7597 E->getAccessor());
7598}
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregora16548e2009-08-11 05:31:07 +00007600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007601ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007602TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007603 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007604
Benjamin Kramerf0623432012-08-23 22:51:59 +00007605 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007606 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007607 Inits, &InitChanged))
7608 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007609
Douglas Gregora16548e2009-08-11 05:31:07 +00007610 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007611 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007612
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007613 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007614 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007615}
Mike Stump11289f42009-09-09 15:08:12 +00007616
Douglas Gregora16548e2009-08-11 05:31:07 +00007617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007619TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007620 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007621
Douglas Gregorebe10102009-08-20 07:17:43 +00007622 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007623 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007624 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007626
Douglas Gregorebe10102009-08-20 07:17:43 +00007627 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007628 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007629 bool ExprChanged = false;
7630 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7631 DEnd = E->designators_end();
7632 D != DEnd; ++D) {
7633 if (D->isFieldDesignator()) {
7634 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7635 D->getDotLoc(),
7636 D->getFieldLoc()));
7637 continue;
7638 }
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregora16548e2009-08-11 05:31:07 +00007640 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007641 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007642 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007644
7645 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007646 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007647
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007649 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007650 continue;
7651 }
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007654 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007655 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7656 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007658
John McCalldadc5752010-08-24 06:29:42 +00007659 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007660 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007662
7663 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007664 End.get(),
7665 D->getLBracketLoc(),
7666 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007667
Douglas Gregora16548e2009-08-11 05:31:07 +00007668 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7669 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007670
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007671 ArrayExprs.push_back(Start.get());
7672 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007673 }
Mike Stump11289f42009-09-09 15:08:12 +00007674
Douglas Gregora16548e2009-08-11 05:31:07 +00007675 if (!getDerived().AlwaysRebuild() &&
7676 Init.get() == E->getInit() &&
7677 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007678 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007679
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007680 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007681 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007682 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007683}
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregora16548e2009-08-11 05:31:07 +00007685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007686ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007687TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007688 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007689 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007690
Douglas Gregor3da3c062009-10-28 00:29:27 +00007691 // FIXME: Will we ever have proper type location here? Will we actually
7692 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 QualType T = getDerived().TransformType(E->getType());
7694 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007696
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 if (!getDerived().AlwaysRebuild() &&
7698 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007699 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007700
Douglas Gregora16548e2009-08-11 05:31:07 +00007701 return getDerived().RebuildImplicitValueInitExpr(T);
7702}
Mike Stump11289f42009-09-09 15:08:12 +00007703
Douglas Gregora16548e2009-08-11 05:31:07 +00007704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007706TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007707 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7708 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007710
John McCalldadc5752010-08-24 06:29:42 +00007711 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007714
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007716 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007717 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007718 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007719
John McCallb268a282010-08-23 23:25:46 +00007720 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007721 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007722}
7723
7724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007726TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007728 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007729 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7730 &ArgumentChanged))
7731 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007732
Douglas Gregora16548e2009-08-11 05:31:07 +00007733 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007734 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007735 E->getRParenLoc());
7736}
Mike Stump11289f42009-09-09 15:08:12 +00007737
Douglas Gregora16548e2009-08-11 05:31:07 +00007738/// \brief Transform an address-of-label expression.
7739///
7740/// By default, the transformation of an address-of-label expression always
7741/// rebuilds the expression, so that the label identifier can be resolved to
7742/// the corresponding label statement by semantic analysis.
7743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007745TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007746 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7747 E->getLabel());
7748 if (!LD)
7749 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007750
Douglas Gregora16548e2009-08-11 05:31:07 +00007751 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007752 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007753}
Mike Stump11289f42009-09-09 15:08:12 +00007754
7755template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007756ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007757TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007758 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007759 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007760 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007761 if (SubStmt.isInvalid()) {
7762 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007763 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007764 }
Mike Stump11289f42009-09-09 15:08:12 +00007765
Douglas Gregora16548e2009-08-11 05:31:07 +00007766 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007767 SubStmt.get() == E->getSubStmt()) {
7768 // Calling this an 'error' is unintuitive, but it does the right thing.
7769 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007770 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007771 }
Mike Stump11289f42009-09-09 15:08:12 +00007772
7773 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007774 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007775 E->getRParenLoc());
7776}
Mike Stump11289f42009-09-09 15:08:12 +00007777
Douglas Gregora16548e2009-08-11 05:31:07 +00007778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007780TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007781 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007782 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007783 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007784
John McCalldadc5752010-08-24 06:29:42 +00007785 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007786 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007788
John McCalldadc5752010-08-24 06:29:42 +00007789 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007790 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007792
Douglas Gregora16548e2009-08-11 05:31:07 +00007793 if (!getDerived().AlwaysRebuild() &&
7794 Cond.get() == E->getCond() &&
7795 LHS.get() == E->getLHS() &&
7796 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007797 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007798
Douglas Gregora16548e2009-08-11 05:31:07 +00007799 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007800 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007801 E->getRParenLoc());
7802}
Mike Stump11289f42009-09-09 15:08:12 +00007803
Douglas Gregora16548e2009-08-11 05:31:07 +00007804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007806TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007807 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007808}
7809
7810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007812TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007813 switch (E->getOperator()) {
7814 case OO_New:
7815 case OO_Delete:
7816 case OO_Array_New:
7817 case OO_Array_Delete:
7818 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007819
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007820 case OO_Call: {
7821 // This is a call to an object's operator().
7822 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7823
7824 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007825 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007826 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007827 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007828
7829 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007830 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7831 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007832
7833 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007834 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007835 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007836 Args))
7837 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007838
John McCallb268a282010-08-23 23:25:46 +00007839 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007840 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007841 E->getLocEnd());
7842 }
7843
7844#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7845 case OO_##Name:
7846#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7847#include "clang/Basic/OperatorKinds.def"
7848 case OO_Subscript:
7849 // Handled below.
7850 break;
7851
7852 case OO_Conditional:
7853 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007854
7855 case OO_None:
7856 case NUM_OVERLOADED_OPERATORS:
7857 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007858 }
7859
John McCalldadc5752010-08-24 06:29:42 +00007860 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007861 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007863
Richard Smithdb2630f2012-10-21 03:28:35 +00007864 ExprResult First;
7865 if (E->getOperator() == OO_Amp)
7866 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7867 else
7868 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007869 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007870 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007871
John McCalldadc5752010-08-24 06:29:42 +00007872 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 if (E->getNumArgs() == 2) {
7874 Second = getDerived().TransformExpr(E->getArg(1));
7875 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007876 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007877 }
Mike Stump11289f42009-09-09 15:08:12 +00007878
Douglas Gregora16548e2009-08-11 05:31:07 +00007879 if (!getDerived().AlwaysRebuild() &&
7880 Callee.get() == E->getCallee() &&
7881 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007882 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007883 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007884
Lang Hames5de91cc2012-10-02 04:45:10 +00007885 Sema::FPContractStateRAII FPContractState(getSema());
7886 getSema().FPFeatures.fp_contract = E->isFPContractable();
7887
Douglas Gregora16548e2009-08-11 05:31:07 +00007888 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7889 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007890 Callee.get(),
7891 First.get(),
7892 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007893}
Mike Stump11289f42009-09-09 15:08:12 +00007894
Douglas Gregora16548e2009-08-11 05:31:07 +00007895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007896ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007897TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7898 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007899}
Mike Stump11289f42009-09-09 15:08:12 +00007900
Douglas Gregora16548e2009-08-11 05:31:07 +00007901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007902ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007903TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7904 // Transform the callee.
7905 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7906 if (Callee.isInvalid())
7907 return ExprError();
7908
7909 // Transform exec config.
7910 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7911 if (EC.isInvalid())
7912 return ExprError();
7913
7914 // Transform arguments.
7915 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007916 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007917 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007918 &ArgChanged))
7919 return ExprError();
7920
7921 if (!getDerived().AlwaysRebuild() &&
7922 Callee.get() == E->getCallee() &&
7923 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007924 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007925
7926 // FIXME: Wrong source location information for the '('.
7927 SourceLocation FakeLParenLoc
7928 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7929 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007930 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007931 E->getRParenLoc(), EC.get());
7932}
7933
7934template<typename Derived>
7935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007936TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007937 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7938 if (!Type)
7939 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007940
John McCalldadc5752010-08-24 06:29:42 +00007941 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007942 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007943 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007944 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007945
Douglas Gregora16548e2009-08-11 05:31:07 +00007946 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007947 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007948 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007949 return E;
Nico Weberc153d242014-07-28 00:02:09 +00007950 return getDerived().RebuildCXXNamedCastExpr(
7951 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
7952 Type, E->getAngleBrackets().getEnd(),
7953 // FIXME. this should be '(' location
7954 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007955}
Mike Stump11289f42009-09-09 15:08:12 +00007956
Douglas Gregora16548e2009-08-11 05:31:07 +00007957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007959TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7960 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007961}
Mike Stump11289f42009-09-09 15:08:12 +00007962
7963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007965TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7966 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007967}
7968
Douglas Gregora16548e2009-08-11 05:31:07 +00007969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007970ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007971TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007972 CXXReinterpretCastExpr *E) {
7973 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007974}
Mike Stump11289f42009-09-09 15:08:12 +00007975
Douglas Gregora16548e2009-08-11 05:31:07 +00007976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007978TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7979 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007980}
Mike Stump11289f42009-09-09 15:08:12 +00007981
Douglas Gregora16548e2009-08-11 05:31:07 +00007982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007983ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007984TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007985 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007986 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7987 if (!Type)
7988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007989
John McCalldadc5752010-08-24 06:29:42 +00007990 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007991 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007992 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007994
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007996 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007997 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007998 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007999
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008000 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008001 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008002 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 E->getRParenLoc());
8004}
Mike Stump11289f42009-09-09 15:08:12 +00008005
Douglas Gregora16548e2009-08-11 05:31:07 +00008006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008008TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008009 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008010 TypeSourceInfo *TInfo
8011 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8012 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008014
Douglas Gregora16548e2009-08-11 05:31:07 +00008015 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008016 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008017 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008018
Douglas Gregor9da64192010-04-26 22:37:10 +00008019 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8020 E->getLocStart(),
8021 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008022 E->getLocEnd());
8023 }
Mike Stump11289f42009-09-09 15:08:12 +00008024
Eli Friedman456f0182012-01-20 01:26:23 +00008025 // We don't know whether the subexpression is potentially evaluated until
8026 // after we perform semantic analysis. We speculatively assume it is
8027 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008028 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008029 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8030 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008031
John McCalldadc5752010-08-24 06:29:42 +00008032 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008033 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008035
Douglas Gregora16548e2009-08-11 05:31:07 +00008036 if (!getDerived().AlwaysRebuild() &&
8037 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008038 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008039
Douglas Gregor9da64192010-04-26 22:37:10 +00008040 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8041 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008042 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 E->getLocEnd());
8044}
8045
8046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008047ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008048TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8049 if (E->isTypeOperand()) {
8050 TypeSourceInfo *TInfo
8051 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8052 if (!TInfo)
8053 return ExprError();
8054
8055 if (!getDerived().AlwaysRebuild() &&
8056 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008057 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008058
Douglas Gregor69735112011-03-06 17:40:41 +00008059 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008060 E->getLocStart(),
8061 TInfo,
8062 E->getLocEnd());
8063 }
8064
Francois Pichet9f4f2072010-09-08 12:20:18 +00008065 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8066
8067 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8068 if (SubExpr.isInvalid())
8069 return ExprError();
8070
8071 if (!getDerived().AlwaysRebuild() &&
8072 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008073 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008074
8075 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8076 E->getLocStart(),
8077 SubExpr.get(),
8078 E->getLocEnd());
8079}
8080
8081template<typename Derived>
8082ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008083TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008084 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008085}
Mike Stump11289f42009-09-09 15:08:12 +00008086
Douglas Gregora16548e2009-08-11 05:31:07 +00008087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008088ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008089TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008090 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008091 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008092}
Mike Stump11289f42009-09-09 15:08:12 +00008093
Douglas Gregora16548e2009-08-11 05:31:07 +00008094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008096TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008097 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008098
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008099 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8100 // Make sure that we capture 'this'.
8101 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008102 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008104
Douglas Gregorb15af892010-01-07 23:12:05 +00008105 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008106}
Mike Stump11289f42009-09-09 15:08:12 +00008107
Douglas Gregora16548e2009-08-11 05:31:07 +00008108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008110TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008111 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008112 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008114
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 if (!getDerived().AlwaysRebuild() &&
8116 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008117 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008118
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008119 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8120 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008121}
Mike Stump11289f42009-09-09 15:08:12 +00008122
Douglas Gregora16548e2009-08-11 05:31:07 +00008123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008125TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008126 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008127 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8128 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008129 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008131
Chandler Carruth794da4c2010-02-08 06:42:49 +00008132 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008133 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008134 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008135
Douglas Gregor033f6752009-12-23 23:03:06 +00008136 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008137}
Mike Stump11289f42009-09-09 15:08:12 +00008138
Douglas Gregora16548e2009-08-11 05:31:07 +00008139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008140ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008141TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8142 FieldDecl *Field
8143 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8144 E->getField()));
8145 if (!Field)
8146 return ExprError();
8147
8148 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008149 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008150
8151 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8152}
8153
8154template<typename Derived>
8155ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008156TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8157 CXXScalarValueInitExpr *E) {
8158 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8159 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008163 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008164 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008165
Chad Rosier1dcde962012-08-08 18:46:20 +00008166 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008167 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008168 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008169}
Mike Stump11289f42009-09-09 15:08:12 +00008170
Douglas Gregora16548e2009-08-11 05:31:07 +00008171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008173TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008175 TypeSourceInfo *AllocTypeInfo
8176 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8177 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008179
Douglas Gregora16548e2009-08-11 05:31:07 +00008180 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008181 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008182 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008184
Douglas Gregora16548e2009-08-11 05:31:07 +00008185 // Transform the placement arguments (if any).
8186 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008187 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008188 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008189 E->getNumPlacementArgs(), true,
8190 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008192
Sebastian Redl6047f072012-02-16 12:22:20 +00008193 // Transform the initializer (if any).
8194 Expr *OldInit = E->getInitializer();
8195 ExprResult NewInit;
8196 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008197 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008198 if (NewInit.isInvalid())
8199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008200
Sebastian Redl6047f072012-02-16 12:22:20 +00008201 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008202 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008203 if (E->getOperatorNew()) {
8204 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008205 getDerived().TransformDecl(E->getLocStart(),
8206 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008207 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008208 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008209 }
8210
Craig Topperc3ec1492014-05-26 06:22:03 +00008211 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008212 if (E->getOperatorDelete()) {
8213 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008214 getDerived().TransformDecl(E->getLocStart(),
8215 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008216 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008219
Douglas Gregora16548e2009-08-11 05:31:07 +00008220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008221 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008222 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008223 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008224 OperatorNew == E->getOperatorNew() &&
8225 OperatorDelete == E->getOperatorDelete() &&
8226 !ArgumentChanged) {
8227 // Mark any declarations we need as referenced.
8228 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008229 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008230 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008231 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008232 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008233
Sebastian Redl6047f072012-02-16 12:22:20 +00008234 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008235 QualType ElementType
8236 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8237 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8238 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8239 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008240 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008241 }
8242 }
8243 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008244
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008245 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008246 }
Mike Stump11289f42009-09-09 15:08:12 +00008247
Douglas Gregor0744ef62010-09-07 21:49:58 +00008248 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008249 if (!ArraySize.get()) {
8250 // If no array size was specified, but the new expression was
8251 // instantiated with an array type (e.g., "new T" where T is
8252 // instantiated with "int[4]"), extract the outer bound from the
8253 // array type as our array size. We do this with constant and
8254 // dependently-sized array types.
8255 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8256 if (!ArrayT) {
8257 // Do nothing
8258 } else if (const ConstantArrayType *ConsArrayT
8259 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008260 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8261 SemaRef.Context.getSizeType(),
8262 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008263 AllocType = ConsArrayT->getElementType();
8264 } else if (const DependentSizedArrayType *DepArrayT
8265 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8266 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008267 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008268 AllocType = DepArrayT->getElementType();
8269 }
8270 }
8271 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008272
Douglas Gregora16548e2009-08-11 05:31:07 +00008273 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8274 E->isGlobalNew(),
8275 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008276 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008277 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008278 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008279 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008280 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008281 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008282 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008283 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008284}
Mike Stump11289f42009-09-09 15:08:12 +00008285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008287ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008288TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008289 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008290 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008292
Douglas Gregord2d9da02010-02-26 00:38:10 +00008293 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008294 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008295 if (E->getOperatorDelete()) {
8296 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008297 getDerived().TransformDecl(E->getLocStart(),
8298 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008299 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008300 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008301 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008302
Douglas Gregora16548e2009-08-11 05:31:07 +00008303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008304 Operand.get() == E->getArgument() &&
8305 OperatorDelete == E->getOperatorDelete()) {
8306 // Mark any declarations we need as referenced.
8307 // FIXME: instantiation-specific.
8308 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008309 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008310
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008311 if (!E->getArgument()->isTypeDependent()) {
8312 QualType Destroyed = SemaRef.Context.getBaseElementType(
8313 E->getDestroyedType());
8314 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8315 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008316 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008317 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008318 }
8319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008320
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008321 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008322 }
Mike Stump11289f42009-09-09 15:08:12 +00008323
Douglas Gregora16548e2009-08-11 05:31:07 +00008324 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8325 E->isGlobalDelete(),
8326 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008327 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008328}
Mike Stump11289f42009-09-09 15:08:12 +00008329
Douglas Gregora16548e2009-08-11 05:31:07 +00008330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008331ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008332TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008333 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008334 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008335 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008337
John McCallba7bf592010-08-24 05:47:05 +00008338 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008339 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008340 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008341 E->getOperatorLoc(),
8342 E->isArrow()? tok::arrow : tok::period,
8343 ObjectTypePtr,
8344 MayBePseudoDestructor);
8345 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008346 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008347
John McCallba7bf592010-08-24 05:47:05 +00008348 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008349 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8350 if (QualifierLoc) {
8351 QualifierLoc
8352 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8353 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008354 return ExprError();
8355 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008356 CXXScopeSpec SS;
8357 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008358
Douglas Gregor678f90d2010-02-25 01:56:36 +00008359 PseudoDestructorTypeStorage Destroyed;
8360 if (E->getDestroyedTypeInfo()) {
8361 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008362 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008363 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008364 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008365 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008366 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008367 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008368 // We aren't likely to be able to resolve the identifier down to a type
8369 // now anyway, so just retain the identifier.
8370 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8371 E->getDestroyedTypeLoc());
8372 } else {
8373 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008374 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008375 *E->getDestroyedTypeIdentifier(),
8376 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008377 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008378 SS, ObjectTypePtr,
8379 false);
8380 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008381 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008382
Douglas Gregor678f90d2010-02-25 01:56:36 +00008383 Destroyed
8384 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8385 E->getDestroyedTypeLoc());
8386 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008387
Craig Topperc3ec1492014-05-26 06:22:03 +00008388 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008389 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008390 CXXScopeSpec EmptySS;
8391 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008392 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008393 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008394 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008395 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008396
John McCallb268a282010-08-23 23:25:46 +00008397 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008398 E->getOperatorLoc(),
8399 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008400 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008401 ScopeTypeInfo,
8402 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008403 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008404 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008405}
Mike Stump11289f42009-09-09 15:08:12 +00008406
Douglas Gregorad8a3362009-09-04 17:36:40 +00008407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008408ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008409TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008410 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008411 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8412 Sema::LookupOrdinaryName);
8413
8414 // Transform all the decls.
8415 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8416 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008417 NamedDecl *InstD = static_cast<NamedDecl*>(
8418 getDerived().TransformDecl(Old->getNameLoc(),
8419 *I));
John McCall84d87672009-12-10 09:41:52 +00008420 if (!InstD) {
8421 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8422 // This can happen because of dependent hiding.
8423 if (isa<UsingShadowDecl>(*I))
8424 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008425 else {
8426 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008427 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008428 }
John McCall84d87672009-12-10 09:41:52 +00008429 }
John McCalle66edc12009-11-24 19:00:30 +00008430
8431 // Expand using declarations.
8432 if (isa<UsingDecl>(InstD)) {
8433 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008434 for (auto *I : UD->shadows())
8435 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008436 continue;
8437 }
8438
8439 R.addDecl(InstD);
8440 }
8441
8442 // Resolve a kind, but don't do any further analysis. If it's
8443 // ambiguous, the callee needs to deal with it.
8444 R.resolveKind();
8445
8446 // Rebuild the nested-name qualifier, if present.
8447 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008448 if (Old->getQualifierLoc()) {
8449 NestedNameSpecifierLoc QualifierLoc
8450 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8451 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008452 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008453
Douglas Gregor0da1d432011-02-28 20:01:57 +00008454 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008455 }
8456
Douglas Gregor9262f472010-04-27 18:19:34 +00008457 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008458 CXXRecordDecl *NamingClass
8459 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8460 Old->getNameLoc(),
8461 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008462 if (!NamingClass) {
8463 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008464 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008466
Douglas Gregorda7be082010-04-27 16:10:10 +00008467 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008468 }
8469
Abramo Bagnara7945c982012-01-27 09:46:47 +00008470 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8471
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008472 // If we have neither explicit template arguments, nor the template keyword,
8473 // it's a normal declaration name.
8474 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008475 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8476
8477 // If we have template arguments, rebuild them, then rebuild the
8478 // templateid expression.
8479 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008480 if (Old->hasExplicitTemplateArgs() &&
8481 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008482 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008483 TransArgs)) {
8484 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008485 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008486 }
John McCalle66edc12009-11-24 19:00:30 +00008487
Abramo Bagnara7945c982012-01-27 09:46:47 +00008488 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008489 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008490}
Mike Stump11289f42009-09-09 15:08:12 +00008491
Douglas Gregora16548e2009-08-11 05:31:07 +00008492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008493ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008494TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8495 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008496 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008497 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8498 TypeSourceInfo *From = E->getArg(I);
8499 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008500 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008501 TypeLocBuilder TLB;
8502 TLB.reserve(FromTL.getFullDataSize());
8503 QualType To = getDerived().TransformType(TLB, FromTL);
8504 if (To.isNull())
8505 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008506
Douglas Gregor29c42f22012-02-24 07:38:34 +00008507 if (To == From->getType())
8508 Args.push_back(From);
8509 else {
8510 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8511 ArgChanged = true;
8512 }
8513 continue;
8514 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008515
Douglas Gregor29c42f22012-02-24 07:38:34 +00008516 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008517
Douglas Gregor29c42f22012-02-24 07:38:34 +00008518 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008519 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008520 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8521 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8522 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008523
Douglas Gregor29c42f22012-02-24 07:38:34 +00008524 // Determine whether the set of unexpanded parameter packs can and should
8525 // be expanded.
8526 bool Expand = true;
8527 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008528 Optional<unsigned> OrigNumExpansions =
8529 ExpansionTL.getTypePtr()->getNumExpansions();
8530 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008531 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8532 PatternTL.getSourceRange(),
8533 Unexpanded,
8534 Expand, RetainExpansion,
8535 NumExpansions))
8536 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008537
Douglas Gregor29c42f22012-02-24 07:38:34 +00008538 if (!Expand) {
8539 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008540 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008541 // expansion.
8542 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008543
Douglas Gregor29c42f22012-02-24 07:38:34 +00008544 TypeLocBuilder TLB;
8545 TLB.reserve(From->getTypeLoc().getFullDataSize());
8546
8547 QualType To = getDerived().TransformType(TLB, PatternTL);
8548 if (To.isNull())
8549 return ExprError();
8550
Chad Rosier1dcde962012-08-08 18:46:20 +00008551 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008552 PatternTL.getSourceRange(),
8553 ExpansionTL.getEllipsisLoc(),
8554 NumExpansions);
8555 if (To.isNull())
8556 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008557
Douglas Gregor29c42f22012-02-24 07:38:34 +00008558 PackExpansionTypeLoc ToExpansionTL
8559 = TLB.push<PackExpansionTypeLoc>(To);
8560 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8561 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8562 continue;
8563 }
8564
8565 // Expand the pack expansion by substituting for each argument in the
8566 // pack(s).
8567 for (unsigned I = 0; I != *NumExpansions; ++I) {
8568 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8569 TypeLocBuilder TLB;
8570 TLB.reserve(PatternTL.getFullDataSize());
8571 QualType To = getDerived().TransformType(TLB, PatternTL);
8572 if (To.isNull())
8573 return ExprError();
8574
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008575 if (To->containsUnexpandedParameterPack()) {
8576 To = getDerived().RebuildPackExpansionType(To,
8577 PatternTL.getSourceRange(),
8578 ExpansionTL.getEllipsisLoc(),
8579 NumExpansions);
8580 if (To.isNull())
8581 return ExprError();
8582
8583 PackExpansionTypeLoc ToExpansionTL
8584 = TLB.push<PackExpansionTypeLoc>(To);
8585 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8586 }
8587
Douglas Gregor29c42f22012-02-24 07:38:34 +00008588 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008590
Douglas Gregor29c42f22012-02-24 07:38:34 +00008591 if (!RetainExpansion)
8592 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008593
Douglas Gregor29c42f22012-02-24 07:38:34 +00008594 // If we're supposed to retain a pack expansion, do so by temporarily
8595 // forgetting the partially-substituted parameter pack.
8596 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8597
8598 TypeLocBuilder TLB;
8599 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008600
Douglas Gregor29c42f22012-02-24 07:38:34 +00008601 QualType To = getDerived().TransformType(TLB, PatternTL);
8602 if (To.isNull())
8603 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008604
8605 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008606 PatternTL.getSourceRange(),
8607 ExpansionTL.getEllipsisLoc(),
8608 NumExpansions);
8609 if (To.isNull())
8610 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008611
Douglas Gregor29c42f22012-02-24 07:38:34 +00008612 PackExpansionTypeLoc ToExpansionTL
8613 = TLB.push<PackExpansionTypeLoc>(To);
8614 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8615 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8616 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008617
Douglas Gregor29c42f22012-02-24 07:38:34 +00008618 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008619 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008620
8621 return getDerived().RebuildTypeTrait(E->getTrait(),
8622 E->getLocStart(),
8623 Args,
8624 E->getLocEnd());
8625}
8626
8627template<typename Derived>
8628ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008629TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8630 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8631 if (!T)
8632 return ExprError();
8633
8634 if (!getDerived().AlwaysRebuild() &&
8635 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008636 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008637
8638 ExprResult SubExpr;
8639 {
8640 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8641 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8642 if (SubExpr.isInvalid())
8643 return ExprError();
8644
8645 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008646 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008647 }
8648
8649 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8650 E->getLocStart(),
8651 T,
8652 SubExpr.get(),
8653 E->getLocEnd());
8654}
8655
8656template<typename Derived>
8657ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008658TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8659 ExprResult SubExpr;
8660 {
8661 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8662 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8663 if (SubExpr.isInvalid())
8664 return ExprError();
8665
8666 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008667 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008668 }
8669
8670 return getDerived().RebuildExpressionTrait(
8671 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8672}
8673
Reid Kleckner32506ed2014-06-12 23:03:48 +00008674template <typename Derived>
8675ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8676 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8677 TypeSourceInfo **RecoveryTSI) {
8678 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8679 DRE, AddrTaken, RecoveryTSI);
8680
8681 // Propagate both errors and recovered types, which return ExprEmpty.
8682 if (!NewDRE.isUsable())
8683 return NewDRE;
8684
8685 // We got an expr, wrap it up in parens.
8686 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8687 return PE;
8688 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8689 PE->getRParen());
8690}
8691
8692template <typename Derived>
8693ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8694 DependentScopeDeclRefExpr *E) {
8695 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8696 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008697}
8698
8699template<typename Derived>
8700ExprResult
8701TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8702 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008703 bool IsAddressOfOperand,
8704 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008705 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008706 NestedNameSpecifierLoc QualifierLoc
8707 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8708 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008709 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008710 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008711
John McCall31f82722010-11-12 08:19:04 +00008712 // TODO: If this is a conversion-function-id, verify that the
8713 // destination type name (if present) resolves the same way after
8714 // instantiation as it did in the local scope.
8715
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008716 DeclarationNameInfo NameInfo
8717 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8718 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008720
John McCalle66edc12009-11-24 19:00:30 +00008721 if (!E->hasExplicitTemplateArgs()) {
8722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008723 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008724 // Note: it is sufficient to compare the Name component of NameInfo:
8725 // if name has not changed, DNLoc has not changed either.
8726 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008727 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008728
Reid Kleckner32506ed2014-06-12 23:03:48 +00008729 return getDerived().RebuildDependentScopeDeclRefExpr(
8730 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8731 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008732 }
John McCall6b51f282009-11-23 01:53:49 +00008733
8734 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008735 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8736 E->getNumTemplateArgs(),
8737 TransArgs))
8738 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008739
Reid Kleckner32506ed2014-06-12 23:03:48 +00008740 return getDerived().RebuildDependentScopeDeclRefExpr(
8741 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8742 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008743}
8744
8745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008747TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008748 // CXXConstructExprs other than for list-initialization and
8749 // CXXTemporaryObjectExpr are always implicit, so when we have
8750 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008751 if ((E->getNumArgs() == 1 ||
8752 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008753 (!getDerived().DropCallArgument(E->getArg(0))) &&
8754 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008755 return getDerived().TransformExpr(E->getArg(0));
8756
Douglas Gregora16548e2009-08-11 05:31:07 +00008757 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8758
8759 QualType T = getDerived().TransformType(E->getType());
8760 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008761 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008762
8763 CXXConstructorDecl *Constructor
8764 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008765 getDerived().TransformDecl(E->getLocStart(),
8766 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008767 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008769
Douglas Gregora16548e2009-08-11 05:31:07 +00008770 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008771 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008772 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008773 &ArgumentChanged))
8774 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008775
Douglas Gregora16548e2009-08-11 05:31:07 +00008776 if (!getDerived().AlwaysRebuild() &&
8777 T == E->getType() &&
8778 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008779 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008780 // Mark the constructor as referenced.
8781 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008782 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008783 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008784 }
Mike Stump11289f42009-09-09 15:08:12 +00008785
Douglas Gregordb121ba2009-12-14 16:27:04 +00008786 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8787 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008788 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008789 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008790 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008791 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008792 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008793 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008794 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008795}
Mike Stump11289f42009-09-09 15:08:12 +00008796
Douglas Gregora16548e2009-08-11 05:31:07 +00008797/// \brief Transform a C++ temporary-binding expression.
8798///
Douglas Gregor363b1512009-12-24 18:51:59 +00008799/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8800/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008803TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008804 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008805}
Mike Stump11289f42009-09-09 15:08:12 +00008806
John McCall5d413782010-12-06 08:20:24 +00008807/// \brief Transform a C++ expression that contains cleanups that should
8808/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008809///
John McCall5d413782010-12-06 08:20:24 +00008810/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008811/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008813ExprResult
John McCall5d413782010-12-06 08:20:24 +00008814TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008815 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008816}
Mike Stump11289f42009-09-09 15:08:12 +00008817
Douglas Gregora16548e2009-08-11 05:31:07 +00008818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008819ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008820TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008821 CXXTemporaryObjectExpr *E) {
8822 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8823 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 CXXConstructorDecl *Constructor
8827 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008828 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008829 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008830 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008832
Douglas Gregora16548e2009-08-11 05:31:07 +00008833 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008834 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008835 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008836 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008837 &ArgumentChanged))
8838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008839
Douglas Gregora16548e2009-08-11 05:31:07 +00008840 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008841 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008843 !ArgumentChanged) {
8844 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008845 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008846 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008847 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008848
Richard Smithd59b8322012-12-19 01:39:02 +00008849 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008850 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8851 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008852 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008853 E->getLocEnd());
8854}
Mike Stump11289f42009-09-09 15:08:12 +00008855
Douglas Gregora16548e2009-08-11 05:31:07 +00008856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008857ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008858TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008859
8860 // Transform any init-capture expressions before entering the scope of the
8861 // lambda body, because they are not semantically within that scope.
8862 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8863 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8864 E->explicit_capture_begin());
8865
8866 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8867 CEnd = E->capture_end();
8868 C != CEnd; ++C) {
8869 if (!C->isInitCapture())
8870 continue;
8871 EnterExpressionEvaluationContext EEEC(getSema(),
8872 Sema::PotentiallyEvaluated);
8873 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8874 C->getCapturedVar()->getInit(),
8875 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8876
8877 if (NewExprInitResult.isInvalid())
8878 return ExprError();
8879 Expr *NewExprInit = NewExprInitResult.get();
8880
8881 VarDecl *OldVD = C->getCapturedVar();
8882 QualType NewInitCaptureType =
8883 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8884 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8885 NewExprInit);
8886 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008887 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8888 std::make_pair(NewExprInitResult, NewInitCaptureType);
8889
8890 }
8891
Faisal Vali524ca282013-11-12 01:40:44 +00008892 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008893 // Transform the template parameters, and add them to the current
8894 // instantiation scope. The null case is handled correctly.
8895 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8896 E->getTemplateParameterList());
8897
8898 // Check to see if the TypeSourceInfo of the call operator needs to
8899 // be transformed, and if so do the transformation in the
8900 // CurrentInstantiationScope.
8901
8902 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8903 FunctionProtoTypeLoc OldCallOpFPTL =
8904 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008905 TypeSourceInfo *NewCallOpTSI = nullptr;
8906
Faisal Vali2cba1332013-10-23 06:44:28 +00008907 const bool CallOpWasAlreadyTransformed =
8908 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8909
8910 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8911 if (CallOpWasAlreadyTransformed)
8912 NewCallOpTSI = OldCallOpTSI;
8913 else {
8914 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8915 // The transformation MUST be done in the CurrentInstantiationScope since
8916 // it introduces a mapping of the original to the newly created
8917 // transformed parameters.
8918
8919 TypeLocBuilder NewCallOpTLBuilder;
Hans Wennborge113c202014-09-18 16:01:32 +00008920 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8921 OldCallOpFPTL,
8922 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008923 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8924 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008925 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008926 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8927 // the vector below - this will be used to synthesize the
8928 // NewCallOperator. Additionally, add the parameters of the untransformed
8929 // lambda call operator to the CurrentInstantiationScope.
8930 SmallVector<ParmVarDecl *, 4> Params;
8931 {
8932 FunctionProtoTypeLoc NewCallOpFPTL =
8933 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8934 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008935 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008936
8937 for (unsigned I = 0; I < NewNumArgs; ++I) {
8938 // If this call operator's type does not require transformation,
8939 // the parameters do not get added to the current instantiation scope,
8940 // - so ADD them! This allows the following to compile when the enclosing
8941 // template is specialized and the entire lambda expression has to be
8942 // transformed.
8943 // template<class T> void foo(T t) {
8944 // auto L = [](auto a) {
8945 // auto M = [](char b) { <-- note: non-generic lambda
8946 // auto N = [](auto c) {
8947 // int x = sizeof(a);
8948 // x = sizeof(b); <-- specifically this line
8949 // x = sizeof(c);
8950 // };
8951 // };
8952 // };
8953 // }
8954 // foo('a')
8955 if (CallOpWasAlreadyTransformed)
8956 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8957 NewParamDeclArray[I]);
8958 // Add to Params array, so these parameters can be used to create
8959 // the newly transformed call operator.
8960 Params.push_back(NewParamDeclArray[I]);
8961 }
8962 }
8963
8964 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008965 return ExprError();
8966
Eli Friedmand564afb2012-09-19 01:18:11 +00008967 // Create the local class that will describe the lambda.
8968 CXXRecordDecl *Class
8969 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008970 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008971 /*KnownDependent=*/false,
8972 E->getCaptureDefault());
8973
Eli Friedmand564afb2012-09-19 01:18:11 +00008974 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8975
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008976 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008977 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008978 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008979 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008980 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008981 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008982 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008983
Faisal Vali2cba1332013-10-23 06:44:28 +00008984 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8985
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008986 return getDerived().TransformLambdaScope(E, NewCallOperator,
8987 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008988}
8989
8990template<typename Derived>
8991ExprResult
8992TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008993 CXXMethodDecl *CallOperator,
8994 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008995 bool Invalid = false;
8996
Douglas Gregorb4328232012-02-14 00:00:48 +00008997 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008998 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8999 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009000
Faisal Vali2b391ab2013-09-26 19:54:12 +00009001 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009002 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009003 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009004 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009005 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009006 E->hasExplicitParameters(),
9007 E->hasExplicitResultType(),
9008 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009009
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009010 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009011 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009012 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009013 CEnd = E->capture_end();
9014 C != CEnd; ++C) {
9015 // When we hit the first implicit capture, tell Sema that we've finished
9016 // the list of explicit captures.
9017 if (!FinishedExplicitCaptures && C->isImplicit()) {
9018 getSema().finishLambdaExplicitCaptures(LSI);
9019 FinishedExplicitCaptures = true;
9020 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009021
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009022 // Capturing 'this' is trivial.
9023 if (C->capturesThis()) {
9024 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9025 continue;
9026 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009027 // Captured expression will be recaptured during captured variables
9028 // rebuilding.
9029 if (C->capturesVLAType())
9030 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009031
Richard Smithba71c082013-05-16 06:20:58 +00009032 // Rebuild init-captures, including the implied field declaration.
9033 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009034
9035 InitCaptureInfoTy InitExprTypePair =
9036 InitCaptureExprsAndTypes[C - E->capture_begin()];
9037 ExprResult Init = InitExprTypePair.first;
9038 QualType InitQualType = InitExprTypePair.second;
9039 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009040 Invalid = true;
9041 continue;
9042 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009043 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009044 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9045 OldVD->getLocation(), InitExprTypePair.second,
9046 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009047 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009048 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009049 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009050 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009051 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009052 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009053 continue;
9054 }
9055
9056 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9057
Douglas Gregor3e308b12012-02-14 19:27:52 +00009058 // Determine the capture kind for Sema.
9059 Sema::TryCaptureKind Kind
9060 = C->isImplicit()? Sema::TryCapture_Implicit
9061 : C->getCaptureKind() == LCK_ByCopy
9062 ? Sema::TryCapture_ExplicitByVal
9063 : Sema::TryCapture_ExplicitByRef;
9064 SourceLocation EllipsisLoc;
9065 if (C->isPackExpansion()) {
9066 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9067 bool ShouldExpand = false;
9068 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009069 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9071 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009072 Unexpanded,
9073 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009074 NumExpansions)) {
9075 Invalid = true;
9076 continue;
9077 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
Douglas Gregor3e308b12012-02-14 19:27:52 +00009079 if (ShouldExpand) {
9080 // The transform has determined that we should perform an expansion;
9081 // transform and capture each of the arguments.
9082 // expansion of the pattern. Do so.
9083 VarDecl *Pack = C->getCapturedVar();
9084 for (unsigned I = 0; I != *NumExpansions; ++I) {
9085 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9086 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009087 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009088 Pack));
9089 if (!CapturedVar) {
9090 Invalid = true;
9091 continue;
9092 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009093
Douglas Gregor3e308b12012-02-14 19:27:52 +00009094 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009095 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9096 }
Richard Smith9467be42014-06-06 17:33:35 +00009097
9098 // FIXME: Retain a pack expansion if RetainExpansion is true.
9099
Douglas Gregor3e308b12012-02-14 19:27:52 +00009100 continue;
9101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009102
Douglas Gregor3e308b12012-02-14 19:27:52 +00009103 EllipsisLoc = C->getEllipsisLoc();
9104 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009105
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009106 // Transform the captured variable.
9107 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009108 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009109 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009110 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009111 Invalid = true;
9112 continue;
9113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009115 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009116 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009117 }
9118 if (!FinishedExplicitCaptures)
9119 getSema().finishLambdaExplicitCaptures(LSI);
9120
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009121
9122 // Enter a new evaluation context to insulate the lambda from any
9123 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009124 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009125
9126 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009127 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009128 /*IsInstantiation=*/true);
9129 return ExprError();
9130 }
9131
9132 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009133 StmtResult Body = getDerived().TransformStmt(E->getBody());
9134 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009135 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009136 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009137 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009138 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009139
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009140 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009141 /*CurScope=*/nullptr,
9142 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009143}
9144
9145template<typename Derived>
9146ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009147TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009148 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009149 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9150 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009152
Douglas Gregora16548e2009-08-11 05:31:07 +00009153 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009154 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009155 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009156 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009157 &ArgumentChanged))
9158 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009159
Douglas Gregora16548e2009-08-11 05:31:07 +00009160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009161 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009162 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009163 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009164
Douglas Gregora16548e2009-08-11 05:31:07 +00009165 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009166 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009167 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009168 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 E->getRParenLoc());
9170}
Mike Stump11289f42009-09-09 15:08:12 +00009171
Douglas Gregora16548e2009-08-11 05:31:07 +00009172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009173ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009174TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009175 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009176 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009177 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009178 Expr *OldBase;
9179 QualType BaseType;
9180 QualType ObjectType;
9181 if (!E->isImplicitAccess()) {
9182 OldBase = E->getBase();
9183 Base = getDerived().TransformExpr(OldBase);
9184 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009186
John McCall2d74de92009-12-01 22:10:20 +00009187 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009188 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009189 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009190 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009191 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009192 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009193 ObjectTy,
9194 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009195 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009196 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009197
John McCallba7bf592010-08-24 05:47:05 +00009198 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009199 BaseType = ((Expr*) Base.get())->getType();
9200 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009201 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009202 BaseType = getDerived().TransformType(E->getBaseType());
9203 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9204 }
Mike Stump11289f42009-09-09 15:08:12 +00009205
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009206 // Transform the first part of the nested-name-specifier that qualifies
9207 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009208 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009209 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009210 E->getFirstQualifierFoundInScope(),
9211 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009212
Douglas Gregore16af532011-02-28 18:50:33 +00009213 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009214 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009215 QualifierLoc
9216 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9217 ObjectType,
9218 FirstQualifierInScope);
9219 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009220 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009221 }
Mike Stump11289f42009-09-09 15:08:12 +00009222
Abramo Bagnara7945c982012-01-27 09:46:47 +00009223 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9224
John McCall31f82722010-11-12 08:19:04 +00009225 // TODO: If this is a conversion-function-id, verify that the
9226 // destination type name (if present) resolves the same way after
9227 // instantiation as it did in the local scope.
9228
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009229 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009230 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009231 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009232 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009233
John McCall2d74de92009-12-01 22:10:20 +00009234 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009235 // This is a reference to a member without an explicitly-specified
9236 // template argument list. Optimize for this common case.
9237 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009238 Base.get() == OldBase &&
9239 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009240 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009241 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009242 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009243 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009244
John McCallb268a282010-08-23 23:25:46 +00009245 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009246 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009247 E->isArrow(),
9248 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009249 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009250 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009251 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009252 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009253 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009254 }
9255
John McCall6b51f282009-11-23 01:53:49 +00009256 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009257 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9258 E->getNumTemplateArgs(),
9259 TransArgs))
9260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009261
John McCallb268a282010-08-23 23:25:46 +00009262 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009263 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009264 E->isArrow(),
9265 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009266 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009267 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009268 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009269 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009270 &TransArgs);
9271}
9272
9273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009275TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009276 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009277 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009278 QualType BaseType;
9279 if (!Old->isImplicitAccess()) {
9280 Base = getDerived().TransformExpr(Old->getBase());
9281 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009282 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009283 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009284 Old->isArrow());
9285 if (Base.isInvalid())
9286 return ExprError();
9287 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009288 } else {
9289 BaseType = getDerived().TransformType(Old->getBaseType());
9290 }
John McCall10eae182009-11-30 22:42:35 +00009291
Douglas Gregor0da1d432011-02-28 20:01:57 +00009292 NestedNameSpecifierLoc QualifierLoc;
9293 if (Old->getQualifierLoc()) {
9294 QualifierLoc
9295 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9296 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009297 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009298 }
9299
Abramo Bagnara7945c982012-01-27 09:46:47 +00009300 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9301
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009302 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009303 Sema::LookupOrdinaryName);
9304
9305 // Transform all the decls.
9306 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9307 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009308 NamedDecl *InstD = static_cast<NamedDecl*>(
9309 getDerived().TransformDecl(Old->getMemberLoc(),
9310 *I));
John McCall84d87672009-12-10 09:41:52 +00009311 if (!InstD) {
9312 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9313 // This can happen because of dependent hiding.
9314 if (isa<UsingShadowDecl>(*I))
9315 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009316 else {
9317 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009318 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009319 }
John McCall84d87672009-12-10 09:41:52 +00009320 }
John McCall10eae182009-11-30 22:42:35 +00009321
9322 // Expand using declarations.
9323 if (isa<UsingDecl>(InstD)) {
9324 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009325 for (auto *I : UD->shadows())
9326 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009327 continue;
9328 }
9329
9330 R.addDecl(InstD);
9331 }
9332
9333 R.resolveKind();
9334
Douglas Gregor9262f472010-04-27 18:19:34 +00009335 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009336 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009337 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009338 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009339 Old->getMemberLoc(),
9340 Old->getNamingClass()));
9341 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009342 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009343
Douglas Gregorda7be082010-04-27 16:10:10 +00009344 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009345 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009346
John McCall10eae182009-11-30 22:42:35 +00009347 TemplateArgumentListInfo TransArgs;
9348 if (Old->hasExplicitTemplateArgs()) {
9349 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9350 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009351 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9352 Old->getNumTemplateArgs(),
9353 TransArgs))
9354 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009355 }
John McCall38836f02010-01-15 08:34:02 +00009356
9357 // FIXME: to do this check properly, we will need to preserve the
9358 // first-qualifier-in-scope here, just in case we had a dependent
9359 // base (and therefore couldn't do the check) and a
9360 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009361 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009362
John McCallb268a282010-08-23 23:25:46 +00009363 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009364 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009365 Old->getOperatorLoc(),
9366 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009367 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009368 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009369 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009370 R,
9371 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009372 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009373}
9374
9375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009376ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009377TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009378 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009379 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9380 if (SubExpr.isInvalid())
9381 return ExprError();
9382
9383 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009384 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009385
9386 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9387}
9388
9389template<typename Derived>
9390ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009391TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009392 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9393 if (Pattern.isInvalid())
9394 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009395
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009396 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009397 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009398
Douglas Gregorb8840002011-01-14 21:20:45 +00009399 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9400 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009401}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009402
9403template<typename Derived>
9404ExprResult
9405TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9406 // If E is not value-dependent, then nothing will change when we transform it.
9407 // Note: This is an instantiation-centric view.
9408 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009409 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009410
9411 // Note: None of the implementations of TryExpandParameterPacks can ever
9412 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009413 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009414 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9415 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009416 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009417 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009418 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009419 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009420 ShouldExpand, RetainExpansion,
9421 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009422 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009423
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009424 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009425 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009426
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009427 NamedDecl *Pack = E->getPack();
9428 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009429 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009430 Pack));
9431 if (!Pack)
9432 return ExprError();
9433 }
9434
Chad Rosier1dcde962012-08-08 18:46:20 +00009435
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009436 // We now know the length of the parameter pack, so build a new expression
9437 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009438 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9439 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009440 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009441}
9442
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009443template<typename Derived>
9444ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009445TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9446 SubstNonTypeTemplateParmPackExpr *E) {
9447 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009448 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009449}
9450
9451template<typename Derived>
9452ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009453TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9454 SubstNonTypeTemplateParmExpr *E) {
9455 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009456 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009457}
9458
9459template<typename Derived>
9460ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009461TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9462 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009463 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009464}
9465
9466template<typename Derived>
9467ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009468TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9469 MaterializeTemporaryExpr *E) {
9470 return getDerived().TransformExpr(E->GetTemporaryExpr());
9471}
Chad Rosier1dcde962012-08-08 18:46:20 +00009472
Douglas Gregorfe314812011-06-21 17:03:29 +00009473template<typename Derived>
9474ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009475TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9476 CXXStdInitializerListExpr *E) {
9477 return getDerived().TransformExpr(E->getSubExpr());
9478}
9479
9480template<typename Derived>
9481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009482TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009483 return SemaRef.MaybeBindToTemporary(E);
9484}
9485
9486template<typename Derived>
9487ExprResult
9488TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009489 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009490}
9491
9492template<typename Derived>
9493ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009494TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9495 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9496 if (SubExpr.isInvalid())
9497 return ExprError();
9498
9499 if (!getDerived().AlwaysRebuild() &&
9500 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009501 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009502
9503 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009504}
9505
9506template<typename Derived>
9507ExprResult
9508TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9509 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009510 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009511 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009512 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009513 /*IsCall=*/false, Elements, &ArgChanged))
9514 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009515
Ted Kremeneke65b0862012-03-06 20:05:56 +00009516 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9517 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009518
Ted Kremeneke65b0862012-03-06 20:05:56 +00009519 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9520 Elements.data(),
9521 Elements.size());
9522}
9523
9524template<typename Derived>
9525ExprResult
9526TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009527 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009528 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009529 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009530 bool ArgChanged = false;
9531 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9532 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009533
Ted Kremeneke65b0862012-03-06 20:05:56 +00009534 if (OrigElement.isPackExpansion()) {
9535 // This key/value element is a pack expansion.
9536 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9537 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9538 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9539 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9540
9541 // Determine whether the set of unexpanded parameter packs can
9542 // and should be expanded.
9543 bool Expand = true;
9544 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009545 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9546 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009547 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9548 OrigElement.Value->getLocEnd());
9549 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9550 PatternRange,
9551 Unexpanded,
9552 Expand, RetainExpansion,
9553 NumExpansions))
9554 return ExprError();
9555
9556 if (!Expand) {
9557 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009558 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009559 // expansion.
9560 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9561 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9562 if (Key.isInvalid())
9563 return ExprError();
9564
9565 if (Key.get() != OrigElement.Key)
9566 ArgChanged = true;
9567
9568 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9569 if (Value.isInvalid())
9570 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009571
Ted Kremeneke65b0862012-03-06 20:05:56 +00009572 if (Value.get() != OrigElement.Value)
9573 ArgChanged = true;
9574
Chad Rosier1dcde962012-08-08 18:46:20 +00009575 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009576 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9577 };
9578 Elements.push_back(Expansion);
9579 continue;
9580 }
9581
9582 // Record right away that the argument was changed. This needs
9583 // to happen even if the array expands to nothing.
9584 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009585
Ted Kremeneke65b0862012-03-06 20:05:56 +00009586 // The transform has determined that we should perform an elementwise
9587 // expansion of the pattern. Do so.
9588 for (unsigned I = 0; I != *NumExpansions; ++I) {
9589 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9590 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9591 if (Key.isInvalid())
9592 return ExprError();
9593
9594 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9595 if (Value.isInvalid())
9596 return ExprError();
9597
Chad Rosier1dcde962012-08-08 18:46:20 +00009598 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009599 Key.get(), Value.get(), SourceLocation(), NumExpansions
9600 };
9601
9602 // If any unexpanded parameter packs remain, we still have a
9603 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009604 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009605 if (Key.get()->containsUnexpandedParameterPack() ||
9606 Value.get()->containsUnexpandedParameterPack())
9607 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009608
Ted Kremeneke65b0862012-03-06 20:05:56 +00009609 Elements.push_back(Element);
9610 }
9611
Richard Smith9467be42014-06-06 17:33:35 +00009612 // FIXME: Retain a pack expansion if RetainExpansion is true.
9613
Ted Kremeneke65b0862012-03-06 20:05:56 +00009614 // We've finished with this pack expansion.
9615 continue;
9616 }
9617
9618 // Transform and check key.
9619 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9620 if (Key.isInvalid())
9621 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009622
Ted Kremeneke65b0862012-03-06 20:05:56 +00009623 if (Key.get() != OrigElement.Key)
9624 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009625
Ted Kremeneke65b0862012-03-06 20:05:56 +00009626 // Transform and check value.
9627 ExprResult Value
9628 = getDerived().TransformExpr(OrigElement.Value);
9629 if (Value.isInvalid())
9630 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009631
Ted Kremeneke65b0862012-03-06 20:05:56 +00009632 if (Value.get() != OrigElement.Value)
9633 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009634
9635 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009636 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009637 };
9638 Elements.push_back(Element);
9639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009640
Ted Kremeneke65b0862012-03-06 20:05:56 +00009641 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9642 return SemaRef.MaybeBindToTemporary(E);
9643
9644 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9645 Elements.data(),
9646 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009647}
9648
Mike Stump11289f42009-09-09 15:08:12 +00009649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009651TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009652 TypeSourceInfo *EncodedTypeInfo
9653 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9654 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009656
Douglas Gregora16548e2009-08-11 05:31:07 +00009657 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009658 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009659 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009660
9661 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009662 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009663 E->getRParenLoc());
9664}
Mike Stump11289f42009-09-09 15:08:12 +00009665
Douglas Gregora16548e2009-08-11 05:31:07 +00009666template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009667ExprResult TreeTransform<Derived>::
9668TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009669 // This is a kind of implicit conversion, and it needs to get dropped
9670 // and recomputed for the same general reasons that ImplicitCastExprs
9671 // do, as well a more specific one: this expression is only valid when
9672 // it appears *immediately* as an argument expression.
9673 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009674}
9675
9676template<typename Derived>
9677ExprResult TreeTransform<Derived>::
9678TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009679 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009680 = getDerived().TransformType(E->getTypeInfoAsWritten());
9681 if (!TSInfo)
9682 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009683
John McCall31168b02011-06-15 23:02:42 +00009684 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009685 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009686 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009687
John McCall31168b02011-06-15 23:02:42 +00009688 if (!getDerived().AlwaysRebuild() &&
9689 TSInfo == E->getTypeInfoAsWritten() &&
9690 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009691 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009692
John McCall31168b02011-06-15 23:02:42 +00009693 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009694 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009695 Result.get());
9696}
9697
9698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009700TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009701 // Transform arguments.
9702 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009703 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009704 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009705 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009706 &ArgChanged))
9707 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009708
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009709 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9710 // Class message: transform the receiver type.
9711 TypeSourceInfo *ReceiverTypeInfo
9712 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9713 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009714 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009715
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009716 // If nothing changed, just retain the existing message send.
9717 if (!getDerived().AlwaysRebuild() &&
9718 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009719 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009720
9721 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009722 SmallVector<SourceLocation, 16> SelLocs;
9723 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009724 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9725 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009726 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009727 E->getMethodDecl(),
9728 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009729 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009730 E->getRightLoc());
9731 }
9732
9733 // Instance message: transform the receiver
9734 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9735 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009736 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009737 = getDerived().TransformExpr(E->getInstanceReceiver());
9738 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009739 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009740
9741 // If nothing changed, just retain the existing message send.
9742 if (!getDerived().AlwaysRebuild() &&
9743 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009744 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009745
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009746 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009747 SmallVector<SourceLocation, 16> SelLocs;
9748 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009749 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009750 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009751 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009752 E->getMethodDecl(),
9753 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009754 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009755 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009756}
9757
Mike Stump11289f42009-09-09 15:08:12 +00009758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009760TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009761 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009762}
9763
Mike Stump11289f42009-09-09 15:08:12 +00009764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009765ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009766TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009767 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009768}
9769
Mike Stump11289f42009-09-09 15:08:12 +00009770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009771ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009772TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009773 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009774 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009775 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009776 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009777
9778 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009779
Douglas Gregord51d90d2010-04-26 20:11:03 +00009780 // If nothing changed, just retain the existing expression.
9781 if (!getDerived().AlwaysRebuild() &&
9782 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009783 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009784
John McCallb268a282010-08-23 23:25:46 +00009785 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009786 E->getLocation(),
9787 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009788}
9789
Mike Stump11289f42009-09-09 15:08:12 +00009790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009792TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009793 // 'super' and types never change. Property never changes. Just
9794 // retain the existing expression.
9795 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009796 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009797
Douglas Gregor9faee212010-04-26 20:47:02 +00009798 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009799 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009800 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009801 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009802
Douglas Gregor9faee212010-04-26 20:47:02 +00009803 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009804
Douglas Gregor9faee212010-04-26 20:47:02 +00009805 // If nothing changed, just retain the existing expression.
9806 if (!getDerived().AlwaysRebuild() &&
9807 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009808 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009809
John McCallb7bd14f2010-12-02 01:19:52 +00009810 if (E->isExplicitProperty())
9811 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9812 E->getExplicitProperty(),
9813 E->getLocation());
9814
9815 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009816 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009817 E->getImplicitPropertyGetter(),
9818 E->getImplicitPropertySetter(),
9819 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009820}
9821
Mike Stump11289f42009-09-09 15:08:12 +00009822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009823ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009824TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9825 // Transform the base expression.
9826 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9827 if (Base.isInvalid())
9828 return ExprError();
9829
9830 // Transform the key expression.
9831 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9832 if (Key.isInvalid())
9833 return ExprError();
9834
9835 // If nothing changed, just retain the existing expression.
9836 if (!getDerived().AlwaysRebuild() &&
9837 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009838 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009839
Chad Rosier1dcde962012-08-08 18:46:20 +00009840 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009841 Base.get(), Key.get(),
9842 E->getAtIndexMethodDecl(),
9843 E->setAtIndexMethodDecl());
9844}
9845
9846template<typename Derived>
9847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009848TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009849 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009850 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009851 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009852 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009853
Douglas Gregord51d90d2010-04-26 20:11:03 +00009854 // If nothing changed, just retain the existing expression.
9855 if (!getDerived().AlwaysRebuild() &&
9856 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009857 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009858
John McCallb268a282010-08-23 23:25:46 +00009859 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009860 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009861 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009862}
9863
Mike Stump11289f42009-09-09 15:08:12 +00009864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009866TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009867 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009868 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009869 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009870 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009871 SubExprs, &ArgumentChanged))
9872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009873
Douglas Gregora16548e2009-08-11 05:31:07 +00009874 if (!getDerived().AlwaysRebuild() &&
9875 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009876 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009877
Douglas Gregora16548e2009-08-11 05:31:07 +00009878 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009879 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009880 E->getRParenLoc());
9881}
9882
Mike Stump11289f42009-09-09 15:08:12 +00009883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009884ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009885TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9886 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9887 if (SrcExpr.isInvalid())
9888 return ExprError();
9889
9890 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9891 if (!Type)
9892 return ExprError();
9893
9894 if (!getDerived().AlwaysRebuild() &&
9895 Type == E->getTypeSourceInfo() &&
9896 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009897 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009898
9899 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9900 SrcExpr.get(), Type,
9901 E->getRParenLoc());
9902}
9903
9904template<typename Derived>
9905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009906TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009907 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009908
Craig Topperc3ec1492014-05-26 06:22:03 +00009909 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009910 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9911
9912 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009913 blockScope->TheDecl->setBlockMissingReturnType(
9914 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009915
Chris Lattner01cf8db2011-07-20 06:58:45 +00009916 SmallVector<ParmVarDecl*, 4> params;
9917 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009918
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009919 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009920 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9921 oldBlock->param_begin(),
9922 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009923 nullptr, paramTypes, &params)) {
9924 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009925 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009926 }
John McCall490112f2011-02-04 18:33:18 +00009927
Jordan Rosea0a86be2013-03-08 22:25:36 +00009928 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009929 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009930 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009931
Jordan Rose5c382722013-03-08 21:51:21 +00009932 QualType functionType =
9933 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009934 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009935 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009936
9937 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009938 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009939 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009940
9941 if (!oldBlock->blockMissingReturnType()) {
9942 blockScope->HasImplicitReturnType = false;
9943 blockScope->ReturnType = exprResultType;
9944 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009945
John McCall3882ace2011-01-05 12:14:39 +00009946 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009947 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009948 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009949 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009950 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009951 }
John McCall3882ace2011-01-05 12:14:39 +00009952
John McCall490112f2011-02-04 18:33:18 +00009953#ifndef NDEBUG
9954 // In builds with assertions, make sure that we captured everything we
9955 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009956 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009957 for (const auto &I : oldBlock->captures()) {
9958 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009959
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009960 // Ignore parameter packs.
9961 if (isa<ParmVarDecl>(oldCapture) &&
9962 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9963 continue;
John McCall490112f2011-02-04 18:33:18 +00009964
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009965 VarDecl *newCapture =
9966 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9967 oldCapture));
9968 assert(blockScope->CaptureMap.count(newCapture));
9969 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009970 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009971 }
9972#endif
9973
9974 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009975 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009976}
9977
Mike Stump11289f42009-09-09 15:08:12 +00009978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009979ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009980TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009981 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009982}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009983
9984template<typename Derived>
9985ExprResult
9986TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009987 QualType RetTy = getDerived().TransformType(E->getType());
9988 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009989 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009990 SubExprs.reserve(E->getNumSubExprs());
9991 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9992 SubExprs, &ArgumentChanged))
9993 return ExprError();
9994
9995 if (!getDerived().AlwaysRebuild() &&
9996 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009997 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009998
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009999 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010000 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010001}
Chad Rosier1dcde962012-08-08 18:46:20 +000010002
Douglas Gregora16548e2009-08-11 05:31:07 +000010003//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010004// Type reconstruction
10005//===----------------------------------------------------------------------===//
10006
Mike Stump11289f42009-09-09 15:08:12 +000010007template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010008QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10009 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010010 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010011 getDerived().getBaseEntity());
10012}
10013
Mike Stump11289f42009-09-09 15:08:12 +000010014template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010015QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10016 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010017 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010018 getDerived().getBaseEntity());
10019}
10020
Mike Stump11289f42009-09-09 15:08:12 +000010021template<typename Derived>
10022QualType
John McCall70dd5f62009-10-30 00:06:24 +000010023TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10024 bool WrittenAsLValue,
10025 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010026 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010027 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010028}
10029
10030template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010031QualType
John McCall70dd5f62009-10-30 00:06:24 +000010032TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10033 QualType ClassType,
10034 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010035 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10036 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010037}
10038
10039template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010040QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010041TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10042 ArrayType::ArraySizeModifier SizeMod,
10043 const llvm::APInt *Size,
10044 Expr *SizeExpr,
10045 unsigned IndexTypeQuals,
10046 SourceRange BracketsRange) {
10047 if (SizeExpr || !Size)
10048 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10049 IndexTypeQuals, BracketsRange,
10050 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010051
10052 QualType Types[] = {
10053 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10054 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10055 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010056 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010057 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010058 QualType SizeType;
10059 for (unsigned I = 0; I != NumTypes; ++I)
10060 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10061 SizeType = Types[I];
10062 break;
10063 }
Mike Stump11289f42009-09-09 15:08:12 +000010064
Eli Friedman9562f392012-01-25 23:20:27 +000010065 // Note that we can return a VariableArrayType here in the case where
10066 // the element type was a dependent VariableArrayType.
10067 IntegerLiteral *ArraySize
10068 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10069 /*FIXME*/BracketsRange.getBegin());
10070 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010071 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010072 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010073}
Mike Stump11289f42009-09-09 15:08:12 +000010074
Douglas Gregord6ff3322009-08-04 16:50:30 +000010075template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010076QualType
10077TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010078 ArrayType::ArraySizeModifier SizeMod,
10079 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010080 unsigned IndexTypeQuals,
10081 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010082 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010083 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010084}
10085
10086template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010087QualType
Mike Stump11289f42009-09-09 15:08:12 +000010088TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010089 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010090 unsigned IndexTypeQuals,
10091 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010092 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010093 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010094}
Mike Stump11289f42009-09-09 15:08:12 +000010095
Douglas Gregord6ff3322009-08-04 16:50:30 +000010096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010097QualType
10098TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010099 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010100 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010101 unsigned IndexTypeQuals,
10102 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010103 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010104 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010105 IndexTypeQuals, BracketsRange);
10106}
10107
10108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010109QualType
10110TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010111 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010112 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010113 unsigned IndexTypeQuals,
10114 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010115 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010116 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010117 IndexTypeQuals, BracketsRange);
10118}
10119
10120template<typename Derived>
10121QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010122 unsigned NumElements,
10123 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010124 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010125 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010126}
Mike Stump11289f42009-09-09 15:08:12 +000010127
Douglas Gregord6ff3322009-08-04 16:50:30 +000010128template<typename Derived>
10129QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10130 unsigned NumElements,
10131 SourceLocation AttributeLoc) {
10132 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10133 NumElements, true);
10134 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010135 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10136 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010137 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010138}
Mike Stump11289f42009-09-09 15:08:12 +000010139
Douglas Gregord6ff3322009-08-04 16:50:30 +000010140template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010141QualType
10142TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010143 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010144 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010145 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010146}
Mike Stump11289f42009-09-09 15:08:12 +000010147
Douglas Gregord6ff3322009-08-04 16:50:30 +000010148template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010149QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10150 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010151 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010152 const FunctionProtoType::ExtProtoInfo &EPI) {
10153 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010154 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010155 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010156 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010157}
Mike Stump11289f42009-09-09 15:08:12 +000010158
Douglas Gregord6ff3322009-08-04 16:50:30 +000010159template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010160QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10161 return SemaRef.Context.getFunctionNoProtoType(T);
10162}
10163
10164template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010165QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10166 assert(D && "no decl found");
10167 if (D->isInvalidDecl()) return QualType();
10168
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010169 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010170 TypeDecl *Ty;
10171 if (isa<UsingDecl>(D)) {
10172 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010173 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010174 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10175
10176 // A valid resolved using typename decl points to exactly one type decl.
10177 assert(++Using->shadow_begin() == Using->shadow_end());
10178 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010179
John McCallb96ec562009-12-04 22:46:56 +000010180 } else {
10181 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10182 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10183 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10184 }
10185
10186 return SemaRef.Context.getTypeDeclType(Ty);
10187}
10188
10189template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010190QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10191 SourceLocation Loc) {
10192 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010193}
10194
10195template<typename Derived>
10196QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10197 return SemaRef.Context.getTypeOfType(Underlying);
10198}
10199
10200template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010201QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10202 SourceLocation Loc) {
10203 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010204}
10205
10206template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010207QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10208 UnaryTransformType::UTTKind UKind,
10209 SourceLocation Loc) {
10210 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10211}
10212
10213template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010214QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010215 TemplateName Template,
10216 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010217 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010218 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010219}
Mike Stump11289f42009-09-09 15:08:12 +000010220
Douglas Gregor1135c352009-08-06 05:28:30 +000010221template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010222QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10223 SourceLocation KWLoc) {
10224 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10225}
10226
10227template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010228TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010229TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010230 bool TemplateKW,
10231 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010232 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010233 Template);
10234}
10235
10236template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010237TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010238TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10239 const IdentifierInfo &Name,
10240 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010241 QualType ObjectType,
10242 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010243 UnqualifiedId TemplateName;
10244 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010245 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010246 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010247 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010248 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010249 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010250 /*EnteringContext=*/false,
10251 Template);
John McCall31f82722010-11-12 08:19:04 +000010252 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010253}
Mike Stump11289f42009-09-09 15:08:12 +000010254
Douglas Gregora16548e2009-08-11 05:31:07 +000010255template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010256TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010257TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010258 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010259 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010260 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010261 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010262 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010263 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010264 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010265 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010266 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010267 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010268 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010269 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010270 /*EnteringContext=*/false,
10271 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010272 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010273}
Chad Rosier1dcde962012-08-08 18:46:20 +000010274
Douglas Gregor71395fa2009-11-04 00:56:37 +000010275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010276ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010277TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10278 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010279 Expr *OrigCallee,
10280 Expr *First,
10281 Expr *Second) {
10282 Expr *Callee = OrigCallee->IgnoreParenCasts();
10283 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010284
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010285 if (First->getObjectKind() == OK_ObjCProperty) {
10286 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10287 if (BinaryOperator::isAssignmentOp(Opc))
10288 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10289 First, Second);
10290 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10291 if (Result.isInvalid())
10292 return ExprError();
10293 First = Result.get();
10294 }
10295
10296 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10297 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10298 if (Result.isInvalid())
10299 return ExprError();
10300 Second = Result.get();
10301 }
10302
Douglas Gregora16548e2009-08-11 05:31:07 +000010303 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010304 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010305 if (!First->getType()->isOverloadableType() &&
10306 !Second->getType()->isOverloadableType())
10307 return getSema().CreateBuiltinArraySubscriptExpr(First,
10308 Callee->getLocStart(),
10309 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010310 } else if (Op == OO_Arrow) {
10311 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010312 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10313 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010314 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010315 // The argument is not of overloadable type, so try to create a
10316 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010317 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010318 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010319
John McCallb268a282010-08-23 23:25:46 +000010320 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010321 }
10322 } else {
John McCallb268a282010-08-23 23:25:46 +000010323 if (!First->getType()->isOverloadableType() &&
10324 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010325 // Neither of the arguments is an overloadable type, so try to
10326 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010327 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010328 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010329 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010330 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010332
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010333 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010334 }
10335 }
Mike Stump11289f42009-09-09 15:08:12 +000010336
10337 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010338 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010339 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010340
John McCallb268a282010-08-23 23:25:46 +000010341 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010342 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010343 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010344 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010345 // If we've resolved this to a particular non-member function, just call
10346 // that function. If we resolved it to a member function,
10347 // CreateOverloaded* will find that function for us.
10348 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10349 if (!isa<CXXMethodDecl>(ND))
10350 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010351 }
Mike Stump11289f42009-09-09 15:08:12 +000010352
Douglas Gregora16548e2009-08-11 05:31:07 +000010353 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010354 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010355 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010356
Douglas Gregora16548e2009-08-11 05:31:07 +000010357 // Create the overloaded operator invocation for unary operators.
10358 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010359 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010360 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010361 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010362 }
Mike Stump11289f42009-09-09 15:08:12 +000010363
Douglas Gregore9d62932011-07-15 16:25:15 +000010364 if (Op == OO_Subscript) {
10365 SourceLocation LBrace;
10366 SourceLocation RBrace;
10367
10368 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10369 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10370 LBrace = SourceLocation::getFromRawEncoding(
10371 NameLoc.CXXOperatorName.BeginOpNameLoc);
10372 RBrace = SourceLocation::getFromRawEncoding(
10373 NameLoc.CXXOperatorName.EndOpNameLoc);
10374 } else {
10375 LBrace = Callee->getLocStart();
10376 RBrace = OpLoc;
10377 }
10378
10379 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10380 First, Second);
10381 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010382
Douglas Gregora16548e2009-08-11 05:31:07 +000010383 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010384 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010385 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010386 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10387 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010389
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010390 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010391}
Mike Stump11289f42009-09-09 15:08:12 +000010392
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010393template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010394ExprResult
John McCallb268a282010-08-23 23:25:46 +000010395TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010396 SourceLocation OperatorLoc,
10397 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010398 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010399 TypeSourceInfo *ScopeType,
10400 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010401 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010402 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010403 QualType BaseType = Base->getType();
10404 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010405 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010406 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010407 !BaseType->getAs<PointerType>()->getPointeeType()
10408 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010409 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010410 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010411 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010412 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010413 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010414 /*FIXME?*/true);
10415 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010416
Douglas Gregor678f90d2010-02-25 01:56:36 +000010417 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010418 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10419 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10420 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10421 NameInfo.setNamedTypeInfo(DestroyedType);
10422
Richard Smith8e4a3862012-05-15 06:15:11 +000010423 // The scope type is now known to be a valid nested name specifier
10424 // component. Tack it on to the end of the nested name specifier.
10425 if (ScopeType)
10426 SS.Extend(SemaRef.Context, SourceLocation(),
10427 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010428
Abramo Bagnara7945c982012-01-27 09:46:47 +000010429 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010430 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010431 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010432 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010433 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010434 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010435 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010436}
10437
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010438template<typename Derived>
10439StmtResult
10440TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010441 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010442 CapturedDecl *CD = S->getCapturedDecl();
10443 unsigned NumParams = CD->getNumParams();
10444 unsigned ContextParamPos = CD->getContextParamPosition();
10445 SmallVector<Sema::CapturedParamNameType, 4> Params;
10446 for (unsigned I = 0; I < NumParams; ++I) {
10447 if (I != ContextParamPos) {
10448 Params.push_back(
10449 std::make_pair(
10450 CD->getParam(I)->getName(),
10451 getDerived().TransformType(CD->getParam(I)->getType())));
10452 } else {
10453 Params.push_back(std::make_pair(StringRef(), QualType()));
10454 }
10455 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010456 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010457 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010458 StmtResult Body;
10459 {
10460 Sema::CompoundScopeRAII CompoundScope(getSema());
10461 Body = getDerived().TransformStmt(S->getCapturedStmt());
10462 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010463
10464 if (Body.isInvalid()) {
10465 getSema().ActOnCapturedRegionError();
10466 return StmtError();
10467 }
10468
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010469 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010470}
10471
Douglas Gregord6ff3322009-08-04 16:50:30 +000010472} // end namespace clang
10473
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010474#endif