blob: a0524bd2284200df5a38ac83685a828741e5713d [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,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
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) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004515 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004516}
4517
4518template<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
Richard Smithf623c962012-04-17 00:58:00 +00004568 // FIXME: Need to transform the exception-specification too.
4569
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(),
4574 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004575 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004576 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) {
John McCalldadc5752010-08-24 06:29:42 +00005824 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005826 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005827
Mike Stump11289f42009-09-09 15:08:12 +00005828 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005829 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005830 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregorebe10102009-08-20 07:17:43 +00005833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005835TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005836 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005837 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005838 for (auto *D : S->decls()) {
5839 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005840 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005841 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005842
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005843 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005844 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregorebe10102009-08-20 07:17:43 +00005846 Decls.push_back(Transformed);
5847 }
Mike Stump11289f42009-09-09 15:08:12 +00005848
Douglas Gregorebe10102009-08-20 07:17:43 +00005849 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005850 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005851
Rafael Espindolaab417692013-07-09 12:05:01 +00005852 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005853}
Mike Stump11289f42009-09-09 15:08:12 +00005854
Douglas Gregorebe10102009-08-20 07:17:43 +00005855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005856StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005857TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Benjamin Kramerf0623432012-08-23 22:51:59 +00005859 SmallVector<Expr*, 8> Constraints;
5860 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005861 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005862
John McCalldadc5752010-08-24 06:29:42 +00005863 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005864 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005865
5866 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005867
Anders Carlssonaaeef072010-01-24 05:50:09 +00005868 // Go through the outputs.
5869 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005870 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
Anders Carlssonaaeef072010-01-24 05:50:09 +00005872 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005873 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
Anders Carlssonaaeef072010-01-24 05:50:09 +00005875 // Transform the output expr.
5876 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005877 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005878 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005879 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
Anders Carlssonaaeef072010-01-24 05:50:09 +00005881 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
John McCallb268a282010-08-23 23:25:46 +00005883 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005885
Anders Carlssonaaeef072010-01-24 05:50:09 +00005886 // Go through the inputs.
5887 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005888 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005889
Anders Carlssonaaeef072010-01-24 05:50:09 +00005890 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005891 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Anders Carlssonaaeef072010-01-24 05:50:09 +00005893 // Transform the input expr.
5894 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005895 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005896 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005897 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005898
Anders Carlssonaaeef072010-01-24 05:50:09 +00005899 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005900
John McCallb268a282010-08-23 23:25:46 +00005901 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005903
Anders Carlssonaaeef072010-01-24 05:50:09 +00005904 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005905 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005906
5907 // Go through the clobbers.
5908 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005909 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005910
5911 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005912 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005913 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5914 S->isVolatile(), S->getNumOutputs(),
5915 S->getNumInputs(), Names.data(),
5916 Constraints, Exprs, AsmString.get(),
5917 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005918}
5919
Chad Rosier32503022012-06-11 20:47:18 +00005920template<typename Derived>
5921StmtResult
5922TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005923 ArrayRef<Token> AsmToks =
5924 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005925
John McCallf413f5e2013-05-03 00:10:13 +00005926 bool HadError = false, HadChange = false;
5927
5928 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5929 SmallVector<Expr*, 8> TransformedExprs;
5930 TransformedExprs.reserve(SrcExprs.size());
5931 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5932 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5933 if (!Result.isUsable()) {
5934 HadError = true;
5935 } else {
5936 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005937 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005938 }
5939 }
5940
5941 if (HadError) return StmtError();
5942 if (!HadChange && !getDerived().AlwaysRebuild())
5943 return Owned(S);
5944
Chad Rosierb6f46c12012-08-15 16:53:30 +00005945 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005946 AsmToks, S->getAsmString(),
5947 S->getNumOutputs(), S->getNumInputs(),
5948 S->getAllConstraints(), S->getClobbers(),
5949 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005950}
Douglas Gregorebe10102009-08-20 07:17:43 +00005951
5952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005953StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005954TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005955 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005956 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005957 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregor96c79492010-04-23 22:50:49 +00005960 // Transform the @catch statements (if present).
5961 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005962 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005963 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005964 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005965 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005966 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005967 if (Catch.get() != S->getCatchStmt(I))
5968 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005969 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005971
Douglas Gregor306de2f2010-04-22 23:59:56 +00005972 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005973 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005974 if (S->getFinallyStmt()) {
5975 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5976 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005978 }
5979
5980 // If nothing changed, just retain this statement.
5981 if (!getDerived().AlwaysRebuild() &&
5982 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005983 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005984 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005985 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005986
Douglas Gregor306de2f2010-04-22 23:59:56 +00005987 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005988 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005989 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005990}
Mike Stump11289f42009-09-09 15:08:12 +00005991
Douglas Gregorebe10102009-08-20 07:17:43 +00005992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005993StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005994TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005995 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005996 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005997 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005998 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005999 if (FromVar->getTypeSourceInfo()) {
6000 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6001 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006004
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006005 QualType T;
6006 if (TSInfo)
6007 T = TSInfo->getType();
6008 else {
6009 T = getDerived().TransformType(FromVar->getType());
6010 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006011 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006014 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6015 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006017 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006018
John McCalldadc5752010-08-24 06:29:42 +00006019 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006020 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006021 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006022
6023 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006024 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006025 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006026}
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregorebe10102009-08-20 07:17:43 +00006028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006030TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006031 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006032 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006033 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006035
Douglas Gregor306de2f2010-04-22 23:59:56 +00006036 // If nothing changed, just retain this statement.
6037 if (!getDerived().AlwaysRebuild() &&
6038 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006039 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006040
6041 // Build a new statement.
6042 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006043 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006044}
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregorebe10102009-08-20 07:17:43 +00006046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006047StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006048TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006049 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006050 if (S->getThrowExpr()) {
6051 Operand = getDerived().TransformExpr(S->getThrowExpr());
6052 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006053 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006055
Douglas Gregor2900c162010-04-22 21:44:01 +00006056 if (!getDerived().AlwaysRebuild() &&
6057 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006058 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006059
John McCallb268a282010-08-23 23:25:46 +00006060 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006061}
Mike Stump11289f42009-09-09 15:08:12 +00006062
Douglas Gregorebe10102009-08-20 07:17:43 +00006063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006064StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006065TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006066 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006067 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006068 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006069 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006071 Object =
6072 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6073 Object.get());
6074 if (Object.isInvalid())
6075 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006076
Douglas Gregor6148de72010-04-22 22:01:21 +00006077 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006078 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006079 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006080 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006081
Douglas Gregor6148de72010-04-22 22:01:21 +00006082 // If nothing change, just retain the current statement.
6083 if (!getDerived().AlwaysRebuild() &&
6084 Object.get() == S->getSynchExpr() &&
6085 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006086 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006087
6088 // Build a new statement.
6089 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006090 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006091}
6092
6093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006094StmtResult
John McCall31168b02011-06-15 23:02:42 +00006095TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6096 ObjCAutoreleasePoolStmt *S) {
6097 // Transform the body.
6098 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6099 if (Body.isInvalid())
6100 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006101
John McCall31168b02011-06-15 23:02:42 +00006102 // If nothing changed, just retain this statement.
6103 if (!getDerived().AlwaysRebuild() &&
6104 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006105 return S;
John McCall31168b02011-06-15 23:02:42 +00006106
6107 // Build a new statement.
6108 return getDerived().RebuildObjCAutoreleasePoolStmt(
6109 S->getAtLoc(), Body.get());
6110}
6111
6112template<typename Derived>
6113StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006114TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006115 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006116 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006117 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006118 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006120
Douglas Gregorf68a5082010-04-22 23:10:45 +00006121 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006122 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006123 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006125
Douglas Gregorf68a5082010-04-22 23:10:45 +00006126 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006127 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006128 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006130
Douglas Gregorf68a5082010-04-22 23:10:45 +00006131 // If nothing changed, just retain this statement.
6132 if (!getDerived().AlwaysRebuild() &&
6133 Element.get() == S->getElement() &&
6134 Collection.get() == S->getCollection() &&
6135 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006136 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006137
Douglas Gregorf68a5082010-04-22 23:10:45 +00006138 // Build a new statement.
6139 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006140 Element.get(),
6141 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006142 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006143 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006144}
6145
David Majnemer5f7efef2013-10-15 09:50:08 +00006146template <typename Derived>
6147StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006148 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006149 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006150 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6151 TypeSourceInfo *T =
6152 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006153 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006155
David Majnemer5f7efef2013-10-15 09:50:08 +00006156 Var = getDerived().RebuildExceptionDecl(
6157 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6158 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006159 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006160 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 }
Mike Stump11289f42009-09-09 15:08:12 +00006162
Douglas Gregorebe10102009-08-20 07:17:43 +00006163 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006164 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006165 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006166 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006167
David Majnemer5f7efef2013-10-15 09:50:08 +00006168 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006169 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006170 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006171
David Majnemer5f7efef2013-10-15 09:50:08 +00006172 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006173}
Mike Stump11289f42009-09-09 15:08:12 +00006174
David Majnemer5f7efef2013-10-15 09:50:08 +00006175template <typename Derived>
6176StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006177 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006178 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregorebe10102009-08-20 07:17:43 +00006182 // Transform the handlers.
6183 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006184 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006186 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006189
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006191 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006192 }
Mike Stump11289f42009-09-09 15:08:12 +00006193
David Majnemer5f7efef2013-10-15 09:50:08 +00006194 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006195 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006196 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006197
John McCallb268a282010-08-23 23:25:46 +00006198 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006199 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
Richard Smith02e85f32011-04-14 22:09:26 +00006202template<typename Derived>
6203StmtResult
6204TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6205 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6206 if (Range.isInvalid())
6207 return StmtError();
6208
6209 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6210 if (BeginEnd.isInvalid())
6211 return StmtError();
6212
6213 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6214 if (Cond.isInvalid())
6215 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006216 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006217 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006218 if (Cond.isInvalid())
6219 return StmtError();
6220 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006221 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006222
6223 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6224 if (Inc.isInvalid())
6225 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006226 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006227 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006228
6229 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6230 if (LoopVar.isInvalid())
6231 return StmtError();
6232
6233 StmtResult NewStmt = S;
6234 if (getDerived().AlwaysRebuild() ||
6235 Range.get() != S->getRangeStmt() ||
6236 BeginEnd.get() != S->getBeginEndStmt() ||
6237 Cond.get() != S->getCond() ||
6238 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006239 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006240 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6241 S->getColonLoc(), Range.get(),
6242 BeginEnd.get(), Cond.get(),
6243 Inc.get(), LoopVar.get(),
6244 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006245 if (NewStmt.isInvalid())
6246 return StmtError();
6247 }
Richard Smith02e85f32011-04-14 22:09:26 +00006248
6249 StmtResult Body = getDerived().TransformStmt(S->getBody());
6250 if (Body.isInvalid())
6251 return StmtError();
6252
6253 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6254 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006255 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006256 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6257 S->getColonLoc(), Range.get(),
6258 BeginEnd.get(), Cond.get(),
6259 Inc.get(), LoopVar.get(),
6260 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006261 if (NewStmt.isInvalid())
6262 return StmtError();
6263 }
Richard Smith02e85f32011-04-14 22:09:26 +00006264
6265 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006266 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006267
6268 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6269}
6270
John Wiegley1c0675e2011-04-28 01:08:34 +00006271template<typename Derived>
6272StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006273TreeTransform<Derived>::TransformMSDependentExistsStmt(
6274 MSDependentExistsStmt *S) {
6275 // Transform the nested-name-specifier, if any.
6276 NestedNameSpecifierLoc QualifierLoc;
6277 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006278 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006279 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6280 if (!QualifierLoc)
6281 return StmtError();
6282 }
6283
6284 // Transform the declaration name.
6285 DeclarationNameInfo NameInfo = S->getNameInfo();
6286 if (NameInfo.getName()) {
6287 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6288 if (!NameInfo.getName())
6289 return StmtError();
6290 }
6291
6292 // Check whether anything changed.
6293 if (!getDerived().AlwaysRebuild() &&
6294 QualifierLoc == S->getQualifierLoc() &&
6295 NameInfo.getName() == S->getNameInfo().getName())
6296 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006297
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006298 // Determine whether this name exists, if we can.
6299 CXXScopeSpec SS;
6300 SS.Adopt(QualifierLoc);
6301 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006302 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006303 case Sema::IER_Exists:
6304 if (S->isIfExists())
6305 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006306
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006307 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6308
6309 case Sema::IER_DoesNotExist:
6310 if (S->isIfNotExists())
6311 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006312
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006313 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006314
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006315 case Sema::IER_Dependent:
6316 Dependent = true;
6317 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006318
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006319 case Sema::IER_Error:
6320 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006323 // We need to continue with the instantiation, so do so now.
6324 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6325 if (SubStmt.isInvalid())
6326 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006328 // If we have resolved the name, just transform to the substatement.
6329 if (!Dependent)
6330 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006331
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006332 // The name is still dependent, so build a dependent expression again.
6333 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6334 S->isIfExists(),
6335 QualifierLoc,
6336 NameInfo,
6337 SubStmt.get());
6338}
6339
6340template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006341ExprResult
6342TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6343 NestedNameSpecifierLoc QualifierLoc;
6344 if (E->getQualifierLoc()) {
6345 QualifierLoc
6346 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6347 if (!QualifierLoc)
6348 return ExprError();
6349 }
6350
6351 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6352 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6353 if (!PD)
6354 return ExprError();
6355
6356 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6357 if (Base.isInvalid())
6358 return ExprError();
6359
6360 return new (SemaRef.getASTContext())
6361 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6362 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6363 QualifierLoc, E->getMemberLoc());
6364}
6365
David Majnemerfad8f482013-10-15 09:33:02 +00006366template <typename Derived>
6367StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006368 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006369 if (TryBlock.isInvalid())
6370 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006371
6372 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006373 if (Handler.isInvalid())
6374 return StmtError();
6375
David Majnemerfad8f482013-10-15 09:33:02 +00006376 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6377 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006378 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006379
Warren Huntf6be4cb2014-07-25 20:52:51 +00006380 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6381 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006382}
6383
David Majnemerfad8f482013-10-15 09:33:02 +00006384template <typename Derived>
6385StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006386 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006387 if (Block.isInvalid())
6388 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006389
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006390 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006391}
6392
David Majnemerfad8f482013-10-15 09:33:02 +00006393template <typename Derived>
6394StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006395 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006396 if (FilterExpr.isInvalid())
6397 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006398
David Majnemer7e755502013-10-15 09:30:14 +00006399 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006400 if (Block.isInvalid())
6401 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006402
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006403 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6404 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006405}
6406
David Majnemerfad8f482013-10-15 09:33:02 +00006407template <typename Derived>
6408StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6409 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006410 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6411 else
6412 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6413}
6414
Nico Weber9b982072014-07-07 00:12:30 +00006415template<typename Derived>
6416StmtResult
6417TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6418 return S;
6419}
6420
Alexander Musman64d33f12014-06-04 07:53:32 +00006421//===----------------------------------------------------------------------===//
6422// OpenMP directive transformation
6423//===----------------------------------------------------------------------===//
6424template <typename Derived>
6425StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6426 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006427
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006428 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006429 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006430 ArrayRef<OMPClause *> Clauses = D->clauses();
6431 TClauses.reserve(Clauses.size());
6432 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6433 I != E; ++I) {
6434 if (*I) {
6435 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006436 if (Clause)
6437 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006438 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006439 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006440 }
6441 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006442 StmtResult AssociatedStmt;
6443 if (D->hasAssociatedStmt()) {
6444 if (!D->getAssociatedStmt()) {
6445 return StmtError();
6446 }
6447 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6448 if (AssociatedStmt.isInvalid()) {
6449 return StmtError();
6450 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006451 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006452 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006453 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006454 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006455
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006456 // Transform directive name for 'omp critical' directive.
6457 DeclarationNameInfo DirName;
6458 if (D->getDirectiveKind() == OMPD_critical) {
6459 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6460 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6461 }
6462
Alexander Musman64d33f12014-06-04 07:53:32 +00006463 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006464 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6465 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006466}
6467
Alexander Musman64d33f12014-06-04 07:53:32 +00006468template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006469StmtResult
6470TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6471 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006472 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6473 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006474 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6475 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6476 return Res;
6477}
6478
Alexander Musman64d33f12014-06-04 07:53:32 +00006479template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006480StmtResult
6481TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6482 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006483 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6484 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6486 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006487 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006488}
6489
Alexey Bataevf29276e2014-06-18 04:14:57 +00006490template <typename Derived>
6491StmtResult
6492TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6493 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006494 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6495 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006496 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6497 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6498 return Res;
6499}
6500
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006501template <typename Derived>
6502StmtResult
6503TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6504 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006505 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6506 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006507 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6508 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6509 return Res;
6510}
6511
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006512template <typename Derived>
6513StmtResult
6514TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6515 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006516 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6517 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6519 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6520 return Res;
6521}
6522
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006523template <typename Derived>
6524StmtResult
6525TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6526 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006527 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6528 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6530 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6531 return Res;
6532}
6533
Alexey Bataev4acb8592014-07-07 13:01:15 +00006534template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006535StmtResult
6536TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6537 DeclarationNameInfo DirName;
6538 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6539 D->getLocStart());
6540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6541 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6542 return Res;
6543}
6544
6545template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006546StmtResult
6547TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6548 getDerived().getSema().StartOpenMPDSABlock(
6549 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6550 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6551 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6552 return Res;
6553}
6554
6555template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006556StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6557 OMPParallelForDirective *D) {
6558 DeclarationNameInfo DirName;
6559 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6560 nullptr, D->getLocStart());
6561 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6562 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6563 return Res;
6564}
6565
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006566template <typename Derived>
6567StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6568 OMPParallelSectionsDirective *D) {
6569 DeclarationNameInfo DirName;
6570 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6571 nullptr, D->getLocStart());
6572 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6573 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6574 return Res;
6575}
6576
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006577template <typename Derived>
6578StmtResult
6579TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6580 DeclarationNameInfo DirName;
6581 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6582 D->getLocStart());
6583 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6584 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6585 return Res;
6586}
6587
Alexey Bataev68446b72014-07-18 07:47:19 +00006588template <typename Derived>
6589StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6590 OMPTaskyieldDirective *D) {
6591 DeclarationNameInfo DirName;
6592 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6593 D->getLocStart());
6594 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6595 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6596 return Res;
6597}
6598
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006599template <typename Derived>
6600StmtResult
6601TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6602 DeclarationNameInfo DirName;
6603 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6604 D->getLocStart());
6605 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6606 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6607 return Res;
6608}
6609
Alexey Bataev2df347a2014-07-18 10:17:07 +00006610template <typename Derived>
6611StmtResult
6612TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6613 DeclarationNameInfo DirName;
6614 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6615 D->getLocStart());
6616 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6617 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6618 return Res;
6619}
6620
Alexey Bataev6125da92014-07-21 11:26:11 +00006621template <typename Derived>
6622StmtResult
6623TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6624 DeclarationNameInfo DirName;
6625 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6626 D->getLocStart());
6627 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6628 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6629 return Res;
6630}
6631
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006632template <typename Derived>
6633StmtResult
6634TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6635 DeclarationNameInfo DirName;
6636 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6637 D->getLocStart());
6638 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6639 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6640 return Res;
6641}
6642
Alexey Bataev0162e452014-07-22 10:10:35 +00006643template <typename Derived>
6644StmtResult
6645TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6646 DeclarationNameInfo DirName;
6647 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6648 D->getLocStart());
6649 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6650 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6651 return Res;
6652}
6653
Alexander Musman64d33f12014-06-04 07:53:32 +00006654//===----------------------------------------------------------------------===//
6655// OpenMP clause transformation
6656//===----------------------------------------------------------------------===//
6657template <typename Derived>
6658OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006659 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6660 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006661 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006662 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006663 C->getLParenLoc(), C->getLocEnd());
6664}
6665
Alexander Musman64d33f12014-06-04 07:53:32 +00006666template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006667OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6668 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6669 if (Cond.isInvalid())
6670 return nullptr;
6671 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6672 C->getLParenLoc(), C->getLocEnd());
6673}
6674
6675template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006676OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006677TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6678 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6679 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006680 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006681 return getDerived().RebuildOMPNumThreadsClause(
6682 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006683}
6684
Alexey Bataev62c87d22014-03-21 04:51:18 +00006685template <typename Derived>
6686OMPClause *
6687TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6688 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6689 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006690 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006691 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006692 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006693}
6694
Alexander Musman8bd31e62014-05-27 15:12:19 +00006695template <typename Derived>
6696OMPClause *
6697TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6698 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6699 if (E.isInvalid())
6700 return 0;
6701 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006702 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006703}
6704
Alexander Musman64d33f12014-06-04 07:53:32 +00006705template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006706OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006707TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006708 return getDerived().RebuildOMPDefaultClause(
6709 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6710 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006711}
6712
Alexander Musman64d33f12014-06-04 07:53:32 +00006713template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006714OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006715TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006716 return getDerived().RebuildOMPProcBindClause(
6717 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6718 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006719}
6720
Alexander Musman64d33f12014-06-04 07:53:32 +00006721template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006722OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006723TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6724 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6725 if (E.isInvalid())
6726 return nullptr;
6727 return getDerived().RebuildOMPScheduleClause(
6728 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6729 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6730}
6731
6732template <typename Derived>
6733OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006734TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6735 // No need to rebuild this clause, no template-dependent parameters.
6736 return C;
6737}
6738
6739template <typename Derived>
6740OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006741TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6742 // No need to rebuild this clause, no template-dependent parameters.
6743 return C;
6744}
6745
6746template <typename Derived>
6747OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006748TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6749 // No need to rebuild this clause, no template-dependent parameters.
6750 return C;
6751}
6752
6753template <typename Derived>
6754OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006755TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6756 // No need to rebuild this clause, no template-dependent parameters.
6757 return C;
6758}
6759
6760template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006761OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6762 // No need to rebuild this clause, no template-dependent parameters.
6763 return C;
6764}
6765
6766template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006767OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6768 // No need to rebuild this clause, no template-dependent parameters.
6769 return C;
6770}
6771
6772template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006773OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006774TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6775 // No need to rebuild this clause, no template-dependent parameters.
6776 return C;
6777}
6778
6779template <typename Derived>
6780OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006781TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6782 // No need to rebuild this clause, no template-dependent parameters.
6783 return C;
6784}
6785
6786template <typename Derived>
6787OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006788TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6789 // No need to rebuild this clause, no template-dependent parameters.
6790 return C;
6791}
6792
6793template <typename Derived>
6794OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006795TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006796 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006797 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006798 for (auto *VE : C->varlists()) {
6799 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006800 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006801 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006802 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006803 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006804 return getDerived().RebuildOMPPrivateClause(
6805 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006806}
6807
Alexander Musman64d33f12014-06-04 07:53:32 +00006808template <typename Derived>
6809OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6810 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006811 llvm::SmallVector<Expr *, 16> Vars;
6812 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006813 for (auto *VE : C->varlists()) {
6814 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006815 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006816 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006817 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006818 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006819 return getDerived().RebuildOMPFirstprivateClause(
6820 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006821}
6822
Alexander Musman64d33f12014-06-04 07:53:32 +00006823template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006824OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006825TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6826 llvm::SmallVector<Expr *, 16> Vars;
6827 Vars.reserve(C->varlist_size());
6828 for (auto *VE : C->varlists()) {
6829 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6830 if (EVar.isInvalid())
6831 return nullptr;
6832 Vars.push_back(EVar.get());
6833 }
6834 return getDerived().RebuildOMPLastprivateClause(
6835 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6836}
6837
6838template <typename Derived>
6839OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006840TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6841 llvm::SmallVector<Expr *, 16> Vars;
6842 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006843 for (auto *VE : C->varlists()) {
6844 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006845 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006846 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006847 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006848 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006849 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6850 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006851}
6852
Alexander Musman64d33f12014-06-04 07:53:32 +00006853template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006854OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006855TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6856 llvm::SmallVector<Expr *, 16> Vars;
6857 Vars.reserve(C->varlist_size());
6858 for (auto *VE : C->varlists()) {
6859 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6860 if (EVar.isInvalid())
6861 return nullptr;
6862 Vars.push_back(EVar.get());
6863 }
6864 CXXScopeSpec ReductionIdScopeSpec;
6865 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6866
6867 DeclarationNameInfo NameInfo = C->getNameInfo();
6868 if (NameInfo.getName()) {
6869 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6870 if (!NameInfo.getName())
6871 return nullptr;
6872 }
6873 return getDerived().RebuildOMPReductionClause(
6874 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6875 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6876}
6877
6878template <typename Derived>
6879OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006880TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6881 llvm::SmallVector<Expr *, 16> Vars;
6882 Vars.reserve(C->varlist_size());
6883 for (auto *VE : C->varlists()) {
6884 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6885 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006886 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006887 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006888 }
6889 ExprResult Step = getDerived().TransformExpr(C->getStep());
6890 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006891 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006892 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6893 C->getLParenLoc(),
6894 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006895}
6896
Alexander Musman64d33f12014-06-04 07:53:32 +00006897template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006898OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006899TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6900 llvm::SmallVector<Expr *, 16> Vars;
6901 Vars.reserve(C->varlist_size());
6902 for (auto *VE : C->varlists()) {
6903 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6904 if (EVar.isInvalid())
6905 return nullptr;
6906 Vars.push_back(EVar.get());
6907 }
6908 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6909 if (Alignment.isInvalid())
6910 return nullptr;
6911 return getDerived().RebuildOMPAlignedClause(
6912 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6913 C->getColonLoc(), C->getLocEnd());
6914}
6915
Alexander Musman64d33f12014-06-04 07:53:32 +00006916template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006917OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006918TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6919 llvm::SmallVector<Expr *, 16> Vars;
6920 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006921 for (auto *VE : C->varlists()) {
6922 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006923 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006924 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006925 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006926 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006927 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6928 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006929}
6930
Alexey Bataevbae9a792014-06-27 10:37:06 +00006931template <typename Derived>
6932OMPClause *
6933TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6934 llvm::SmallVector<Expr *, 16> Vars;
6935 Vars.reserve(C->varlist_size());
6936 for (auto *VE : C->varlists()) {
6937 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6938 if (EVar.isInvalid())
6939 return nullptr;
6940 Vars.push_back(EVar.get());
6941 }
6942 return getDerived().RebuildOMPCopyprivateClause(
6943 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6944}
6945
Alexey Bataev6125da92014-07-21 11:26:11 +00006946template <typename Derived>
6947OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6948 llvm::SmallVector<Expr *, 16> Vars;
6949 Vars.reserve(C->varlist_size());
6950 for (auto *VE : C->varlists()) {
6951 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6952 if (EVar.isInvalid())
6953 return nullptr;
6954 Vars.push_back(EVar.get());
6955 }
6956 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6957 C->getLParenLoc(), C->getLocEnd());
6958}
6959
Douglas Gregorebe10102009-08-20 07:17:43 +00006960//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006961// Expression transformation
6962//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006966 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006967}
Mike Stump11289f42009-09-09 15:08:12 +00006968
6969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006972 NestedNameSpecifierLoc QualifierLoc;
6973 if (E->getQualifierLoc()) {
6974 QualifierLoc
6975 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6976 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006978 }
John McCallce546572009-12-08 09:08:17 +00006979
6980 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006981 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6982 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006983 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006985
John McCall815039a2010-08-17 21:27:17 +00006986 DeclarationNameInfo NameInfo = E->getNameInfo();
6987 if (NameInfo.getName()) {
6988 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6989 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006990 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006991 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006992
6993 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006994 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006995 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006996 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006997 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006998
6999 // Mark it referenced in the new context regardless.
7000 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007001 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007002
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007003 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007004 }
John McCallce546572009-12-08 09:08:17 +00007005
Craig Topperc3ec1492014-05-26 06:22:03 +00007006 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007007 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007008 TemplateArgs = &TransArgs;
7009 TransArgs.setLAngleLoc(E->getLAngleLoc());
7010 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007011 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7012 E->getNumTemplateArgs(),
7013 TransArgs))
7014 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007015 }
7016
Chad Rosier1dcde962012-08-08 18:46:20 +00007017 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007018 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007019}
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007024 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007025}
Mike Stump11289f42009-09-09 15:08:12 +00007026
Douglas Gregora16548e2009-08-11 05:31:07 +00007027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007028ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007029TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007030 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007031}
Mike Stump11289f42009-09-09 15:08:12 +00007032
Douglas Gregora16548e2009-08-11 05:31:07 +00007033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007034ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007035TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007036 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007037}
Mike Stump11289f42009-09-09 15:08:12 +00007038
Douglas Gregora16548e2009-08-11 05:31:07 +00007039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007040ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007041TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007042 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007043}
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregora16548e2009-08-11 05:31:07 +00007045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007047TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007048 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007049}
7050
7051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007052ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007053TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007054 if (FunctionDecl *FD = E->getDirectCallee())
7055 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007056 return SemaRef.MaybeBindToTemporary(E);
7057}
7058
7059template<typename Derived>
7060ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007061TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7062 ExprResult ControllingExpr =
7063 getDerived().TransformExpr(E->getControllingExpr());
7064 if (ControllingExpr.isInvalid())
7065 return ExprError();
7066
Chris Lattner01cf8db2011-07-20 06:58:45 +00007067 SmallVector<Expr *, 4> AssocExprs;
7068 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007069 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7070 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7071 if (TS) {
7072 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7073 if (!AssocType)
7074 return ExprError();
7075 AssocTypes.push_back(AssocType);
7076 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007077 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007078 }
7079
7080 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7081 if (AssocExpr.isInvalid())
7082 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007083 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007084 }
7085
7086 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7087 E->getDefaultLoc(),
7088 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007089 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007090 AssocTypes,
7091 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007092}
7093
7094template<typename Derived>
7095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007097 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007098 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007100
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007102 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007103
John McCallb268a282010-08-23 23:25:46 +00007104 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 E->getRParen());
7106}
7107
Richard Smithdb2630f2012-10-21 03:28:35 +00007108/// \brief The operand of a unary address-of operator has special rules: it's
7109/// allowed to refer to a non-static member of a class even if there's no 'this'
7110/// object available.
7111template<typename Derived>
7112ExprResult
7113TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7114 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007115 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007116 else
7117 return getDerived().TransformExpr(E);
7118}
7119
Mike Stump11289f42009-09-09 15:08:12 +00007120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007121ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007122TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007123 ExprResult SubExpr;
7124 if (E->getOpcode() == UO_AddrOf)
7125 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7126 else
7127 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007130
Douglas Gregora16548e2009-08-11 05:31:07 +00007131 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007132 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007133
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7135 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007136 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007137}
Mike Stump11289f42009-09-09 15:08:12 +00007138
Douglas Gregora16548e2009-08-11 05:31:07 +00007139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007140ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007141TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7142 // Transform the type.
7143 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7144 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007146
Douglas Gregor882211c2010-04-28 22:16:22 +00007147 // Transform all of the components into components similar to what the
7148 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007149 // FIXME: It would be slightly more efficient in the non-dependent case to
7150 // just map FieldDecls, rather than requiring the rebuilder to look for
7151 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007152 // template code that we don't care.
7153 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007154 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007155 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007156 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007157 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7158 const Node &ON = E->getComponent(I);
7159 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007160 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007161 Comp.LocStart = ON.getSourceRange().getBegin();
7162 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007163 switch (ON.getKind()) {
7164 case Node::Array: {
7165 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007166 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007167 if (Index.isInvalid())
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 ExprChanged = ExprChanged || Index.get() != FromIndex;
7171 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007172 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007173 break;
7174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007175
Douglas Gregor882211c2010-04-28 22:16:22 +00007176 case Node::Field:
7177 case Node::Identifier:
7178 Comp.isBrackets = false;
7179 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007180 if (!Comp.U.IdentInfo)
7181 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007182
Douglas Gregor882211c2010-04-28 22:16:22 +00007183 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007184
Douglas Gregord1702062010-04-29 00:18:15 +00007185 case Node::Base:
7186 // Will be recomputed during the rebuild.
7187 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007189
Douglas Gregor882211c2010-04-28 22:16:22 +00007190 Components.push_back(Comp);
7191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007192
Douglas Gregor882211c2010-04-28 22:16:22 +00007193 // If nothing changed, retain the existing expression.
7194 if (!getDerived().AlwaysRebuild() &&
7195 Type == E->getTypeSourceInfo() &&
7196 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007197 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007198
Douglas Gregor882211c2010-04-28 22:16:22 +00007199 // Build a new offsetof expression.
7200 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7201 Components.data(), Components.size(),
7202 E->getRParenLoc());
7203}
7204
7205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007206ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007207TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7208 assert(getDerived().AlreadyTransformed(E->getType()) &&
7209 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007210 return E;
John McCall8d69a212010-11-15 23:31:06 +00007211}
7212
7213template<typename Derived>
7214ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007215TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007216 // Rebuild the syntactic form. The original syntactic form has
7217 // opaque-value expressions in it, so strip those away and rebuild
7218 // the result. This is a really awful way of doing this, but the
7219 // better solution (rebuilding the semantic expressions and
7220 // rebinding OVEs as necessary) doesn't work; we'd need
7221 // TreeTransform to not strip away implicit conversions.
7222 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7223 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007224 if (result.isInvalid()) return ExprError();
7225
7226 // If that gives us a pseudo-object result back, the pseudo-object
7227 // expression must have been an lvalue-to-rvalue conversion which we
7228 // should reapply.
7229 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007230 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007231
7232 return result;
7233}
7234
7235template<typename Derived>
7236ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007237TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7238 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007239 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007240 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007241
John McCallbcd03502009-12-07 02:54:59 +00007242 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007243 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007245
John McCall4c98fd82009-11-04 07:28:41 +00007246 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007247 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007248
Peter Collingbournee190dee2011-03-11 19:24:49 +00007249 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7250 E->getKind(),
7251 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007252 }
Mike Stump11289f42009-09-09 15:08:12 +00007253
Eli Friedmane4f22df2012-02-29 04:03:55 +00007254 // C++0x [expr.sizeof]p1:
7255 // The operand is either an expression, which is an unevaluated operand
7256 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007257 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7258 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007259
Reid Kleckner32506ed2014-06-12 23:03:48 +00007260 // Try to recover if we have something like sizeof(T::X) where X is a type.
7261 // Notably, there must be *exactly* one set of parens if X is a type.
7262 TypeSourceInfo *RecoveryTSI = nullptr;
7263 ExprResult SubExpr;
7264 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7265 if (auto *DRE =
7266 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7267 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7268 PE, DRE, false, &RecoveryTSI);
7269 else
7270 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7271
7272 if (RecoveryTSI) {
7273 return getDerived().RebuildUnaryExprOrTypeTrait(
7274 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7275 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007277
Eli Friedmane4f22df2012-02-29 04:03:55 +00007278 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007279 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007280
Peter Collingbournee190dee2011-03-11 19:24:49 +00007281 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7282 E->getOperatorLoc(),
7283 E->getKind(),
7284 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007285}
Mike Stump11289f42009-09-09 15:08:12 +00007286
Douglas Gregora16548e2009-08-11 05:31:07 +00007287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007289TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007290 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007291 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007293
John McCalldadc5752010-08-24 06:29:42 +00007294 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007295 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007297
7298
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 if (!getDerived().AlwaysRebuild() &&
7300 LHS.get() == E->getLHS() &&
7301 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007302 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007303
John McCallb268a282010-08-23 23:25:46 +00007304 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007305 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007306 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007307 E->getRBracketLoc());
7308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
7310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007313 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007314 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007315 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007316 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007317
7318 // Transform arguments.
7319 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007320 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007321 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007322 &ArgChanged))
7323 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007324
Douglas Gregora16548e2009-08-11 05:31:07 +00007325 if (!getDerived().AlwaysRebuild() &&
7326 Callee.get() == E->getCallee() &&
7327 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007328 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007331 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007332 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007333 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007334 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007335 E->getRParenLoc());
7336}
Mike Stump11289f42009-09-09 15:08:12 +00007337
7338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007340TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007341 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007342 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007343 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007344
Douglas Gregorea972d32011-02-28 21:54:11 +00007345 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007346 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007347 QualifierLoc
7348 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007349
Douglas Gregorea972d32011-02-28 21:54:11 +00007350 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007351 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007352 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007353 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007354
Eli Friedman2cfcef62009-12-04 06:40:45 +00007355 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007356 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7357 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007360
John McCall16df1e52010-03-30 21:47:33 +00007361 NamedDecl *FoundDecl = E->getFoundDecl();
7362 if (FoundDecl == E->getMemberDecl()) {
7363 FoundDecl = Member;
7364 } else {
7365 FoundDecl = cast_or_null<NamedDecl>(
7366 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7367 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007368 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007369 }
7370
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 if (!getDerived().AlwaysRebuild() &&
7372 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007373 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007374 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007375 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007376 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007377
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007378 // Mark it referenced in the new context regardless.
7379 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007380 SemaRef.MarkMemberReferenced(E);
7381
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007382 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007383 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007384
John McCall6b51f282009-11-23 01:53:49 +00007385 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007386 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007387 TransArgs.setLAngleLoc(E->getLAngleLoc());
7388 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007389 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7390 E->getNumTemplateArgs(),
7391 TransArgs))
7392 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007393 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007394
Douglas Gregora16548e2009-08-11 05:31:07 +00007395 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007396 SourceLocation FakeOperatorLoc =
7397 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007398
John McCall38836f02010-01-15 08:34:02 +00007399 // FIXME: to do this check properly, we will need to preserve the
7400 // first-qualifier-in-scope here, just in case we had a dependent
7401 // base (and therefore couldn't do the check) and a
7402 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007403 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007404
John McCallb268a282010-08-23 23:25:46 +00007405 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007406 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007407 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007408 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007409 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007410 Member,
John McCall16df1e52010-03-30 21:47:33 +00007411 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007412 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007413 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007414 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007415}
Mike Stump11289f42009-09-09 15:08:12 +00007416
Douglas Gregora16548e2009-08-11 05:31:07 +00007417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007418ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007419TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007420 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007421 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007423
John McCalldadc5752010-08-24 06:29:42 +00007424 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
7429 LHS.get() == E->getLHS() &&
7430 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007431 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007432
Lang Hames5de91cc2012-10-02 04:45:10 +00007433 Sema::FPContractStateRAII FPContractState(getSema());
7434 getSema().FPFeatures.fp_contract = E->isFPContractable();
7435
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007437 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007438}
7439
Mike Stump11289f42009-09-09 15:08:12 +00007440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007441ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007442TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007443 CompoundAssignOperator *E) {
7444 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007445}
Mike Stump11289f42009-09-09 15:08:12 +00007446
Douglas Gregora16548e2009-08-11 05:31:07 +00007447template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007448ExprResult TreeTransform<Derived>::
7449TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7450 // Just rebuild the common and RHS expressions and see whether we
7451 // get any changes.
7452
7453 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7454 if (commonExpr.isInvalid())
7455 return ExprError();
7456
7457 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7458 if (rhs.isInvalid())
7459 return ExprError();
7460
7461 if (!getDerived().AlwaysRebuild() &&
7462 commonExpr.get() == e->getCommon() &&
7463 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007464 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007465
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007466 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007467 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007468 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007469 e->getColonLoc(),
7470 rhs.get());
7471}
7472
7473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007474ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007475TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007476 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007477 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007479
John McCalldadc5752010-08-24 06:29:42 +00007480 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007481 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007483
John McCalldadc5752010-08-24 06:29:42 +00007484 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007485 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007487
Douglas Gregora16548e2009-08-11 05:31:07 +00007488 if (!getDerived().AlwaysRebuild() &&
7489 Cond.get() == E->getCond() &&
7490 LHS.get() == E->getLHS() &&
7491 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007492 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007493
John McCallb268a282010-08-23 23:25:46 +00007494 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007495 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007496 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007497 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007498 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007499}
Mike Stump11289f42009-09-09 15:08:12 +00007500
7501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007503TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007504 // Implicit casts are eliminated during transformation, since they
7505 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007506 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007507}
Mike Stump11289f42009-09-09 15:08:12 +00007508
Douglas Gregora16548e2009-08-11 05:31:07 +00007509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007511TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007512 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7513 if (!Type)
7514 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007515
John McCalldadc5752010-08-24 06:29:42 +00007516 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007517 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007520
Douglas Gregora16548e2009-08-11 05:31:07 +00007521 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007522 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007523 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007524 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007525
John McCall97513962010-01-15 18:39:57 +00007526 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007527 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007528 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007529 SubExpr.get());
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>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007535 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7536 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7537 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007539
John McCalldadc5752010-08-24 06:29:42 +00007540 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007541 if (Init.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() &&
John McCalle15bbff2010-01-18 19:35:47 +00007545 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007547 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007548
John McCall5d7aa7f2010-01-19 22:33:45 +00007549 // Note: the expression type doesn't necessarily match the
7550 // type-as-written, but that's okay, because it should always be
7551 // derivable from the initializer.
7552
John McCalle15bbff2010-01-18 19:35:47 +00007553 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007554 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007555 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007556}
Mike Stump11289f42009-09-09 15:08:12 +00007557
Douglas Gregora16548e2009-08-11 05:31:07 +00007558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007559ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007560TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007561 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007562 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007564
Douglas Gregora16548e2009-08-11 05:31:07 +00007565 if (!getDerived().AlwaysRebuild() &&
7566 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007567 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007568
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007570 SourceLocation FakeOperatorLoc =
7571 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007572 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007573 E->getAccessorLoc(),
7574 E->getAccessor());
7575}
Mike Stump11289f42009-09-09 15:08:12 +00007576
Douglas Gregora16548e2009-08-11 05:31:07 +00007577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007579TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007581
Benjamin Kramerf0623432012-08-23 22:51:59 +00007582 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007583 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007584 Inits, &InitChanged))
7585 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007588 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007589
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007590 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007591 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007592}
Mike Stump11289f42009-09-09 15:08:12 +00007593
Douglas Gregora16548e2009-08-11 05:31:07 +00007594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007596TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007597 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007598
Douglas Gregorebe10102009-08-20 07:17:43 +00007599 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007600 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007603
Douglas Gregorebe10102009-08-20 07:17:43 +00007604 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007605 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007606 bool ExprChanged = false;
7607 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7608 DEnd = E->designators_end();
7609 D != DEnd; ++D) {
7610 if (D->isFieldDesignator()) {
7611 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7612 D->getDotLoc(),
7613 D->getFieldLoc()));
7614 continue;
7615 }
Mike Stump11289f42009-09-09 15:08:12 +00007616
Douglas Gregora16548e2009-08-11 05:31:07 +00007617 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007618 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007619 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007621
7622 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007623 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007624
Douglas Gregora16548e2009-08-11 05:31:07 +00007625 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007626 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007627 continue;
7628 }
Mike Stump11289f42009-09-09 15:08:12 +00007629
Douglas Gregora16548e2009-08-11 05:31:07 +00007630 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007631 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7633 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007635
John McCalldadc5752010-08-24 06:29:42 +00007636 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007637 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007639
7640 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007641 End.get(),
7642 D->getLBracketLoc(),
7643 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007644
Douglas Gregora16548e2009-08-11 05:31:07 +00007645 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7646 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007647
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007648 ArrayExprs.push_back(Start.get());
7649 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007650 }
Mike Stump11289f42009-09-09 15:08:12 +00007651
Douglas Gregora16548e2009-08-11 05:31:07 +00007652 if (!getDerived().AlwaysRebuild() &&
7653 Init.get() == E->getInit() &&
7654 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007655 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007656
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007657 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007659 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007660}
Mike Stump11289f42009-09-09 15:08:12 +00007661
Douglas Gregora16548e2009-08-11 05:31:07 +00007662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007663ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007664TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007665 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007666 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007667
Douglas Gregor3da3c062009-10-28 00:29:27 +00007668 // FIXME: Will we ever have proper type location here? Will we actually
7669 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007670 QualType T = getDerived().TransformType(E->getType());
7671 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 if (!getDerived().AlwaysRebuild() &&
7675 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007676 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007677
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 return getDerived().RebuildImplicitValueInitExpr(T);
7679}
Mike Stump11289f42009-09-09 15:08:12 +00007680
Douglas Gregora16548e2009-08-11 05:31:07 +00007681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007682ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007683TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007684 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7685 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007687
John McCalldadc5752010-08-24 06:29:42 +00007688 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007691
Douglas Gregora16548e2009-08-11 05:31:07 +00007692 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007693 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007695 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007696
John McCallb268a282010-08-23 23:25:46 +00007697 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007698 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007699}
7700
7701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007703TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007704 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007705 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007706 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7707 &ArgumentChanged))
7708 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007709
Douglas Gregora16548e2009-08-11 05:31:07 +00007710 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007711 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 E->getRParenLoc());
7713}
Mike Stump11289f42009-09-09 15:08:12 +00007714
Douglas Gregora16548e2009-08-11 05:31:07 +00007715/// \brief Transform an address-of-label expression.
7716///
7717/// By default, the transformation of an address-of-label expression always
7718/// rebuilds the expression, so that the label identifier can be resolved to
7719/// the corresponding label statement by semantic analysis.
7720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007722TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007723 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7724 E->getLabel());
7725 if (!LD)
7726 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007729 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007730}
Mike Stump11289f42009-09-09 15:08:12 +00007731
7732template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007734TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007735 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007736 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007738 if (SubStmt.isInvalid()) {
7739 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007740 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007741 }
Mike Stump11289f42009-09-09 15:08:12 +00007742
Douglas Gregora16548e2009-08-11 05:31:07 +00007743 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007744 SubStmt.get() == E->getSubStmt()) {
7745 // Calling this an 'error' is unintuitive, but it does the right thing.
7746 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007747 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007748 }
Mike Stump11289f42009-09-09 15:08:12 +00007749
7750 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007751 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007752 E->getRParenLoc());
7753}
Mike Stump11289f42009-09-09 15:08:12 +00007754
Douglas Gregora16548e2009-08-11 05:31:07 +00007755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007756ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007757TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007758 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007759 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007760 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007761
John McCalldadc5752010-08-24 06:29:42 +00007762 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007763 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007765
John McCalldadc5752010-08-24 06:29:42 +00007766 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007767 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007769
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 if (!getDerived().AlwaysRebuild() &&
7771 Cond.get() == E->getCond() &&
7772 LHS.get() == E->getLHS() &&
7773 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007774 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007775
Douglas Gregora16548e2009-08-11 05:31:07 +00007776 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007777 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007778 E->getRParenLoc());
7779}
Mike Stump11289f42009-09-09 15:08:12 +00007780
Douglas Gregora16548e2009-08-11 05:31:07 +00007781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007782ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007783TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007784 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007785}
7786
7787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007788ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007789TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007790 switch (E->getOperator()) {
7791 case OO_New:
7792 case OO_Delete:
7793 case OO_Array_New:
7794 case OO_Array_Delete:
7795 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007796
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007797 case OO_Call: {
7798 // This is a call to an object's operator().
7799 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7800
7801 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007802 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007803 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007804 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007805
7806 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007807 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7808 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007809
7810 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007811 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007812 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007813 Args))
7814 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007815
John McCallb268a282010-08-23 23:25:46 +00007816 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007817 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007818 E->getLocEnd());
7819 }
7820
7821#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7822 case OO_##Name:
7823#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7824#include "clang/Basic/OperatorKinds.def"
7825 case OO_Subscript:
7826 // Handled below.
7827 break;
7828
7829 case OO_Conditional:
7830 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007831
7832 case OO_None:
7833 case NUM_OVERLOADED_OPERATORS:
7834 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007835 }
7836
John McCalldadc5752010-08-24 06:29:42 +00007837 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007838 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007840
Richard Smithdb2630f2012-10-21 03:28:35 +00007841 ExprResult First;
7842 if (E->getOperator() == OO_Amp)
7843 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7844 else
7845 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007846 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007847 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007848
John McCalldadc5752010-08-24 06:29:42 +00007849 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007850 if (E->getNumArgs() == 2) {
7851 Second = getDerived().TransformExpr(E->getArg(1));
7852 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007853 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 }
Mike Stump11289f42009-09-09 15:08:12 +00007855
Douglas Gregora16548e2009-08-11 05:31:07 +00007856 if (!getDerived().AlwaysRebuild() &&
7857 Callee.get() == E->getCallee() &&
7858 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007859 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007860 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007861
Lang Hames5de91cc2012-10-02 04:45:10 +00007862 Sema::FPContractStateRAII FPContractState(getSema());
7863 getSema().FPFeatures.fp_contract = E->isFPContractable();
7864
Douglas Gregora16548e2009-08-11 05:31:07 +00007865 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7866 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007867 Callee.get(),
7868 First.get(),
7869 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007870}
Mike Stump11289f42009-09-09 15:08:12 +00007871
Douglas Gregora16548e2009-08-11 05:31:07 +00007872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007874TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7875 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007876}
Mike Stump11289f42009-09-09 15:08:12 +00007877
Douglas Gregora16548e2009-08-11 05:31:07 +00007878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007879ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007880TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7881 // Transform the callee.
7882 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7883 if (Callee.isInvalid())
7884 return ExprError();
7885
7886 // Transform exec config.
7887 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7888 if (EC.isInvalid())
7889 return ExprError();
7890
7891 // Transform arguments.
7892 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007893 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007894 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007895 &ArgChanged))
7896 return ExprError();
7897
7898 if (!getDerived().AlwaysRebuild() &&
7899 Callee.get() == E->getCallee() &&
7900 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007901 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007902
7903 // FIXME: Wrong source location information for the '('.
7904 SourceLocation FakeLParenLoc
7905 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7906 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007907 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007908 E->getRParenLoc(), EC.get());
7909}
7910
7911template<typename Derived>
7912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007914 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7915 if (!Type)
7916 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007917
John McCalldadc5752010-08-24 06:29:42 +00007918 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007919 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007922
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007924 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007925 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007926 return E;
Nico Weberc153d242014-07-28 00:02:09 +00007927 return getDerived().RebuildCXXNamedCastExpr(
7928 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
7929 Type, E->getAngleBrackets().getEnd(),
7930 // FIXME. this should be '(' location
7931 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007932}
Mike Stump11289f42009-09-09 15:08:12 +00007933
Douglas Gregora16548e2009-08-11 05:31:07 +00007934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007936TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7937 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007938}
Mike Stump11289f42009-09-09 15:08:12 +00007939
7940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007942TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7943 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007944}
7945
Douglas Gregora16548e2009-08-11 05:31:07 +00007946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007947ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007948TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007949 CXXReinterpretCastExpr *E) {
7950 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007951}
Mike Stump11289f42009-09-09 15:08:12 +00007952
Douglas Gregora16548e2009-08-11 05:31:07 +00007953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007955TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7956 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007957}
Mike Stump11289f42009-09-09 15:08:12 +00007958
Douglas Gregora16548e2009-08-11 05:31:07 +00007959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007960ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007961TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007962 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007963 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7964 if (!Type)
7965 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007966
John McCalldadc5752010-08-24 06:29:42 +00007967 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007968 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007971
Douglas Gregora16548e2009-08-11 05:31:07 +00007972 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007973 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007975 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007977 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007978 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007979 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007980 E->getRParenLoc());
7981}
Mike Stump11289f42009-09-09 15:08:12 +00007982
Douglas Gregora16548e2009-08-11 05:31:07 +00007983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007984ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007985TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007986 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007987 TypeSourceInfo *TInfo
7988 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7989 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007991
Douglas Gregora16548e2009-08-11 05:31:07 +00007992 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007993 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007994 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007995
Douglas Gregor9da64192010-04-26 22:37:10 +00007996 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7997 E->getLocStart(),
7998 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007999 E->getLocEnd());
8000 }
Mike Stump11289f42009-09-09 15:08:12 +00008001
Eli Friedman456f0182012-01-20 01:26:23 +00008002 // We don't know whether the subexpression is potentially evaluated until
8003 // after we perform semantic analysis. We speculatively assume it is
8004 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008006 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8007 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008008
John McCalldadc5752010-08-24 06:29:42 +00008009 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008012
Douglas Gregora16548e2009-08-11 05:31:07 +00008013 if (!getDerived().AlwaysRebuild() &&
8014 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008015 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008016
Douglas Gregor9da64192010-04-26 22:37:10 +00008017 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8018 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008019 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008020 E->getLocEnd());
8021}
8022
8023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008024ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008025TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8026 if (E->isTypeOperand()) {
8027 TypeSourceInfo *TInfo
8028 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8029 if (!TInfo)
8030 return ExprError();
8031
8032 if (!getDerived().AlwaysRebuild() &&
8033 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008034 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008035
Douglas Gregor69735112011-03-06 17:40:41 +00008036 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008037 E->getLocStart(),
8038 TInfo,
8039 E->getLocEnd());
8040 }
8041
Francois Pichet9f4f2072010-09-08 12:20:18 +00008042 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8043
8044 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8045 if (SubExpr.isInvalid())
8046 return ExprError();
8047
8048 if (!getDerived().AlwaysRebuild() &&
8049 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008050 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008051
8052 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8053 E->getLocStart(),
8054 SubExpr.get(),
8055 E->getLocEnd());
8056}
8057
8058template<typename Derived>
8059ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008060TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008061 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008062}
Mike Stump11289f42009-09-09 15:08:12 +00008063
Douglas Gregora16548e2009-08-11 05:31:07 +00008064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008065ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008066TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008067 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008068 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008069}
Mike Stump11289f42009-09-09 15:08:12 +00008070
Douglas Gregora16548e2009-08-11 05:31:07 +00008071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008073TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008074 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008075
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008076 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8077 // Make sure that we capture 'this'.
8078 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008079 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008081
Douglas Gregorb15af892010-01-07 23:12:05 +00008082 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008083}
Mike Stump11289f42009-09-09 15:08:12 +00008084
Douglas Gregora16548e2009-08-11 05:31:07 +00008085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008087TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008088 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008089 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008091
Douglas Gregora16548e2009-08-11 05:31:07 +00008092 if (!getDerived().AlwaysRebuild() &&
8093 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008094 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008095
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008096 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8097 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008098}
Mike Stump11289f42009-09-09 15:08:12 +00008099
Douglas Gregora16548e2009-08-11 05:31:07 +00008100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008102TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008103 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008104 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8105 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008106 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008108
Chandler Carruth794da4c2010-02-08 06:42:49 +00008109 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008110 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008111 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregor033f6752009-12-23 23:03:06 +00008113 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008114}
Mike Stump11289f42009-09-09 15:08:12 +00008115
Douglas Gregora16548e2009-08-11 05:31:07 +00008116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008117ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008118TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8119 FieldDecl *Field
8120 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8121 E->getField()));
8122 if (!Field)
8123 return ExprError();
8124
8125 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008126 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008127
8128 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8129}
8130
8131template<typename Derived>
8132ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008133TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8134 CXXScalarValueInitExpr *E) {
8135 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8136 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008137 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008138
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008140 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008141 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008142
Chad Rosier1dcde962012-08-08 18:46:20 +00008143 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008144 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008145 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008146}
Mike Stump11289f42009-09-09 15:08:12 +00008147
Douglas Gregora16548e2009-08-11 05:31:07 +00008148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008150TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008151 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008152 TypeSourceInfo *AllocTypeInfo
8153 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8154 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008156
Douglas Gregora16548e2009-08-11 05:31:07 +00008157 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008158 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008159 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008161
Douglas Gregora16548e2009-08-11 05:31:07 +00008162 // Transform the placement arguments (if any).
8163 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008164 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008165 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008166 E->getNumPlacementArgs(), true,
8167 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008169
Sebastian Redl6047f072012-02-16 12:22:20 +00008170 // Transform the initializer (if any).
8171 Expr *OldInit = E->getInitializer();
8172 ExprResult NewInit;
8173 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008174 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008175 if (NewInit.isInvalid())
8176 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008177
Sebastian Redl6047f072012-02-16 12:22:20 +00008178 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008179 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008180 if (E->getOperatorNew()) {
8181 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008182 getDerived().TransformDecl(E->getLocStart(),
8183 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008184 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008185 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008186 }
8187
Craig Topperc3ec1492014-05-26 06:22:03 +00008188 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008189 if (E->getOperatorDelete()) {
8190 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008191 getDerived().TransformDecl(E->getLocStart(),
8192 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008193 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008194 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008196
Douglas Gregora16548e2009-08-11 05:31:07 +00008197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008198 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008199 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008200 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008201 OperatorNew == E->getOperatorNew() &&
8202 OperatorDelete == E->getOperatorDelete() &&
8203 !ArgumentChanged) {
8204 // Mark any declarations we need as referenced.
8205 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008206 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008207 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008208 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008209 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008210
Sebastian Redl6047f072012-02-16 12:22:20 +00008211 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008212 QualType ElementType
8213 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8214 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8215 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8216 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008217 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008218 }
8219 }
8220 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008221
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008222 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008223 }
Mike Stump11289f42009-09-09 15:08:12 +00008224
Douglas Gregor0744ef62010-09-07 21:49:58 +00008225 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008226 if (!ArraySize.get()) {
8227 // If no array size was specified, but the new expression was
8228 // instantiated with an array type (e.g., "new T" where T is
8229 // instantiated with "int[4]"), extract the outer bound from the
8230 // array type as our array size. We do this with constant and
8231 // dependently-sized array types.
8232 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8233 if (!ArrayT) {
8234 // Do nothing
8235 } else if (const ConstantArrayType *ConsArrayT
8236 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008237 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8238 SemaRef.Context.getSizeType(),
8239 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008240 AllocType = ConsArrayT->getElementType();
8241 } else if (const DependentSizedArrayType *DepArrayT
8242 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8243 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008244 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008245 AllocType = DepArrayT->getElementType();
8246 }
8247 }
8248 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008249
Douglas Gregora16548e2009-08-11 05:31:07 +00008250 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8251 E->isGlobalNew(),
8252 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008253 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008254 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008255 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008256 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008257 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008258 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008259 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008260 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008261}
Mike Stump11289f42009-09-09 15:08:12 +00008262
Douglas Gregora16548e2009-08-11 05:31:07 +00008263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008264ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008265TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008266 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008267 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008269
Douglas Gregord2d9da02010-02-26 00:38:10 +00008270 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008271 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008272 if (E->getOperatorDelete()) {
8273 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008274 getDerived().TransformDecl(E->getLocStart(),
8275 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008276 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008277 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008279
Douglas Gregora16548e2009-08-11 05:31:07 +00008280 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008281 Operand.get() == E->getArgument() &&
8282 OperatorDelete == E->getOperatorDelete()) {
8283 // Mark any declarations we need as referenced.
8284 // FIXME: instantiation-specific.
8285 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008286 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008287
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008288 if (!E->getArgument()->isTypeDependent()) {
8289 QualType Destroyed = SemaRef.Context.getBaseElementType(
8290 E->getDestroyedType());
8291 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8292 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008293 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008294 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008295 }
8296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008297
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008298 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008299 }
Mike Stump11289f42009-09-09 15:08:12 +00008300
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8302 E->isGlobalDelete(),
8303 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008304 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008305}
Mike Stump11289f42009-09-09 15:08:12 +00008306
Douglas Gregora16548e2009-08-11 05:31:07 +00008307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008308ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008309TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008310 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008311 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008312 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008314
John McCallba7bf592010-08-24 05:47:05 +00008315 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008316 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008317 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008318 E->getOperatorLoc(),
8319 E->isArrow()? tok::arrow : tok::period,
8320 ObjectTypePtr,
8321 MayBePseudoDestructor);
8322 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008323 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008324
John McCallba7bf592010-08-24 05:47:05 +00008325 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008326 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8327 if (QualifierLoc) {
8328 QualifierLoc
8329 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8330 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008331 return ExprError();
8332 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008333 CXXScopeSpec SS;
8334 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008335
Douglas Gregor678f90d2010-02-25 01:56:36 +00008336 PseudoDestructorTypeStorage Destroyed;
8337 if (E->getDestroyedTypeInfo()) {
8338 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008339 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008340 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008341 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008342 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008343 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008344 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008345 // We aren't likely to be able to resolve the identifier down to a type
8346 // now anyway, so just retain the identifier.
8347 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8348 E->getDestroyedTypeLoc());
8349 } else {
8350 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008351 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008352 *E->getDestroyedTypeIdentifier(),
8353 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008354 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008355 SS, ObjectTypePtr,
8356 false);
8357 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008359
Douglas Gregor678f90d2010-02-25 01:56:36 +00008360 Destroyed
8361 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8362 E->getDestroyedTypeLoc());
8363 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008364
Craig Topperc3ec1492014-05-26 06:22:03 +00008365 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008366 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008367 CXXScopeSpec EmptySS;
8368 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008369 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008370 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008371 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008373
John McCallb268a282010-08-23 23:25:46 +00008374 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008375 E->getOperatorLoc(),
8376 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008377 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008378 ScopeTypeInfo,
8379 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008380 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008381 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008382}
Mike Stump11289f42009-09-09 15:08:12 +00008383
Douglas Gregorad8a3362009-09-04 17:36:40 +00008384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008385ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008386TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008387 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008388 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8389 Sema::LookupOrdinaryName);
8390
8391 // Transform all the decls.
8392 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8393 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008394 NamedDecl *InstD = static_cast<NamedDecl*>(
8395 getDerived().TransformDecl(Old->getNameLoc(),
8396 *I));
John McCall84d87672009-12-10 09:41:52 +00008397 if (!InstD) {
8398 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8399 // This can happen because of dependent hiding.
8400 if (isa<UsingShadowDecl>(*I))
8401 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008402 else {
8403 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008404 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008405 }
John McCall84d87672009-12-10 09:41:52 +00008406 }
John McCalle66edc12009-11-24 19:00:30 +00008407
8408 // Expand using declarations.
8409 if (isa<UsingDecl>(InstD)) {
8410 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008411 for (auto *I : UD->shadows())
8412 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008413 continue;
8414 }
8415
8416 R.addDecl(InstD);
8417 }
8418
8419 // Resolve a kind, but don't do any further analysis. If it's
8420 // ambiguous, the callee needs to deal with it.
8421 R.resolveKind();
8422
8423 // Rebuild the nested-name qualifier, if present.
8424 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008425 if (Old->getQualifierLoc()) {
8426 NestedNameSpecifierLoc QualifierLoc
8427 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8428 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008429 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008430
Douglas Gregor0da1d432011-02-28 20:01:57 +00008431 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008432 }
8433
Douglas Gregor9262f472010-04-27 18:19:34 +00008434 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008435 CXXRecordDecl *NamingClass
8436 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8437 Old->getNameLoc(),
8438 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008439 if (!NamingClass) {
8440 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008441 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008442 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008443
Douglas Gregorda7be082010-04-27 16:10:10 +00008444 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008445 }
8446
Abramo Bagnara7945c982012-01-27 09:46:47 +00008447 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8448
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008449 // If we have neither explicit template arguments, nor the template keyword,
8450 // it's a normal declaration name.
8451 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008452 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8453
8454 // If we have template arguments, rebuild them, then rebuild the
8455 // templateid expression.
8456 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008457 if (Old->hasExplicitTemplateArgs() &&
8458 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008459 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008460 TransArgs)) {
8461 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008462 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008463 }
John McCalle66edc12009-11-24 19:00:30 +00008464
Abramo Bagnara7945c982012-01-27 09:46:47 +00008465 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008466 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008467}
Mike Stump11289f42009-09-09 15:08:12 +00008468
Douglas Gregora16548e2009-08-11 05:31:07 +00008469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008470ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008471TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8472 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008473 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008474 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8475 TypeSourceInfo *From = E->getArg(I);
8476 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008477 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008478 TypeLocBuilder TLB;
8479 TLB.reserve(FromTL.getFullDataSize());
8480 QualType To = getDerived().TransformType(TLB, FromTL);
8481 if (To.isNull())
8482 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008483
Douglas Gregor29c42f22012-02-24 07:38:34 +00008484 if (To == From->getType())
8485 Args.push_back(From);
8486 else {
8487 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8488 ArgChanged = true;
8489 }
8490 continue;
8491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008492
Douglas Gregor29c42f22012-02-24 07:38:34 +00008493 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008494
Douglas Gregor29c42f22012-02-24 07:38:34 +00008495 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008496 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008497 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8498 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8499 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008500
Douglas Gregor29c42f22012-02-24 07:38:34 +00008501 // Determine whether the set of unexpanded parameter packs can and should
8502 // be expanded.
8503 bool Expand = true;
8504 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008505 Optional<unsigned> OrigNumExpansions =
8506 ExpansionTL.getTypePtr()->getNumExpansions();
8507 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008508 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8509 PatternTL.getSourceRange(),
8510 Unexpanded,
8511 Expand, RetainExpansion,
8512 NumExpansions))
8513 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008514
Douglas Gregor29c42f22012-02-24 07:38:34 +00008515 if (!Expand) {
8516 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008517 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008518 // expansion.
8519 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008520
Douglas Gregor29c42f22012-02-24 07:38:34 +00008521 TypeLocBuilder TLB;
8522 TLB.reserve(From->getTypeLoc().getFullDataSize());
8523
8524 QualType To = getDerived().TransformType(TLB, PatternTL);
8525 if (To.isNull())
8526 return ExprError();
8527
Chad Rosier1dcde962012-08-08 18:46:20 +00008528 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008529 PatternTL.getSourceRange(),
8530 ExpansionTL.getEllipsisLoc(),
8531 NumExpansions);
8532 if (To.isNull())
8533 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008534
Douglas Gregor29c42f22012-02-24 07:38:34 +00008535 PackExpansionTypeLoc ToExpansionTL
8536 = TLB.push<PackExpansionTypeLoc>(To);
8537 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8538 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8539 continue;
8540 }
8541
8542 // Expand the pack expansion by substituting for each argument in the
8543 // pack(s).
8544 for (unsigned I = 0; I != *NumExpansions; ++I) {
8545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8546 TypeLocBuilder TLB;
8547 TLB.reserve(PatternTL.getFullDataSize());
8548 QualType To = getDerived().TransformType(TLB, PatternTL);
8549 if (To.isNull())
8550 return ExprError();
8551
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008552 if (To->containsUnexpandedParameterPack()) {
8553 To = getDerived().RebuildPackExpansionType(To,
8554 PatternTL.getSourceRange(),
8555 ExpansionTL.getEllipsisLoc(),
8556 NumExpansions);
8557 if (To.isNull())
8558 return ExprError();
8559
8560 PackExpansionTypeLoc ToExpansionTL
8561 = TLB.push<PackExpansionTypeLoc>(To);
8562 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8563 }
8564
Douglas Gregor29c42f22012-02-24 07:38:34 +00008565 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8566 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008567
Douglas Gregor29c42f22012-02-24 07:38:34 +00008568 if (!RetainExpansion)
8569 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008570
Douglas Gregor29c42f22012-02-24 07:38:34 +00008571 // If we're supposed to retain a pack expansion, do so by temporarily
8572 // forgetting the partially-substituted parameter pack.
8573 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8574
8575 TypeLocBuilder TLB;
8576 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008577
Douglas Gregor29c42f22012-02-24 07:38:34 +00008578 QualType To = getDerived().TransformType(TLB, PatternTL);
8579 if (To.isNull())
8580 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008581
8582 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008583 PatternTL.getSourceRange(),
8584 ExpansionTL.getEllipsisLoc(),
8585 NumExpansions);
8586 if (To.isNull())
8587 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008588
Douglas Gregor29c42f22012-02-24 07:38:34 +00008589 PackExpansionTypeLoc ToExpansionTL
8590 = TLB.push<PackExpansionTypeLoc>(To);
8591 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8592 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008594
Douglas Gregor29c42f22012-02-24 07:38:34 +00008595 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008596 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008597
8598 return getDerived().RebuildTypeTrait(E->getTrait(),
8599 E->getLocStart(),
8600 Args,
8601 E->getLocEnd());
8602}
8603
8604template<typename Derived>
8605ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008606TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8607 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8608 if (!T)
8609 return ExprError();
8610
8611 if (!getDerived().AlwaysRebuild() &&
8612 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008613 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008614
8615 ExprResult SubExpr;
8616 {
8617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8618 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8619 if (SubExpr.isInvalid())
8620 return ExprError();
8621
8622 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008623 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008624 }
8625
8626 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8627 E->getLocStart(),
8628 T,
8629 SubExpr.get(),
8630 E->getLocEnd());
8631}
8632
8633template<typename Derived>
8634ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008635TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8636 ExprResult SubExpr;
8637 {
8638 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8639 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8640 if (SubExpr.isInvalid())
8641 return ExprError();
8642
8643 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008644 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008645 }
8646
8647 return getDerived().RebuildExpressionTrait(
8648 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8649}
8650
Reid Kleckner32506ed2014-06-12 23:03:48 +00008651template <typename Derived>
8652ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8653 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8654 TypeSourceInfo **RecoveryTSI) {
8655 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8656 DRE, AddrTaken, RecoveryTSI);
8657
8658 // Propagate both errors and recovered types, which return ExprEmpty.
8659 if (!NewDRE.isUsable())
8660 return NewDRE;
8661
8662 // We got an expr, wrap it up in parens.
8663 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8664 return PE;
8665 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8666 PE->getRParen());
8667}
8668
8669template <typename Derived>
8670ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8671 DependentScopeDeclRefExpr *E) {
8672 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8673 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008674}
8675
8676template<typename Derived>
8677ExprResult
8678TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8679 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008680 bool IsAddressOfOperand,
8681 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008682 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008683 NestedNameSpecifierLoc QualifierLoc
8684 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8685 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008686 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008687 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008688
John McCall31f82722010-11-12 08:19:04 +00008689 // TODO: If this is a conversion-function-id, verify that the
8690 // destination type name (if present) resolves the same way after
8691 // instantiation as it did in the local scope.
8692
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008693 DeclarationNameInfo NameInfo
8694 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8695 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008697
John McCalle66edc12009-11-24 19:00:30 +00008698 if (!E->hasExplicitTemplateArgs()) {
8699 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008700 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008701 // Note: it is sufficient to compare the Name component of NameInfo:
8702 // if name has not changed, DNLoc has not changed either.
8703 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008704 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008705
Reid Kleckner32506ed2014-06-12 23:03:48 +00008706 return getDerived().RebuildDependentScopeDeclRefExpr(
8707 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8708 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008709 }
John McCall6b51f282009-11-23 01:53:49 +00008710
8711 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008712 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8713 E->getNumTemplateArgs(),
8714 TransArgs))
8715 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008716
Reid Kleckner32506ed2014-06-12 23:03:48 +00008717 return getDerived().RebuildDependentScopeDeclRefExpr(
8718 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8719 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008720}
8721
8722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008724TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008725 // CXXConstructExprs other than for list-initialization and
8726 // CXXTemporaryObjectExpr are always implicit, so when we have
8727 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008728 if ((E->getNumArgs() == 1 ||
8729 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008730 (!getDerived().DropCallArgument(E->getArg(0))) &&
8731 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008732 return getDerived().TransformExpr(E->getArg(0));
8733
Douglas Gregora16548e2009-08-11 05:31:07 +00008734 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8735
8736 QualType T = getDerived().TransformType(E->getType());
8737 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008738 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008739
8740 CXXConstructorDecl *Constructor
8741 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008742 getDerived().TransformDecl(E->getLocStart(),
8743 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008744 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008746
Douglas Gregora16548e2009-08-11 05:31:07 +00008747 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008748 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008749 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008750 &ArgumentChanged))
8751 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008752
Douglas Gregora16548e2009-08-11 05:31:07 +00008753 if (!getDerived().AlwaysRebuild() &&
8754 T == E->getType() &&
8755 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008756 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008757 // Mark the constructor as referenced.
8758 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008759 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008760 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008761 }
Mike Stump11289f42009-09-09 15:08:12 +00008762
Douglas Gregordb121ba2009-12-14 16:27:04 +00008763 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8764 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008765 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008766 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008767 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008768 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008769 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008770 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008771 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008772}
Mike Stump11289f42009-09-09 15:08:12 +00008773
Douglas Gregora16548e2009-08-11 05:31:07 +00008774/// \brief Transform a C++ temporary-binding expression.
8775///
Douglas Gregor363b1512009-12-24 18:51:59 +00008776/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8777/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008780TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008781 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008782}
Mike Stump11289f42009-09-09 15:08:12 +00008783
John McCall5d413782010-12-06 08:20:24 +00008784/// \brief Transform a C++ expression that contains cleanups that should
8785/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008786///
John McCall5d413782010-12-06 08:20:24 +00008787/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008788/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008790ExprResult
John McCall5d413782010-12-06 08:20:24 +00008791TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008792 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008793}
Mike Stump11289f42009-09-09 15:08:12 +00008794
Douglas Gregora16548e2009-08-11 05:31:07 +00008795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008796ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008797TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008798 CXXTemporaryObjectExpr *E) {
8799 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8800 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008801 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008802
Douglas Gregora16548e2009-08-11 05:31:07 +00008803 CXXConstructorDecl *Constructor
8804 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008805 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008806 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008807 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008809
Douglas Gregora16548e2009-08-11 05:31:07 +00008810 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008811 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008812 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008813 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008814 &ArgumentChanged))
8815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008816
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008818 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008819 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008820 !ArgumentChanged) {
8821 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008822 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008823 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008825
Richard Smithd59b8322012-12-19 01:39:02 +00008826 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008827 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8828 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008829 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008830 E->getLocEnd());
8831}
Mike Stump11289f42009-09-09 15:08:12 +00008832
Douglas Gregora16548e2009-08-11 05:31:07 +00008833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008834ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008835TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008836
8837 // Transform any init-capture expressions before entering the scope of the
8838 // lambda body, because they are not semantically within that scope.
8839 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8840 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8841 E->explicit_capture_begin());
8842
8843 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8844 CEnd = E->capture_end();
8845 C != CEnd; ++C) {
8846 if (!C->isInitCapture())
8847 continue;
8848 EnterExpressionEvaluationContext EEEC(getSema(),
8849 Sema::PotentiallyEvaluated);
8850 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8851 C->getCapturedVar()->getInit(),
8852 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8853
8854 if (NewExprInitResult.isInvalid())
8855 return ExprError();
8856 Expr *NewExprInit = NewExprInitResult.get();
8857
8858 VarDecl *OldVD = C->getCapturedVar();
8859 QualType NewInitCaptureType =
8860 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8861 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8862 NewExprInit);
8863 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008864 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8865 std::make_pair(NewExprInitResult, NewInitCaptureType);
8866
8867 }
8868
Faisal Vali524ca282013-11-12 01:40:44 +00008869 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008870 // Transform the template parameters, and add them to the current
8871 // instantiation scope. The null case is handled correctly.
8872 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8873 E->getTemplateParameterList());
8874
8875 // Check to see if the TypeSourceInfo of the call operator needs to
8876 // be transformed, and if so do the transformation in the
8877 // CurrentInstantiationScope.
8878
8879 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8880 FunctionProtoTypeLoc OldCallOpFPTL =
8881 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008882 TypeSourceInfo *NewCallOpTSI = nullptr;
8883
Faisal Vali2cba1332013-10-23 06:44:28 +00008884 const bool CallOpWasAlreadyTransformed =
8885 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8886
8887 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8888 if (CallOpWasAlreadyTransformed)
8889 NewCallOpTSI = OldCallOpTSI;
8890 else {
8891 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8892 // The transformation MUST be done in the CurrentInstantiationScope since
8893 // it introduces a mapping of the original to the newly created
8894 // transformed parameters.
8895
8896 TypeLocBuilder NewCallOpTLBuilder;
8897 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8898 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008899 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008900 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8901 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008902 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008903 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8904 // the vector below - this will be used to synthesize the
8905 // NewCallOperator. Additionally, add the parameters of the untransformed
8906 // lambda call operator to the CurrentInstantiationScope.
8907 SmallVector<ParmVarDecl *, 4> Params;
8908 {
8909 FunctionProtoTypeLoc NewCallOpFPTL =
8910 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8911 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008912 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008913
8914 for (unsigned I = 0; I < NewNumArgs; ++I) {
8915 // If this call operator's type does not require transformation,
8916 // the parameters do not get added to the current instantiation scope,
8917 // - so ADD them! This allows the following to compile when the enclosing
8918 // template is specialized and the entire lambda expression has to be
8919 // transformed.
8920 // template<class T> void foo(T t) {
8921 // auto L = [](auto a) {
8922 // auto M = [](char b) { <-- note: non-generic lambda
8923 // auto N = [](auto c) {
8924 // int x = sizeof(a);
8925 // x = sizeof(b); <-- specifically this line
8926 // x = sizeof(c);
8927 // };
8928 // };
8929 // };
8930 // }
8931 // foo('a')
8932 if (CallOpWasAlreadyTransformed)
8933 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8934 NewParamDeclArray[I]);
8935 // Add to Params array, so these parameters can be used to create
8936 // the newly transformed call operator.
8937 Params.push_back(NewParamDeclArray[I]);
8938 }
8939 }
8940
8941 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008942 return ExprError();
8943
Eli Friedmand564afb2012-09-19 01:18:11 +00008944 // Create the local class that will describe the lambda.
8945 CXXRecordDecl *Class
8946 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008947 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008948 /*KnownDependent=*/false,
8949 E->getCaptureDefault());
8950
Eli Friedmand564afb2012-09-19 01:18:11 +00008951 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8952
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008953 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008954 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008955 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008956 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008957 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008958 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008959 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008960
Faisal Vali2cba1332013-10-23 06:44:28 +00008961 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8962
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008963 return getDerived().TransformLambdaScope(E, NewCallOperator,
8964 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008965}
8966
8967template<typename Derived>
8968ExprResult
8969TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008970 CXXMethodDecl *CallOperator,
8971 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008972 bool Invalid = false;
8973
Douglas Gregorb4328232012-02-14 00:00:48 +00008974 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008975 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8976 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008977
Faisal Vali2b391ab2013-09-26 19:54:12 +00008978 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008979 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008980 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008981 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008982 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008983 E->hasExplicitParameters(),
8984 E->hasExplicitResultType(),
8985 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008986
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008987 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008988 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008989 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008990 CEnd = E->capture_end();
8991 C != CEnd; ++C) {
8992 // When we hit the first implicit capture, tell Sema that we've finished
8993 // the list of explicit captures.
8994 if (!FinishedExplicitCaptures && C->isImplicit()) {
8995 getSema().finishLambdaExplicitCaptures(LSI);
8996 FinishedExplicitCaptures = true;
8997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008998
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008999 // Capturing 'this' is trivial.
9000 if (C->capturesThis()) {
9001 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9002 continue;
9003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009004
Richard Smithba71c082013-05-16 06:20:58 +00009005 // Rebuild init-captures, including the implied field declaration.
9006 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009007
9008 InitCaptureInfoTy InitExprTypePair =
9009 InitCaptureExprsAndTypes[C - E->capture_begin()];
9010 ExprResult Init = InitExprTypePair.first;
9011 QualType InitQualType = InitExprTypePair.second;
9012 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009013 Invalid = true;
9014 continue;
9015 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009016 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009017 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9018 OldVD->getLocation(), InitExprTypePair.second,
9019 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009020 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009021 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009022 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009023 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009024 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009025 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009026 continue;
9027 }
9028
9029 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9030
Douglas Gregor3e308b12012-02-14 19:27:52 +00009031 // Determine the capture kind for Sema.
9032 Sema::TryCaptureKind Kind
9033 = C->isImplicit()? Sema::TryCapture_Implicit
9034 : C->getCaptureKind() == LCK_ByCopy
9035 ? Sema::TryCapture_ExplicitByVal
9036 : Sema::TryCapture_ExplicitByRef;
9037 SourceLocation EllipsisLoc;
9038 if (C->isPackExpansion()) {
9039 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9040 bool ShouldExpand = false;
9041 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009042 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009043 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9044 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009045 Unexpanded,
9046 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009047 NumExpansions)) {
9048 Invalid = true;
9049 continue;
9050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009051
Douglas Gregor3e308b12012-02-14 19:27:52 +00009052 if (ShouldExpand) {
9053 // The transform has determined that we should perform an expansion;
9054 // transform and capture each of the arguments.
9055 // expansion of the pattern. Do so.
9056 VarDecl *Pack = C->getCapturedVar();
9057 for (unsigned I = 0; I != *NumExpansions; ++I) {
9058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9059 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009060 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009061 Pack));
9062 if (!CapturedVar) {
9063 Invalid = true;
9064 continue;
9065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009066
Douglas Gregor3e308b12012-02-14 19:27:52 +00009067 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009068 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9069 }
Richard Smith9467be42014-06-06 17:33:35 +00009070
9071 // FIXME: Retain a pack expansion if RetainExpansion is true.
9072
Douglas Gregor3e308b12012-02-14 19:27:52 +00009073 continue;
9074 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009075
Douglas Gregor3e308b12012-02-14 19:27:52 +00009076 EllipsisLoc = C->getEllipsisLoc();
9077 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009079 // Transform the captured variable.
9080 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009081 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009082 C->getCapturedVar()));
9083 if (!CapturedVar) {
9084 Invalid = true;
9085 continue;
9086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009087
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009088 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009089 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009090 }
9091 if (!FinishedExplicitCaptures)
9092 getSema().finishLambdaExplicitCaptures(LSI);
9093
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009094
9095 // Enter a new evaluation context to insulate the lambda from any
9096 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009097 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009098
9099 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009100 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009101 /*IsInstantiation=*/true);
9102 return ExprError();
9103 }
9104
9105 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009106 StmtResult Body = getDerived().TransformStmt(E->getBody());
9107 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009108 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009109 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009110 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009111 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009112
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009113 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009114 /*CurScope=*/nullptr,
9115 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009116}
9117
9118template<typename Derived>
9119ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009120TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009121 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009122 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9123 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009125
Douglas Gregora16548e2009-08-11 05:31:07 +00009126 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009127 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009128 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009129 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009130 &ArgumentChanged))
9131 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009132
Douglas Gregora16548e2009-08-11 05:31:07 +00009133 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009134 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009135 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009136 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009137
Douglas Gregora16548e2009-08-11 05:31:07 +00009138 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009139 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009140 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009141 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009142 E->getRParenLoc());
9143}
Mike Stump11289f42009-09-09 15:08:12 +00009144
Douglas Gregora16548e2009-08-11 05:31:07 +00009145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009146ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009147TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009148 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009149 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009150 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009151 Expr *OldBase;
9152 QualType BaseType;
9153 QualType ObjectType;
9154 if (!E->isImplicitAccess()) {
9155 OldBase = E->getBase();
9156 Base = getDerived().TransformExpr(OldBase);
9157 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009159
John McCall2d74de92009-12-01 22:10:20 +00009160 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009161 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009162 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009163 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009164 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009165 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009166 ObjectTy,
9167 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009168 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009169 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009170
John McCallba7bf592010-08-24 05:47:05 +00009171 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009172 BaseType = ((Expr*) Base.get())->getType();
9173 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009174 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009175 BaseType = getDerived().TransformType(E->getBaseType());
9176 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9177 }
Mike Stump11289f42009-09-09 15:08:12 +00009178
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009179 // Transform the first part of the nested-name-specifier that qualifies
9180 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009181 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009182 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009183 E->getFirstQualifierFoundInScope(),
9184 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009185
Douglas Gregore16af532011-02-28 18:50:33 +00009186 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009187 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009188 QualifierLoc
9189 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9190 ObjectType,
9191 FirstQualifierInScope);
9192 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009193 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009194 }
Mike Stump11289f42009-09-09 15:08:12 +00009195
Abramo Bagnara7945c982012-01-27 09:46:47 +00009196 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9197
John McCall31f82722010-11-12 08:19:04 +00009198 // TODO: If this is a conversion-function-id, verify that the
9199 // destination type name (if present) resolves the same way after
9200 // instantiation as it did in the local scope.
9201
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009202 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009203 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009204 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009206
John McCall2d74de92009-12-01 22:10:20 +00009207 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009208 // This is a reference to a member without an explicitly-specified
9209 // template argument list. Optimize for this common case.
9210 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009211 Base.get() == OldBase &&
9212 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009213 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009214 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009215 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009216 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009217
John McCallb268a282010-08-23 23:25:46 +00009218 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009219 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009220 E->isArrow(),
9221 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009222 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009223 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009224 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009225 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009226 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009227 }
9228
John McCall6b51f282009-11-23 01:53:49 +00009229 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009230 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9231 E->getNumTemplateArgs(),
9232 TransArgs))
9233 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009234
John McCallb268a282010-08-23 23:25:46 +00009235 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009236 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009237 E->isArrow(),
9238 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009239 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009240 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009241 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009242 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009243 &TransArgs);
9244}
9245
9246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009248TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009249 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009250 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009251 QualType BaseType;
9252 if (!Old->isImplicitAccess()) {
9253 Base = getDerived().TransformExpr(Old->getBase());
9254 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009255 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009256 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009257 Old->isArrow());
9258 if (Base.isInvalid())
9259 return ExprError();
9260 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009261 } else {
9262 BaseType = getDerived().TransformType(Old->getBaseType());
9263 }
John McCall10eae182009-11-30 22:42:35 +00009264
Douglas Gregor0da1d432011-02-28 20:01:57 +00009265 NestedNameSpecifierLoc QualifierLoc;
9266 if (Old->getQualifierLoc()) {
9267 QualifierLoc
9268 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9269 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009270 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009271 }
9272
Abramo Bagnara7945c982012-01-27 09:46:47 +00009273 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9274
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009275 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009276 Sema::LookupOrdinaryName);
9277
9278 // Transform all the decls.
9279 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9280 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009281 NamedDecl *InstD = static_cast<NamedDecl*>(
9282 getDerived().TransformDecl(Old->getMemberLoc(),
9283 *I));
John McCall84d87672009-12-10 09:41:52 +00009284 if (!InstD) {
9285 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9286 // This can happen because of dependent hiding.
9287 if (isa<UsingShadowDecl>(*I))
9288 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009289 else {
9290 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009291 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009292 }
John McCall84d87672009-12-10 09:41:52 +00009293 }
John McCall10eae182009-11-30 22:42:35 +00009294
9295 // Expand using declarations.
9296 if (isa<UsingDecl>(InstD)) {
9297 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009298 for (auto *I : UD->shadows())
9299 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009300 continue;
9301 }
9302
9303 R.addDecl(InstD);
9304 }
9305
9306 R.resolveKind();
9307
Douglas Gregor9262f472010-04-27 18:19:34 +00009308 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009309 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009310 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009311 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009312 Old->getMemberLoc(),
9313 Old->getNamingClass()));
9314 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
Douglas Gregorda7be082010-04-27 16:10:10 +00009317 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009318 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009319
John McCall10eae182009-11-30 22:42:35 +00009320 TemplateArgumentListInfo TransArgs;
9321 if (Old->hasExplicitTemplateArgs()) {
9322 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9323 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009324 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9325 Old->getNumTemplateArgs(),
9326 TransArgs))
9327 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009328 }
John McCall38836f02010-01-15 08:34:02 +00009329
9330 // FIXME: to do this check properly, we will need to preserve the
9331 // first-qualifier-in-scope here, just in case we had a dependent
9332 // base (and therefore couldn't do the check) and a
9333 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009334 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009335
John McCallb268a282010-08-23 23:25:46 +00009336 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009337 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009338 Old->getOperatorLoc(),
9339 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009340 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009341 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009342 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009343 R,
9344 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009345 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009346}
9347
9348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009349ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009350TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009351 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009352 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9353 if (SubExpr.isInvalid())
9354 return ExprError();
9355
9356 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009357 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009358
9359 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9360}
9361
9362template<typename Derived>
9363ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009364TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009365 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9366 if (Pattern.isInvalid())
9367 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009368
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009369 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009370 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009371
Douglas Gregorb8840002011-01-14 21:20:45 +00009372 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9373 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009374}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009375
9376template<typename Derived>
9377ExprResult
9378TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9379 // If E is not value-dependent, then nothing will change when we transform it.
9380 // Note: This is an instantiation-centric view.
9381 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009382 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009383
9384 // Note: None of the implementations of TryExpandParameterPacks can ever
9385 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009386 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009387 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9388 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009389 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009390 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009391 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009392 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009393 ShouldExpand, RetainExpansion,
9394 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009395 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009396
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009397 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009398 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009399
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009400 NamedDecl *Pack = E->getPack();
9401 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009402 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009403 Pack));
9404 if (!Pack)
9405 return ExprError();
9406 }
9407
Chad Rosier1dcde962012-08-08 18:46:20 +00009408
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009409 // We now know the length of the parameter pack, so build a new expression
9410 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009411 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9412 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009413 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009414}
9415
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009416template<typename Derived>
9417ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009418TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9419 SubstNonTypeTemplateParmPackExpr *E) {
9420 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009421 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009422}
9423
9424template<typename Derived>
9425ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009426TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9427 SubstNonTypeTemplateParmExpr *E) {
9428 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009429 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009430}
9431
9432template<typename Derived>
9433ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009434TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9435 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009436 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009437}
9438
9439template<typename Derived>
9440ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009441TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9442 MaterializeTemporaryExpr *E) {
9443 return getDerived().TransformExpr(E->GetTemporaryExpr());
9444}
Chad Rosier1dcde962012-08-08 18:46:20 +00009445
Douglas Gregorfe314812011-06-21 17:03:29 +00009446template<typename Derived>
9447ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009448TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9449 CXXStdInitializerListExpr *E) {
9450 return getDerived().TransformExpr(E->getSubExpr());
9451}
9452
9453template<typename Derived>
9454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009455TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009456 return SemaRef.MaybeBindToTemporary(E);
9457}
9458
9459template<typename Derived>
9460ExprResult
9461TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009462 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009463}
9464
9465template<typename Derived>
9466ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009467TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9468 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9469 if (SubExpr.isInvalid())
9470 return ExprError();
9471
9472 if (!getDerived().AlwaysRebuild() &&
9473 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009474 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009475
9476 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009477}
9478
9479template<typename Derived>
9480ExprResult
9481TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9482 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009483 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009484 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009485 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009486 /*IsCall=*/false, Elements, &ArgChanged))
9487 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009488
Ted Kremeneke65b0862012-03-06 20:05:56 +00009489 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9490 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009491
Ted Kremeneke65b0862012-03-06 20:05:56 +00009492 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9493 Elements.data(),
9494 Elements.size());
9495}
9496
9497template<typename Derived>
9498ExprResult
9499TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009500 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009501 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009502 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009503 bool ArgChanged = false;
9504 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9505 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009506
Ted Kremeneke65b0862012-03-06 20:05:56 +00009507 if (OrigElement.isPackExpansion()) {
9508 // This key/value element is a pack expansion.
9509 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9510 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9511 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9512 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9513
9514 // Determine whether the set of unexpanded parameter packs can
9515 // and should be expanded.
9516 bool Expand = true;
9517 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009518 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9519 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009520 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9521 OrigElement.Value->getLocEnd());
9522 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9523 PatternRange,
9524 Unexpanded,
9525 Expand, RetainExpansion,
9526 NumExpansions))
9527 return ExprError();
9528
9529 if (!Expand) {
9530 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009531 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009532 // expansion.
9533 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9534 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9535 if (Key.isInvalid())
9536 return ExprError();
9537
9538 if (Key.get() != OrigElement.Key)
9539 ArgChanged = true;
9540
9541 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9542 if (Value.isInvalid())
9543 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009544
Ted Kremeneke65b0862012-03-06 20:05:56 +00009545 if (Value.get() != OrigElement.Value)
9546 ArgChanged = true;
9547
Chad Rosier1dcde962012-08-08 18:46:20 +00009548 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009549 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9550 };
9551 Elements.push_back(Expansion);
9552 continue;
9553 }
9554
9555 // Record right away that the argument was changed. This needs
9556 // to happen even if the array expands to nothing.
9557 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009558
Ted Kremeneke65b0862012-03-06 20:05:56 +00009559 // The transform has determined that we should perform an elementwise
9560 // expansion of the pattern. Do so.
9561 for (unsigned I = 0; I != *NumExpansions; ++I) {
9562 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9563 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9564 if (Key.isInvalid())
9565 return ExprError();
9566
9567 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9568 if (Value.isInvalid())
9569 return ExprError();
9570
Chad Rosier1dcde962012-08-08 18:46:20 +00009571 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009572 Key.get(), Value.get(), SourceLocation(), NumExpansions
9573 };
9574
9575 // If any unexpanded parameter packs remain, we still have a
9576 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009577 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009578 if (Key.get()->containsUnexpandedParameterPack() ||
9579 Value.get()->containsUnexpandedParameterPack())
9580 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009581
Ted Kremeneke65b0862012-03-06 20:05:56 +00009582 Elements.push_back(Element);
9583 }
9584
Richard Smith9467be42014-06-06 17:33:35 +00009585 // FIXME: Retain a pack expansion if RetainExpansion is true.
9586
Ted Kremeneke65b0862012-03-06 20:05:56 +00009587 // We've finished with this pack expansion.
9588 continue;
9589 }
9590
9591 // Transform and check key.
9592 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9593 if (Key.isInvalid())
9594 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009595
Ted Kremeneke65b0862012-03-06 20:05:56 +00009596 if (Key.get() != OrigElement.Key)
9597 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009598
Ted Kremeneke65b0862012-03-06 20:05:56 +00009599 // Transform and check value.
9600 ExprResult Value
9601 = getDerived().TransformExpr(OrigElement.Value);
9602 if (Value.isInvalid())
9603 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009604
Ted Kremeneke65b0862012-03-06 20:05:56 +00009605 if (Value.get() != OrigElement.Value)
9606 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009607
9608 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009609 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009610 };
9611 Elements.push_back(Element);
9612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009613
Ted Kremeneke65b0862012-03-06 20:05:56 +00009614 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9615 return SemaRef.MaybeBindToTemporary(E);
9616
9617 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9618 Elements.data(),
9619 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009620}
9621
Mike Stump11289f42009-09-09 15:08:12 +00009622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009624TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009625 TypeSourceInfo *EncodedTypeInfo
9626 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9627 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009629
Douglas Gregora16548e2009-08-11 05:31:07 +00009630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009631 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009632 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009633
9634 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009635 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009636 E->getRParenLoc());
9637}
Mike Stump11289f42009-09-09 15:08:12 +00009638
Douglas Gregora16548e2009-08-11 05:31:07 +00009639template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009640ExprResult TreeTransform<Derived>::
9641TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009642 // This is a kind of implicit conversion, and it needs to get dropped
9643 // and recomputed for the same general reasons that ImplicitCastExprs
9644 // do, as well a more specific one: this expression is only valid when
9645 // it appears *immediately* as an argument expression.
9646 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009647}
9648
9649template<typename Derived>
9650ExprResult TreeTransform<Derived>::
9651TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009652 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009653 = getDerived().TransformType(E->getTypeInfoAsWritten());
9654 if (!TSInfo)
9655 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009656
John McCall31168b02011-06-15 23:02:42 +00009657 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009658 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009659 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009660
John McCall31168b02011-06-15 23:02:42 +00009661 if (!getDerived().AlwaysRebuild() &&
9662 TSInfo == E->getTypeInfoAsWritten() &&
9663 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009664 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009665
John McCall31168b02011-06-15 23:02:42 +00009666 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009667 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009668 Result.get());
9669}
9670
9671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009673TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009674 // Transform arguments.
9675 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009676 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009677 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009678 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009679 &ArgChanged))
9680 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009681
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009682 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9683 // Class message: transform the receiver type.
9684 TypeSourceInfo *ReceiverTypeInfo
9685 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9686 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009687 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009688
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009689 // If nothing changed, just retain the existing message send.
9690 if (!getDerived().AlwaysRebuild() &&
9691 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009692 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009693
9694 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009695 SmallVector<SourceLocation, 16> SelLocs;
9696 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009697 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9698 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009699 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009700 E->getMethodDecl(),
9701 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009702 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009703 E->getRightLoc());
9704 }
9705
9706 // Instance message: transform the receiver
9707 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9708 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009709 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009710 = getDerived().TransformExpr(E->getInstanceReceiver());
9711 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009712 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009713
9714 // If nothing changed, just retain the existing message send.
9715 if (!getDerived().AlwaysRebuild() &&
9716 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009717 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009718
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009719 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009720 SmallVector<SourceLocation, 16> SelLocs;
9721 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009722 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009723 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009724 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009725 E->getMethodDecl(),
9726 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009727 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009728 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009729}
9730
Mike Stump11289f42009-09-09 15:08:12 +00009731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009733TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009734 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009735}
9736
Mike Stump11289f42009-09-09 15:08:12 +00009737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009738ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009739TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009740 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009741}
9742
Mike Stump11289f42009-09-09 15:08:12 +00009743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009745TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009746 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009747 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009748 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009749 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009750
9751 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009752
Douglas Gregord51d90d2010-04-26 20:11:03 +00009753 // If nothing changed, just retain the existing expression.
9754 if (!getDerived().AlwaysRebuild() &&
9755 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009756 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009757
John McCallb268a282010-08-23 23:25:46 +00009758 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009759 E->getLocation(),
9760 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009761}
9762
Mike Stump11289f42009-09-09 15:08:12 +00009763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009765TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009766 // 'super' and types never change. Property never changes. Just
9767 // retain the existing expression.
9768 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009769 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009770
Douglas Gregor9faee212010-04-26 20:47:02 +00009771 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009772 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009773 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009774 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009775
Douglas Gregor9faee212010-04-26 20:47:02 +00009776 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009777
Douglas Gregor9faee212010-04-26 20:47:02 +00009778 // If nothing changed, just retain the existing expression.
9779 if (!getDerived().AlwaysRebuild() &&
9780 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009781 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009782
John McCallb7bd14f2010-12-02 01:19:52 +00009783 if (E->isExplicitProperty())
9784 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9785 E->getExplicitProperty(),
9786 E->getLocation());
9787
9788 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009789 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009790 E->getImplicitPropertyGetter(),
9791 E->getImplicitPropertySetter(),
9792 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009793}
9794
Mike Stump11289f42009-09-09 15:08:12 +00009795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009796ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009797TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9798 // Transform the base expression.
9799 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9800 if (Base.isInvalid())
9801 return ExprError();
9802
9803 // Transform the key expression.
9804 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9805 if (Key.isInvalid())
9806 return ExprError();
9807
9808 // If nothing changed, just retain the existing expression.
9809 if (!getDerived().AlwaysRebuild() &&
9810 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009811 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009812
Chad Rosier1dcde962012-08-08 18:46:20 +00009813 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009814 Base.get(), Key.get(),
9815 E->getAtIndexMethodDecl(),
9816 E->setAtIndexMethodDecl());
9817}
9818
9819template<typename Derived>
9820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009821TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009822 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009823 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009824 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009825 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009826
Douglas Gregord51d90d2010-04-26 20:11:03 +00009827 // If nothing changed, just retain the existing expression.
9828 if (!getDerived().AlwaysRebuild() &&
9829 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009830 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009831
John McCallb268a282010-08-23 23:25:46 +00009832 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009833 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009834 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009835}
9836
Mike Stump11289f42009-09-09 15:08:12 +00009837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009838ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009839TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009840 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009841 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009842 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009843 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009844 SubExprs, &ArgumentChanged))
9845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009846
Douglas Gregora16548e2009-08-11 05:31:07 +00009847 if (!getDerived().AlwaysRebuild() &&
9848 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009849 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009850
Douglas Gregora16548e2009-08-11 05:31:07 +00009851 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009852 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009853 E->getRParenLoc());
9854}
9855
Mike Stump11289f42009-09-09 15:08:12 +00009856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009857ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009858TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9859 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9860 if (SrcExpr.isInvalid())
9861 return ExprError();
9862
9863 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9864 if (!Type)
9865 return ExprError();
9866
9867 if (!getDerived().AlwaysRebuild() &&
9868 Type == E->getTypeSourceInfo() &&
9869 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009870 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009871
9872 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9873 SrcExpr.get(), Type,
9874 E->getRParenLoc());
9875}
9876
9877template<typename Derived>
9878ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009879TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009880 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009881
Craig Topperc3ec1492014-05-26 06:22:03 +00009882 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009883 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9884
9885 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009886 blockScope->TheDecl->setBlockMissingReturnType(
9887 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009888
Chris Lattner01cf8db2011-07-20 06:58:45 +00009889 SmallVector<ParmVarDecl*, 4> params;
9890 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009891
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009892 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009893 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9894 oldBlock->param_begin(),
9895 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009896 nullptr, paramTypes, &params)) {
9897 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009898 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009899 }
John McCall490112f2011-02-04 18:33:18 +00009900
Jordan Rosea0a86be2013-03-08 22:25:36 +00009901 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009902 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009903 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009904
Jordan Rose5c382722013-03-08 21:51:21 +00009905 QualType functionType =
9906 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009907 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009908 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009909
9910 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009911 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009912 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009913
9914 if (!oldBlock->blockMissingReturnType()) {
9915 blockScope->HasImplicitReturnType = false;
9916 blockScope->ReturnType = exprResultType;
9917 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009918
John McCall3882ace2011-01-05 12:14:39 +00009919 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009920 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009921 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009922 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009923 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009924 }
John McCall3882ace2011-01-05 12:14:39 +00009925
John McCall490112f2011-02-04 18:33:18 +00009926#ifndef NDEBUG
9927 // In builds with assertions, make sure that we captured everything we
9928 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009929 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009930 for (const auto &I : oldBlock->captures()) {
9931 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009932
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009933 // Ignore parameter packs.
9934 if (isa<ParmVarDecl>(oldCapture) &&
9935 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9936 continue;
John McCall490112f2011-02-04 18:33:18 +00009937
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009938 VarDecl *newCapture =
9939 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9940 oldCapture));
9941 assert(blockScope->CaptureMap.count(newCapture));
9942 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009943 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009944 }
9945#endif
9946
9947 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009948 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009949}
9950
Mike Stump11289f42009-09-09 15:08:12 +00009951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009952ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009953TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009954 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009955}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009956
9957template<typename Derived>
9958ExprResult
9959TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009960 QualType RetTy = getDerived().TransformType(E->getType());
9961 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009962 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009963 SubExprs.reserve(E->getNumSubExprs());
9964 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9965 SubExprs, &ArgumentChanged))
9966 return ExprError();
9967
9968 if (!getDerived().AlwaysRebuild() &&
9969 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009970 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009971
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009972 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009973 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009974}
Chad Rosier1dcde962012-08-08 18:46:20 +00009975
Douglas Gregora16548e2009-08-11 05:31:07 +00009976//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009977// Type reconstruction
9978//===----------------------------------------------------------------------===//
9979
Mike Stump11289f42009-09-09 15:08:12 +00009980template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009981QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9982 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009983 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009984 getDerived().getBaseEntity());
9985}
9986
Mike Stump11289f42009-09-09 15:08:12 +00009987template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009988QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9989 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009990 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009991 getDerived().getBaseEntity());
9992}
9993
Mike Stump11289f42009-09-09 15:08:12 +00009994template<typename Derived>
9995QualType
John McCall70dd5f62009-10-30 00:06:24 +00009996TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9997 bool WrittenAsLValue,
9998 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009999 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010000 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010001}
10002
10003template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010004QualType
John McCall70dd5f62009-10-30 00:06:24 +000010005TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10006 QualType ClassType,
10007 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010008 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10009 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010010}
10011
10012template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010013QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010014TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10015 ArrayType::ArraySizeModifier SizeMod,
10016 const llvm::APInt *Size,
10017 Expr *SizeExpr,
10018 unsigned IndexTypeQuals,
10019 SourceRange BracketsRange) {
10020 if (SizeExpr || !Size)
10021 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10022 IndexTypeQuals, BracketsRange,
10023 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010024
10025 QualType Types[] = {
10026 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10027 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10028 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010029 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010030 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010031 QualType SizeType;
10032 for (unsigned I = 0; I != NumTypes; ++I)
10033 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10034 SizeType = Types[I];
10035 break;
10036 }
Mike Stump11289f42009-09-09 15:08:12 +000010037
Eli Friedman9562f392012-01-25 23:20:27 +000010038 // Note that we can return a VariableArrayType here in the case where
10039 // the element type was a dependent VariableArrayType.
10040 IntegerLiteral *ArraySize
10041 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10042 /*FIXME*/BracketsRange.getBegin());
10043 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010044 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010045 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010046}
Mike Stump11289f42009-09-09 15:08:12 +000010047
Douglas Gregord6ff3322009-08-04 16:50:30 +000010048template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010049QualType
10050TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010051 ArrayType::ArraySizeModifier SizeMod,
10052 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010053 unsigned IndexTypeQuals,
10054 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010055 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010056 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010057}
10058
10059template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010060QualType
Mike Stump11289f42009-09-09 15:08:12 +000010061TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010062 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010063 unsigned IndexTypeQuals,
10064 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010065 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010066 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010067}
Mike Stump11289f42009-09-09 15:08:12 +000010068
Douglas Gregord6ff3322009-08-04 16:50:30 +000010069template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010070QualType
10071TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010072 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010073 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010074 unsigned IndexTypeQuals,
10075 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010076 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010077 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010078 IndexTypeQuals, BracketsRange);
10079}
10080
10081template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010082QualType
10083TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010084 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010085 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010086 unsigned IndexTypeQuals,
10087 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010088 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010089 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010090 IndexTypeQuals, BracketsRange);
10091}
10092
10093template<typename Derived>
10094QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010095 unsigned NumElements,
10096 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010097 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010098 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010099}
Mike Stump11289f42009-09-09 15:08:12 +000010100
Douglas Gregord6ff3322009-08-04 16:50:30 +000010101template<typename Derived>
10102QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10103 unsigned NumElements,
10104 SourceLocation AttributeLoc) {
10105 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10106 NumElements, true);
10107 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010108 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10109 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010110 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010111}
Mike Stump11289f42009-09-09 15:08:12 +000010112
Douglas Gregord6ff3322009-08-04 16:50:30 +000010113template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010114QualType
10115TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010116 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010117 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010118 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010119}
Mike Stump11289f42009-09-09 15:08:12 +000010120
Douglas Gregord6ff3322009-08-04 16:50:30 +000010121template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010122QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10123 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010124 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010125 const FunctionProtoType::ExtProtoInfo &EPI) {
10126 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010127 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010128 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010129 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010130}
Mike Stump11289f42009-09-09 15:08:12 +000010131
Douglas Gregord6ff3322009-08-04 16:50:30 +000010132template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010133QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10134 return SemaRef.Context.getFunctionNoProtoType(T);
10135}
10136
10137template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010138QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10139 assert(D && "no decl found");
10140 if (D->isInvalidDecl()) return QualType();
10141
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010142 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010143 TypeDecl *Ty;
10144 if (isa<UsingDecl>(D)) {
10145 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010146 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010147 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10148
10149 // A valid resolved using typename decl points to exactly one type decl.
10150 assert(++Using->shadow_begin() == Using->shadow_end());
10151 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010152
John McCallb96ec562009-12-04 22:46:56 +000010153 } else {
10154 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10155 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10156 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10157 }
10158
10159 return SemaRef.Context.getTypeDeclType(Ty);
10160}
10161
10162template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010163QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10164 SourceLocation Loc) {
10165 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010166}
10167
10168template<typename Derived>
10169QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10170 return SemaRef.Context.getTypeOfType(Underlying);
10171}
10172
10173template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010174QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10175 SourceLocation Loc) {
10176 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010177}
10178
10179template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010180QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10181 UnaryTransformType::UTTKind UKind,
10182 SourceLocation Loc) {
10183 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10184}
10185
10186template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010187QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010188 TemplateName Template,
10189 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010190 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010191 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010192}
Mike Stump11289f42009-09-09 15:08:12 +000010193
Douglas Gregor1135c352009-08-06 05:28:30 +000010194template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010195QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10196 SourceLocation KWLoc) {
10197 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10198}
10199
10200template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010201TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010202TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010203 bool TemplateKW,
10204 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010205 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010206 Template);
10207}
10208
10209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010210TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010211TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10212 const IdentifierInfo &Name,
10213 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010214 QualType ObjectType,
10215 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010216 UnqualifiedId TemplateName;
10217 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010218 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010219 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010220 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010221 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010222 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010223 /*EnteringContext=*/false,
10224 Template);
John McCall31f82722010-11-12 08:19:04 +000010225 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010226}
Mike Stump11289f42009-09-09 15:08:12 +000010227
Douglas Gregora16548e2009-08-11 05:31:07 +000010228template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010229TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010230TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010231 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010232 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010233 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010234 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010235 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010236 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010237 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010238 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010239 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010240 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010241 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010242 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010243 /*EnteringContext=*/false,
10244 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010245 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010246}
Chad Rosier1dcde962012-08-08 18:46:20 +000010247
Douglas Gregor71395fa2009-11-04 00:56:37 +000010248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010249ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010250TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10251 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010252 Expr *OrigCallee,
10253 Expr *First,
10254 Expr *Second) {
10255 Expr *Callee = OrigCallee->IgnoreParenCasts();
10256 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010257
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010258 if (First->getObjectKind() == OK_ObjCProperty) {
10259 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10260 if (BinaryOperator::isAssignmentOp(Opc))
10261 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10262 First, Second);
10263 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10264 if (Result.isInvalid())
10265 return ExprError();
10266 First = Result.get();
10267 }
10268
10269 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10270 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10271 if (Result.isInvalid())
10272 return ExprError();
10273 Second = Result.get();
10274 }
10275
Douglas Gregora16548e2009-08-11 05:31:07 +000010276 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010277 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010278 if (!First->getType()->isOverloadableType() &&
10279 !Second->getType()->isOverloadableType())
10280 return getSema().CreateBuiltinArraySubscriptExpr(First,
10281 Callee->getLocStart(),
10282 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010283 } else if (Op == OO_Arrow) {
10284 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010285 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10286 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010287 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010288 // The argument is not of overloadable type, so try to create a
10289 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010290 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010291 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010292
John McCallb268a282010-08-23 23:25:46 +000010293 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010294 }
10295 } else {
John McCallb268a282010-08-23 23:25:46 +000010296 if (!First->getType()->isOverloadableType() &&
10297 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010298 // Neither of the arguments is an overloadable type, so try to
10299 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010300 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010301 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010302 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010303 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010305
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010306 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010307 }
10308 }
Mike Stump11289f42009-09-09 15:08:12 +000010309
10310 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010311 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010312 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010313
John McCallb268a282010-08-23 23:25:46 +000010314 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010315 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010316 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010317 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010318 // If we've resolved this to a particular non-member function, just call
10319 // that function. If we resolved it to a member function,
10320 // CreateOverloaded* will find that function for us.
10321 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10322 if (!isa<CXXMethodDecl>(ND))
10323 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010324 }
Mike Stump11289f42009-09-09 15:08:12 +000010325
Douglas Gregora16548e2009-08-11 05:31:07 +000010326 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010327 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010328 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010329
Douglas Gregora16548e2009-08-11 05:31:07 +000010330 // Create the overloaded operator invocation for unary operators.
10331 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010332 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010333 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010334 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010335 }
Mike Stump11289f42009-09-09 15:08:12 +000010336
Douglas Gregore9d62932011-07-15 16:25:15 +000010337 if (Op == OO_Subscript) {
10338 SourceLocation LBrace;
10339 SourceLocation RBrace;
10340
10341 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10342 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10343 LBrace = SourceLocation::getFromRawEncoding(
10344 NameLoc.CXXOperatorName.BeginOpNameLoc);
10345 RBrace = SourceLocation::getFromRawEncoding(
10346 NameLoc.CXXOperatorName.EndOpNameLoc);
10347 } else {
10348 LBrace = Callee->getLocStart();
10349 RBrace = OpLoc;
10350 }
10351
10352 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10353 First, Second);
10354 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010355
Douglas Gregora16548e2009-08-11 05:31:07 +000010356 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010357 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010358 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010359 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10360 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010361 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010362
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010363 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010364}
Mike Stump11289f42009-09-09 15:08:12 +000010365
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010366template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010367ExprResult
John McCallb268a282010-08-23 23:25:46 +000010368TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010369 SourceLocation OperatorLoc,
10370 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010371 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010372 TypeSourceInfo *ScopeType,
10373 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010374 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010375 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010376 QualType BaseType = Base->getType();
10377 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010378 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010379 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010380 !BaseType->getAs<PointerType>()->getPointeeType()
10381 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010382 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010383 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010384 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010385 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010386 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010387 /*FIXME?*/true);
10388 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010389
Douglas Gregor678f90d2010-02-25 01:56:36 +000010390 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010391 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10392 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10393 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10394 NameInfo.setNamedTypeInfo(DestroyedType);
10395
Richard Smith8e4a3862012-05-15 06:15:11 +000010396 // The scope type is now known to be a valid nested name specifier
10397 // component. Tack it on to the end of the nested name specifier.
10398 if (ScopeType)
10399 SS.Extend(SemaRef.Context, SourceLocation(),
10400 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010401
Abramo Bagnara7945c982012-01-27 09:46:47 +000010402 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010403 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010404 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010405 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010406 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010407 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010408 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010409}
10410
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010411template<typename Derived>
10412StmtResult
10413TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010414 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010415 CapturedDecl *CD = S->getCapturedDecl();
10416 unsigned NumParams = CD->getNumParams();
10417 unsigned ContextParamPos = CD->getContextParamPosition();
10418 SmallVector<Sema::CapturedParamNameType, 4> Params;
10419 for (unsigned I = 0; I < NumParams; ++I) {
10420 if (I != ContextParamPos) {
10421 Params.push_back(
10422 std::make_pair(
10423 CD->getParam(I)->getName(),
10424 getDerived().TransformType(CD->getParam(I)->getType())));
10425 } else {
10426 Params.push_back(std::make_pair(StringRef(), QualType()));
10427 }
10428 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010429 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010430 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010431 StmtResult Body;
10432 {
10433 Sema::CompoundScopeRAII CompoundScope(getSema());
10434 Body = getDerived().TransformStmt(S->getCapturedStmt());
10435 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010436
10437 if (Body.isInvalid()) {
10438 getSema().ActOnCapturedRegionError();
10439 return StmtError();
10440 }
10441
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010442 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010443}
10444
Douglas Gregord6ff3322009-08-04 16:50:30 +000010445} // end namespace clang
10446
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010447#endif