blob: df4ab10e748b69047246772d05f64d71c48934c5 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000347 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
Hans Wennborge113c202014-09-18 16:01:32 +0000548 unsigned ThisTypeQuals);
Douglas Gregor3024f072012-04-16 07:05:22 +0000549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Nico Weberc153d242014-07-28 00:02:09 +0000563 QualType TransformDependentTemplateSpecializationType(
564 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
565 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566
John McCall58f10c32010-03-11 09:03:00 +0000567 /// \brief Transforms the parameters of a function type into the
568 /// given vectors.
569 ///
570 /// The result vectors should be kept in sync; null entries in the
571 /// variables vector are acceptable.
572 ///
573 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000574 bool TransformFunctionTypeParams(SourceLocation Loc,
575 ParmVarDecl **Params, unsigned NumParams,
576 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000577 SmallVectorImpl<QualType> &PTypes,
578 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000579
580 /// \brief Transforms a single function-type parameter. Return null
581 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000582 ///
583 /// \param indexAdjustment - A number to add to the parameter's
584 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000585 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000586 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000587 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000588 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000589
John McCall31f82722010-11-12 08:19:04 +0000590 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000591
John McCalldadc5752010-08-24 06:29:42 +0000592 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
593 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000594
595 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000596 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000597 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
598 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000599
Faisal Vali2cba1332013-10-23 06:44:28 +0000600 TemplateParameterList *TransformTemplateParameterList(
601 TemplateParameterList *TPL) {
602 return TPL;
603 }
604
Richard Smithdb2630f2012-10-21 03:28:35 +0000605 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000608 bool IsAddressOfOperand,
609 TypeSourceInfo **RecoveryTSI);
610
611 ExprResult TransformParenDependentScopeDeclRefExpr(
612 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
613 TypeSourceInfo **RecoveryTSI);
614
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000615 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000616
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
618// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000619#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000620 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000621 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000622#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000624 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000625#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000626#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000627
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000628#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000629 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000630 OMPClause *Transform ## Class(Class *S);
631#include "clang/Basic/OpenMPKinds.def"
632
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 /// \brief Build a new pointer type given its pointee type.
634 ///
635 /// By default, performs semantic analysis when building the pointer type.
636 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
639 /// \brief Build a new block pointer type given its pointee type.
640 ///
Mike Stump11289f42009-09-09 15:08:12 +0000641 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000643 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 ///
John McCall70dd5f62009-10-30 00:06:24 +0000647 /// By default, performs semantic analysis when building the
648 /// reference type. Subclasses may override this routine to provide
649 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000650 ///
John McCall70dd5f62009-10-30 00:06:24 +0000651 /// \param LValue whether the type was written with an lvalue sigil
652 /// or an rvalue sigil.
653 QualType RebuildReferenceType(QualType ReferentType,
654 bool LValue,
655 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000656
Douglas Gregord6ff3322009-08-04 16:50:30 +0000657 /// \brief Build a new member pointer type given the pointee type and the
658 /// class type it refers into.
659 ///
660 /// By default, performs semantic analysis when building the member pointer
661 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000662 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
663 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000664
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// \brief Build a new array type given the element type, size
666 /// modifier, size of the array (if known), size expression, and index type
667 /// qualifiers.
668 ///
669 /// By default, performs semantic analysis when building the array type.
670 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000671 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672 QualType RebuildArrayType(QualType ElementType,
673 ArrayType::ArraySizeModifier SizeMod,
674 const llvm::APInt *Size,
675 Expr *SizeExpr,
676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new constant array type given the element type, size
680 /// modifier, (known) size of the array, and index type qualifiers.
681 ///
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000684 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
686 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000689
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 /// \brief Build a new incomplete array type given the element type, size
691 /// modifier, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000695 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 /// size modifier, size expression, and index type qualifiers.
702 ///
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000705 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000707 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
710
Mike Stump11289f42009-09-09 15:08:12 +0000711 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 /// size modifier, size expression, and index type qualifiers.
713 ///
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000716 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000718 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 unsigned IndexTypeQuals,
720 SourceRange BracketsRange);
721
722 /// \brief Build a new vector type given the element type and
723 /// number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000727 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000728 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000729
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 /// \brief Build a new extended vector type given the element type and
731 /// number of elements.
732 ///
733 /// By default, performs semantic analysis when building the vector type.
734 /// Subclasses may override this routine to provide different behavior.
735 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
736 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000737
738 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// given the element type and number of elements.
740 ///
741 /// By default, performs semantic analysis when building the vector type.
742 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000743 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000744 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 /// \brief Build a new function type.
748 ///
749 /// By default, performs semantic analysis when building the function type.
750 /// Subclasses may override this routine to provide different behavior.
751 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000752 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000753 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000754
John McCall550e0c22009-10-21 00:40:46 +0000755 /// \brief Build a new unprototyped function type.
756 QualType RebuildFunctionNoProtoType(QualType ResultType);
757
John McCallb96ec562009-12-04 22:46:56 +0000758 /// \brief Rebuild an unresolved typename type, given the decl that
759 /// the UnresolvedUsingTypenameDecl was transformed to.
760 QualType RebuildUnresolvedUsingType(Decl *D);
761
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000763 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 return SemaRef.Context.getTypeDeclType(Typedef);
765 }
766
767 /// \brief Build a new class/struct/union type.
768 QualType RebuildRecordType(RecordDecl *Record) {
769 return SemaRef.Context.getTypeDeclType(Record);
770 }
771
772 /// \brief Build a new Enum type.
773 QualType RebuildEnumType(EnumDecl *Enum) {
774 return SemaRef.Context.getTypeDeclType(Enum);
775 }
John McCallfcc33b02009-09-05 00:15:47 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, performs semantic analysis when building the typeof type.
780 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000781 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000782
Mike Stump11289f42009-09-09 15:08:12 +0000783 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000784 ///
785 /// By default, builds a new TypeOfType with the given underlying type.
786 QualType RebuildTypeOfType(QualType Underlying);
787
Alexis Hunte852b102011-05-24 22:41:36 +0000788 /// \brief Build a new unary transform type.
789 QualType RebuildUnaryTransformType(QualType BaseType,
790 UnaryTransformType::UTTKind UKind,
791 SourceLocation Loc);
792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 ///
795 /// By default, performs semantic analysis when building the decltype type.
796 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000797 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000798
Richard Smith74aeef52013-04-26 16:15:35 +0000799 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000800 ///
801 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000802 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000803 // Note, IsDependent is always false here: we implicitly convert an 'auto'
804 // which has been deduced to a dependent type into an undeduced 'auto', so
805 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000806 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
807 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000808 }
809
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 /// \brief Build a new template specialization type.
811 ///
812 /// By default, performs semantic analysis when building the template
813 /// specialization type. Subclasses may override this routine to provide
814 /// different behavior.
815 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000816 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000817 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000818
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000819 /// \brief Build a new parenthesized type.
820 ///
821 /// By default, builds a new ParenType type from the inner type.
822 /// Subclasses may override this routine to provide different behavior.
823 QualType RebuildParenType(QualType InnerType) {
824 return SemaRef.Context.getParenType(InnerType);
825 }
826
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 /// \brief Build a new qualified name type.
828 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000829 /// By default, builds a new ElaboratedType type from the keyword,
830 /// the nested-name-specifier and the named type.
831 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000832 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
833 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000834 NestedNameSpecifierLoc QualifierLoc,
835 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000836 return SemaRef.Context.getElaboratedType(Keyword,
837 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000838 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000839 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000840
841 /// \brief Build a new typename type that refers to a template-id.
842 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000843 /// By default, builds a new DependentNameType type from the
844 /// nested-name-specifier and the given type. Subclasses may override
845 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000846 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 ElaboratedTypeKeyword Keyword,
848 NestedNameSpecifierLoc QualifierLoc,
849 const IdentifierInfo *Name,
850 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000851 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000852 // Rebuild the template name.
853 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000854 CXXScopeSpec SS;
855 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000856 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000857 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
858 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000859
Douglas Gregora7a795b2011-03-01 20:11:18 +0000860 if (InstName.isNull())
861 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000862
Douglas Gregora7a795b2011-03-01 20:11:18 +0000863 // If it's still dependent, make a dependent specialization.
864 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000865 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
866 QualifierLoc.getNestedNameSpecifier(),
867 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000868 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 // Otherwise, make an elaborated type wrapping a non-dependent
871 // specialization.
872 QualType T =
873 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
874 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000875
Craig Topperc3ec1492014-05-26 06:22:03 +0000876 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000877 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000878
879 return SemaRef.Context.getElaboratedType(Keyword,
880 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000881 T);
882 }
883
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884 /// \brief Build a new typename type that refers to an identifier.
885 ///
886 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000888 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000889 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 NestedNameSpecifierLoc QualifierLoc,
892 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000893 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000894 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000895 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000896
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000897 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000898 // If the name is still dependent, just build a new dependent name type.
899 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 return SemaRef.Context.getDependentNameType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000902 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000903 }
904
Abramo Bagnara6150c882010-05-11 21:36:43 +0000905 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000906 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000907 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000908
909 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
910
Abramo Bagnarad7548482010-05-19 21:37:53 +0000911 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000912 // into a non-dependent elaborated-type-specifier. Find the tag we're
913 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000914 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
916 if (!DC)
917 return QualType();
918
John McCallbf8c5192010-05-27 06:40:31 +0000919 if (SemaRef.RequireCompleteDeclContext(SS, DC))
920 return QualType();
921
Craig Topperc3ec1492014-05-26 06:22:03 +0000922 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 SemaRef.LookupQualifiedName(Result, DC);
924 switch (Result.getResultKind()) {
925 case LookupResult::NotFound:
926 case LookupResult::NotFoundInCurrentInstantiation:
927 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000928
Douglas Gregore677daf2010-03-31 22:19:08 +0000929 case LookupResult::Found:
930 Tag = Result.getAsSingle<TagDecl>();
931 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000932
Douglas Gregore677daf2010-03-31 22:19:08 +0000933 case LookupResult::FoundOverloaded:
934 case LookupResult::FoundUnresolvedValue:
935 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000936
Douglas Gregore677daf2010-03-31 22:19:08 +0000937 case LookupResult::Ambiguous:
938 // Let the LookupResult structure handle ambiguities.
939 return QualType();
940 }
941
942 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000943 // Check where the name exists but isn't a tag type and use that to emit
944 // better diagnostics.
945 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::Found:
949 case LookupResult::FoundOverloaded:
950 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000951 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000952 unsigned Kind = 0;
953 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000954 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
955 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000956 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
957 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
958 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000959 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000960 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000961 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000962 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000963 break;
964 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 return QualType();
966 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000967
Richard Trieucaa33d32011-06-10 03:11:26 +0000968 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
969 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000970 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000971 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
972 return QualType();
973 }
974
975 // Build the elaborated-type-specifier type.
976 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000977 return SemaRef.Context.getElaboratedType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000979 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregor822d0302011-01-12 17:07:58 +0000982 /// \brief Build a new pack expansion type.
983 ///
984 /// By default, builds a new PackExpansionType type from the given pattern.
985 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000986 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000987 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000988 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000989 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000990 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
991 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000992 }
993
Eli Friedman0dfb8892011-10-06 23:00:33 +0000994 /// \brief Build a new atomic type given its value type.
995 ///
996 /// By default, performs semantic analysis when building the atomic type.
997 /// Subclasses may override this routine to provide different behavior.
998 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
999
Douglas Gregor71dc5092009-08-06 06:41:21 +00001000 /// \brief Build a new template name given a nested name specifier, a flag
1001 /// indicating whether the "template" keyword was provided, and the template
1002 /// that the template name refers to.
1003 ///
1004 /// By default, builds the new template name directly. Subclasses may override
1005 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001006 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001007 bool TemplateKW,
1008 TemplateDecl *Template);
1009
Douglas Gregor71dc5092009-08-06 06:41:21 +00001010 /// \brief Build a new template name given a nested name specifier and the
1011 /// name that is referred to as a template.
1012 ///
1013 /// By default, performs semantic analysis to determine whether the name can
1014 /// be resolved to a specific template, then builds the appropriate kind of
1015 /// template name. Subclasses may override this routine to provide different
1016 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001017 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1018 const IdentifierInfo &Name,
1019 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001020 QualType ObjectType,
1021 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregor71395fa2009-11-04 00:56:37 +00001023 /// \brief Build a new template name given a nested name specifier and the
1024 /// overloaded operator name that is referred to as a template.
1025 ///
1026 /// By default, performs semantic analysis to determine whether the name can
1027 /// be resolved to a specific template, then builds the appropriate kind of
1028 /// template name. Subclasses may override this routine to provide different
1029 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001030 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001031 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001032 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001033 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001034
1035 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001036 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001037 ///
1038 /// By default, performs semantic analysis to determine whether the name can
1039 /// be resolved to a specific template, then builds the appropriate kind of
1040 /// template name. Subclasses may override this routine to provide different
1041 /// behavior.
1042 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1043 const TemplateArgument &ArgPack) {
1044 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1045 }
1046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new compound statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 MultiStmtArg Statements,
1053 SourceLocation RBraceLoc,
1054 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001055 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 IsStmtExpr);
1057 }
1058
1059 /// \brief Build a new case statement.
1060 ///
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001063 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001064 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001065 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001066 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001068 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001069 ColonLoc);
1070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Attach the body to a new case statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001077 getSema().ActOnCaseStmtBody(S, Body);
1078 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
Mike Stump11289f42009-09-09 15:08:12 +00001080
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /// \brief Build a new default statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Stmt *SubStmt) {
1088 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001089 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 }
Mike Stump11289f42009-09-09 15:08:12 +00001091
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 /// \brief Build a new label statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001096 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1097 SourceLocation ColonLoc, Stmt *SubStmt) {
1098 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 }
Mike Stump11289f42009-09-09 15:08:12 +00001100
Richard Smithc202b282012-04-14 00:33:13 +00001101 /// \brief Build a new label statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001105 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1106 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001107 Stmt *SubStmt) {
1108 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1109 }
1110
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 /// \brief Build a new "if" statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001116 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001117 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001118 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Start building a new switch statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001126 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001127 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001128 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001129 }
Mike Stump11289f42009-09-09 15:08:12 +00001130
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 /// \brief Attach the body to the switch statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001135 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001136 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001137 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 }
1139
1140 /// \brief Build a new while statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001144 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1145 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001146 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 }
Mike Stump11289f42009-09-09 15:08:12 +00001148
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 /// \brief Build a new do-while statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001153 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001154 SourceLocation WhileLoc, SourceLocation LParenLoc,
1155 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001156 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1157 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001158 }
1159
1160 /// \brief Build a new for statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001164 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001166 VarDecl *CondVar, Sema::FullExprArg Inc,
1167 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001168 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001169 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new goto statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001176 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1177 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001178 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001179 }
1180
1181 /// \brief Build a new indirect goto statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001186 SourceLocation StarLoc,
1187 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 /// \brief Build a new return statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001195 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001196 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 }
Mike Stump11289f42009-09-09 15:08:12 +00001198
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 /// \brief Build a new declaration statement.
1200 ///
1201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001203 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001204 SourceLocation StartLoc, SourceLocation EndLoc) {
1205 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001206 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Anders Carlssonaaeef072010-01-24 05:50:09 +00001209 /// \brief Build a new inline asm statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001213 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1214 bool IsVolatile, unsigned NumOutputs,
1215 unsigned NumInputs, IdentifierInfo **Names,
1216 MultiExprArg Constraints, MultiExprArg Exprs,
1217 Expr *AsmString, MultiExprArg Clobbers,
1218 SourceLocation RParenLoc) {
1219 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1220 NumInputs, Names, Constraints, Exprs,
1221 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001222 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001223
Chad Rosier32503022012-06-11 20:47:18 +00001224 /// \brief Build a new MS style inline asm statement.
1225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001228 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001229 ArrayRef<Token> AsmToks,
1230 StringRef AsmString,
1231 unsigned NumOutputs, unsigned NumInputs,
1232 ArrayRef<StringRef> Constraints,
1233 ArrayRef<StringRef> Clobbers,
1234 ArrayRef<Expr*> Exprs,
1235 SourceLocation EndLoc) {
1236 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1237 NumOutputs, NumInputs,
1238 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001239 }
1240
James Dennett2a4d13c2012-06-15 07:13:21 +00001241 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001246 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001247 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001248 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001249 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001250 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001251 }
1252
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001253 /// \brief Rebuild an Objective-C exception declaration.
1254 ///
1255 /// By default, performs semantic analysis to build the new declaration.
1256 /// Subclasses may override this routine to provide different behavior.
1257 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1258 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001259 return getSema().BuildObjCExceptionDecl(TInfo, T,
1260 ExceptionDecl->getInnerLocStart(),
1261 ExceptionDecl->getLocation(),
1262 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001264
James Dennett2a4d13c2012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001269 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001270 SourceLocation RParenLoc,
1271 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001272 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001273 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001274 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001276
James Dennett2a4d13c2012-06-15 07:13:21 +00001277 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001281 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001282 Stmt *Body) {
1283 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001285
James Dennett2a4d13c2012-06-15 07:13:21 +00001286 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001291 Expr *Operand) {
1292 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001293 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001294
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001295 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001299 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001300 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001301 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001302 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001303 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001304 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1305 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001306 }
1307
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001308 /// \brief Build a new OpenMP 'if' clause.
1309 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001310 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001311 /// Subclasses may override this routine to provide different behavior.
1312 OMPClause *RebuildOMPIfClause(Expr *Condition,
1313 SourceLocation StartLoc,
1314 SourceLocation LParenLoc,
1315 SourceLocation EndLoc) {
1316 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1317 LParenLoc, EndLoc);
1318 }
1319
Alexey Bataev3778b602014-07-17 07:32:53 +00001320 /// \brief Build a new OpenMP 'final' clause.
1321 ///
1322 /// By default, performs semantic analysis to build the new OpenMP clause.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1325 SourceLocation LParenLoc,
1326 SourceLocation EndLoc) {
1327 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1328 EndLoc);
1329 }
1330
Alexey Bataev568a8332014-03-06 06:15:19 +00001331 /// \brief Build a new OpenMP 'num_threads' clause.
1332 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001333 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1340 LParenLoc, EndLoc);
1341 }
1342
Alexey Bataev62c87d22014-03-21 04:51:18 +00001343 /// \brief Build a new OpenMP 'safelen' clause.
1344 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001345 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1351 }
1352
Alexander Musman8bd31e62014-05-27 15:12:19 +00001353 /// \brief Build a new OpenMP 'collapse' clause.
1354 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001355 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001356 /// Subclasses may override this routine to provide different behavior.
1357 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1361 EndLoc);
1362 }
1363
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001364 /// \brief Build a new OpenMP 'default' clause.
1365 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001366 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001367 /// Subclasses may override this routine to provide different behavior.
1368 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1369 SourceLocation KindKwLoc,
1370 SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1374 StartLoc, LParenLoc, EndLoc);
1375 }
1376
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001377 /// \brief Build a new OpenMP 'proc_bind' clause.
1378 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001379 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1382 SourceLocation KindKwLoc,
1383 SourceLocation StartLoc,
1384 SourceLocation LParenLoc,
1385 SourceLocation EndLoc) {
1386 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1387 StartLoc, LParenLoc, EndLoc);
1388 }
1389
Alexey Bataev56dafe82014-06-20 07:16:17 +00001390 /// \brief Build a new OpenMP 'schedule' clause.
1391 ///
1392 /// By default, performs semantic analysis to build the new OpenMP clause.
1393 /// Subclasses may override this routine to provide different behavior.
1394 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1395 Expr *ChunkSize,
1396 SourceLocation StartLoc,
1397 SourceLocation LParenLoc,
1398 SourceLocation KindLoc,
1399 SourceLocation CommaLoc,
1400 SourceLocation EndLoc) {
1401 return getSema().ActOnOpenMPScheduleClause(
1402 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1403 }
1404
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001405 /// \brief Build a new OpenMP 'private' clause.
1406 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001407 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001408 /// Subclasses may override this routine to provide different behavior.
1409 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1410 SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1414 EndLoc);
1415 }
1416
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001417 /// \brief Build a new OpenMP 'firstprivate' clause.
1418 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001419 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001420 /// Subclasses may override this routine to provide different behavior.
1421 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1422 SourceLocation StartLoc,
1423 SourceLocation LParenLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1426 EndLoc);
1427 }
1428
Alexander Musman1bb328c2014-06-04 13:06:39 +00001429 /// \brief Build a new OpenMP 'lastprivate' clause.
1430 ///
1431 /// By default, performs semantic analysis to build the new OpenMP clause.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1438 EndLoc);
1439 }
1440
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001441 /// \brief Build a new OpenMP 'shared' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001444 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001445 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1450 EndLoc);
1451 }
1452
Alexey Bataevc5e02582014-06-16 07:08:35 +00001453 /// \brief Build a new OpenMP 'reduction' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new statement.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1458 SourceLocation StartLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation ColonLoc,
1461 SourceLocation EndLoc,
1462 CXXScopeSpec &ReductionIdScopeSpec,
1463 const DeclarationNameInfo &ReductionId) {
1464 return getSema().ActOnOpenMPReductionClause(
1465 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1466 ReductionId);
1467 }
1468
Alexander Musman8dba6642014-04-22 13:09:42 +00001469 /// \brief Build a new OpenMP 'linear' clause.
1470 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001471 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001472 /// Subclasses may override this routine to provide different behavior.
1473 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation ColonLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1479 ColonLoc, EndLoc);
1480 }
1481
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001482 /// \brief Build a new OpenMP 'aligned' clause.
1483 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001484 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001485 /// Subclasses may override this routine to provide different behavior.
1486 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1487 SourceLocation StartLoc,
1488 SourceLocation LParenLoc,
1489 SourceLocation ColonLoc,
1490 SourceLocation EndLoc) {
1491 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1492 LParenLoc, ColonLoc, EndLoc);
1493 }
1494
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001495 /// \brief Build a new OpenMP 'copyin' clause.
1496 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001497 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001498 /// Subclasses may override this routine to provide different behavior.
1499 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1500 SourceLocation StartLoc,
1501 SourceLocation LParenLoc,
1502 SourceLocation EndLoc) {
1503 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1504 EndLoc);
1505 }
1506
Alexey Bataevbae9a792014-06-27 10:37:06 +00001507 /// \brief Build a new OpenMP 'copyprivate' clause.
1508 ///
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1512 SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1516 EndLoc);
1517 }
1518
Alexey Bataev6125da92014-07-21 11:26:11 +00001519 /// \brief Build a new OpenMP 'flush' pseudo clause.
1520 ///
1521 /// By default, performs semantic analysis to build the new OpenMP clause.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1528 EndLoc);
1529 }
1530
James Dennett2a4d13c2012-06-15 07:13:21 +00001531 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001532 ///
1533 /// By default, performs semantic analysis to build the new statement.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1536 Expr *object) {
1537 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1538 }
1539
James Dennett2a4d13c2012-06-15 07:13:21 +00001540 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001541 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001542 /// By default, performs semantic analysis to build the new statement.
1543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001544 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001545 Expr *Object, Stmt *Body) {
1546 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001547 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001548
James Dennett2a4d13c2012-06-15 07:13:21 +00001549 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1553 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1554 Stmt *Body) {
1555 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1556 }
John McCall53848232011-07-27 01:07:15 +00001557
Douglas Gregorf68a5082010-04-22 23:10:45 +00001558 /// \brief Build a new Objective-C fast enumeration statement.
1559 ///
1560 /// By default, performs semantic analysis to build the new statement.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001563 Stmt *Element,
1564 Expr *Collection,
1565 SourceLocation RParenLoc,
1566 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001567 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001568 Element,
John McCallb268a282010-08-23 23:25:46 +00001569 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001570 RParenLoc);
1571 if (ForEachStmt.isInvalid())
1572 return StmtError();
1573
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001574 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001576
Douglas Gregorebe10102009-08-20 07:17:43 +00001577 /// \brief Build a new C++ exception declaration.
1578 ///
1579 /// By default, performs semantic analysis to build the new decaration.
1580 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001581 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001582 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001583 SourceLocation StartLoc,
1584 SourceLocation IdLoc,
1585 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001586 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001587 StartLoc, IdLoc, Id);
1588 if (Var)
1589 getSema().CurContext->addDecl(Var);
1590 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001591 }
1592
1593 /// \brief Build a new C++ catch statement.
1594 ///
1595 /// By default, performs semantic analysis to build the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001598 VarDecl *ExceptionDecl,
1599 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001600 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1601 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001602 }
Mike Stump11289f42009-09-09 15:08:12 +00001603
Douglas Gregorebe10102009-08-20 07:17:43 +00001604 /// \brief Build a new C++ try statement.
1605 ///
1606 /// By default, performs semantic analysis to build the new statement.
1607 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001608 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1609 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001610 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001611 }
Mike Stump11289f42009-09-09 15:08:12 +00001612
Richard Smith02e85f32011-04-14 22:09:26 +00001613 /// \brief Build a new C++0x range-based for statement.
1614 ///
1615 /// By default, performs semantic analysis to build the new statement.
1616 /// Subclasses may override this routine to provide different behavior.
1617 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1618 SourceLocation ColonLoc,
1619 Stmt *Range, Stmt *BeginEnd,
1620 Expr *Cond, Expr *Inc,
1621 Stmt *LoopVar,
1622 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001623 // If we've just learned that the range is actually an Objective-C
1624 // collection, treat this as an Objective-C fast enumeration loop.
1625 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1626 if (RangeStmt->isSingleDecl()) {
1627 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001628 if (RangeVar->isInvalidDecl())
1629 return StmtError();
1630
Douglas Gregorf7106af2013-04-08 18:40:13 +00001631 Expr *RangeExpr = RangeVar->getInit();
1632 if (!RangeExpr->isTypeDependent() &&
1633 RangeExpr->getType()->isObjCObjectPointerType())
1634 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1635 RParenLoc);
1636 }
1637 }
1638 }
1639
Richard Smith02e85f32011-04-14 22:09:26 +00001640 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001641 Cond, Inc, LoopVar, RParenLoc,
1642 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001643 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001644
1645 /// \brief Build a new C++0x range-based for statement.
1646 ///
1647 /// By default, performs semantic analysis to build the new statement.
1648 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001649 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001650 bool IsIfExists,
1651 NestedNameSpecifierLoc QualifierLoc,
1652 DeclarationNameInfo NameInfo,
1653 Stmt *Nested) {
1654 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1655 QualifierLoc, NameInfo, Nested);
1656 }
1657
Richard Smith02e85f32011-04-14 22:09:26 +00001658 /// \brief Attach body to a C++0x range-based for statement.
1659 ///
1660 /// By default, performs semantic analysis to finish the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
1662 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1663 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001665
David Majnemerfad8f482013-10-15 09:33:02 +00001666 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001667 Stmt *TryBlock, Stmt *Handler) {
1668 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001669 }
1670
David Majnemerfad8f482013-10-15 09:33:02 +00001671 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001672 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001673 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001674 }
1675
David Majnemerfad8f482013-10-15 09:33:02 +00001676 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1677 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001678 }
1679
Alexey Bataevec474782014-10-09 08:45:04 +00001680 /// \brief Build a new predefined expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
1684 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1685 PredefinedExpr::IdentType IT) {
1686 return getSema().BuildPredefinedExpr(Loc, IT);
1687 }
1688
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 /// \brief Build a new expression that references a declaration.
1690 ///
1691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001694 LookupResult &R,
1695 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001696 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1697 }
1698
1699
1700 /// \brief Build a new expression that references a declaration.
1701 ///
1702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001704 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001705 ValueDecl *VD,
1706 const DeclarationNameInfo &NameInfo,
1707 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001708 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001709 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001710
1711 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001712
1713 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
Mike Stump11289f42009-09-09 15:08:12 +00001715
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregora16548e2009-08-11 05:31:07 +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 RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001722 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 }
1724
Douglas Gregorad8a3362009-09-04 17:36:40 +00001725 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001726 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001729 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001730 SourceLocation OperatorLoc,
1731 bool isArrow,
1732 CXXScopeSpec &SS,
1733 TypeSourceInfo *ScopeType,
1734 SourceLocation CCLoc,
1735 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001736 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001737
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001739 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001742 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001743 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001744 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001745 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
Mike Stump11289f42009-09-09 15:08:12 +00001747
Douglas Gregor882211c2010-04-28 22:16:22 +00001748 /// \brief Build a new builtin offsetof expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001753 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001754 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001755 unsigned NumComponents,
1756 SourceLocation RParenLoc) {
1757 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1758 NumComponents, RParenLoc);
1759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001760
1761 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001762 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001763 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001766 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1767 SourceLocation OpLoc,
1768 UnaryExprOrTypeTrait ExprKind,
1769 SourceRange R) {
1770 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
Peter Collingbournee190dee2011-03-11 19:24:49 +00001773 /// \brief Build a new sizeof, alignof or vec step expression with an
1774 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001775 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001778 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1779 UnaryExprOrTypeTrait ExprKind,
1780 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001781 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001782 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001785
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001786 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001790 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001795 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001797 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001798 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 RBracketLoc);
1800 }
1801
1802 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001803 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001806 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001808 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001809 Expr *ExecConfig = nullptr) {
1810 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001811 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 }
1813
1814 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001815 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// By default, performs semantic analysis to build the new expression.
1817 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001818 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001819 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001820 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001821 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001822 const DeclarationNameInfo &MemberNameInfo,
1823 ValueDecl *Member,
1824 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001825 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001826 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001827 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1828 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001829 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001830 // We have a reference to an unnamed field. This is always the
1831 // base of an anonymous struct/union member access, i.e. the
1832 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001833 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001834 assert(Member->getType()->isRecordType() &&
1835 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001836
Richard Smithcab9a7d2011-10-26 19:06:56 +00001837 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001838 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001839 QualifierLoc.getNestedNameSpecifier(),
1840 FoundDecl, Member);
1841 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001842 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001843 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001844 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001845 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001846 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001847 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001848 cast<FieldDecl>(Member)->getType(),
1849 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001850 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001853 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001854 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001855
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001856 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001857 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001858
John McCall16df1e52010-03-30 21:47:33 +00001859 // FIXME: this involves duplicating earlier analysis in a lot of
1860 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001861 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001862 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001863 R.resolveKind();
1864
John McCallb268a282010-08-23 23:25:46 +00001865 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001866 SS, TemplateKWLoc,
1867 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001868 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 }
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001872 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001875 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001876 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001877 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001878 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001879 }
1880
1881 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001885 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001886 SourceLocation QuestionLoc,
1887 Expr *LHS,
1888 SourceLocation ColonLoc,
1889 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001890 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1891 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
1893
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001895 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001898 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001899 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001901 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001902 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001903 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001907 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001911 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001913 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001914 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001915 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 }
Mike Stump11289f42009-09-09 15:08:12 +00001917
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001922 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 SourceLocation OpLoc,
1924 SourceLocation AccessorLoc,
1925 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001926
John McCall10eae182009-11-30 22:42:35 +00001927 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001928 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001929 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001930 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001931 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001932 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001933 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001934 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001938 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001942 MultiExprArg Inits,
1943 SourceLocation RBraceLoc,
1944 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001946 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001947 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001948 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001949
Douglas Gregord3d93062009-11-09 17:16:50 +00001950 // Patch in the result type we were given, which may have been computed
1951 // when the initial InitListExpr was built.
1952 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1953 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001954 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001958 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001961 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 MultiExprArg ArrayExprs,
1963 SourceLocation EqualOrColonLoc,
1964 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001965 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001968 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001971
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001972 return Result;
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 value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001976 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// By default, builds the implicit value initialization without performing
1978 /// any semantic analysis. Subclasses may override this routine to provide
1979 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001981 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 }
Mike Stump11289f42009-09-09 15:08:12 +00001983
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001985 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001988 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001989 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001990 SourceLocation RParenLoc) {
1991 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001992 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001993 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
1995
1996 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002000 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002001 MultiExprArg SubExprs,
2002 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002003 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 }
Mike Stump11289f42009-09-09 15:08:12 +00002005
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002007 ///
2008 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// rather than attempting to map the label statement itself.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002012 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002013 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 }
Mike Stump11289f42009-09-09 15:08:12 +00002015
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002017 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002020 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002021 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002023 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 }
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 /// \brief Build a new __builtin_choose_expr expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002030 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002031 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 SourceLocation RParenLoc) {
2033 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002034 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 RParenLoc);
2036 }
Mike Stump11289f42009-09-09 15:08:12 +00002037
Peter Collingbourne91147592011-04-15 00:35:48 +00002038 /// \brief Build a new generic selection expression.
2039 ///
2040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
2042 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2043 SourceLocation DefaultLoc,
2044 SourceLocation RParenLoc,
2045 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002046 ArrayRef<TypeSourceInfo *> Types,
2047 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002048 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002049 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002050 }
2051
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// \brief Build a new overloaded operator call expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// The semantic analysis provides the behavior of template instantiation,
2056 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002057 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 /// argument-dependent lookup, etc. Subclasses may override this routine to
2059 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002060 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002062 Expr *Callee,
2063 Expr *First,
2064 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002065
2066 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// reinterpret_cast.
2068 ///
2069 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002070 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002072 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 Stmt::StmtClass Class,
2074 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002075 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 SourceLocation RAngleLoc,
2077 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002078 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 SourceLocation RParenLoc) {
2080 switch (Class) {
2081 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002082 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002083 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002084 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002085
2086 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002087 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002088 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002089 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002090
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002092 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002093 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002094 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002096
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002098 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002099 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002100 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002103 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 /// \brief Build a new C++ static_cast expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002113 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RAngleLoc,
2115 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002116 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002118 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002119 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002120 SourceRange(LAngleLoc, RAngleLoc),
2121 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 }
2123
2124 /// \brief Build a new C++ dynamic_cast expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002130 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 SourceLocation RAngleLoc,
2132 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002133 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002135 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002136 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002137 SourceRange(LAngleLoc, RAngleLoc),
2138 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 }
2140
2141 /// \brief Build a new C++ reinterpret_cast expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002145 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002147 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 SourceLocation RAngleLoc,
2149 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002150 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002152 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002153 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002154 SourceRange(LAngleLoc, RAngleLoc),
2155 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
2157
2158 /// \brief Build a new C++ const_cast expression.
2159 ///
2160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002164 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 SourceLocation RAngleLoc,
2166 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002167 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002169 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002170 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002171 SourceRange(LAngleLoc, RAngleLoc),
2172 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 /// \brief Build a new C++ functional-style cast expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002179 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2180 SourceLocation LParenLoc,
2181 Expr *Sub,
2182 SourceLocation RParenLoc) {
2183 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002184 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 RParenLoc);
2186 }
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 /// \brief Build a new C++ typeid(type) expression.
2189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002193 SourceLocation TypeidLoc,
2194 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002196 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002197 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Francois Pichet9f4f2072010-09-08 12:20:18 +00002200
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 /// \brief Build a new C++ typeid(expr) expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002206 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002207 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002209 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002210 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002211 }
2212
Francois Pichet9f4f2072010-09-08 12:20:18 +00002213 /// \brief Build a new C++ __uuidof(type) expression.
2214 ///
2215 /// By default, performs semantic analysis to build the new expression.
2216 /// Subclasses may override this routine to provide different behavior.
2217 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2218 SourceLocation TypeidLoc,
2219 TypeSourceInfo *Operand,
2220 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002221 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002222 RParenLoc);
2223 }
2224
2225 /// \brief Build a new C++ __uuidof(expr) expression.
2226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
2229 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2230 SourceLocation TypeidLoc,
2231 Expr *Operand,
2232 SourceLocation RParenLoc) {
2233 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2234 RParenLoc);
2235 }
2236
Douglas Gregora16548e2009-08-11 05:31:07 +00002237 /// \brief Build a new C++ "this" expression.
2238 ///
2239 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002240 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002242 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002243 QualType ThisType,
2244 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002245 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002246 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
2248
2249 /// \brief Build a new C++ throw expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002253 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2254 bool IsThrownVariableInScope) {
2255 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 }
2257
2258 /// \brief Build a new C++ default-argument expression.
2259 ///
2260 /// By default, builds a new default-argument expression, which does not
2261 /// require any semantic analysis. Subclasses may override this routine to
2262 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002263 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002264 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002265 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 }
2267
Richard Smith852c9db2013-04-20 22:23:05 +00002268 /// \brief Build a new C++11 default-initialization expression.
2269 ///
2270 /// By default, builds a new default field initialization expression, which
2271 /// does not require any semantic analysis. Subclasses may override this
2272 /// routine to provide different behavior.
2273 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2274 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002275 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002276 }
2277
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// \brief Build a new C++ zero-initialization expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002282 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2283 SourceLocation LParenLoc,
2284 SourceLocation RParenLoc) {
2285 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002286 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
Mike Stump11289f42009-09-09 15:08:12 +00002288
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 /// \brief Build a new C++ "new" expression.
2290 ///
2291 /// By default, performs semantic analysis to build the new expression.
2292 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002293 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002294 bool UseGlobal,
2295 SourceLocation PlacementLParen,
2296 MultiExprArg PlacementArgs,
2297 SourceLocation PlacementRParen,
2298 SourceRange TypeIdParens,
2299 QualType AllocatedType,
2300 TypeSourceInfo *AllocatedTypeInfo,
2301 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002302 SourceRange DirectInitRange,
2303 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002304 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002306 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002308 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002309 AllocatedType,
2310 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002311 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002312 DirectInitRange,
2313 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 }
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 /// \brief Build a new C++ "delete" expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002320 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 bool IsGlobalDelete,
2322 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002323 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002325 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 }
Mike Stump11289f42009-09-09 15:08:12 +00002327
Douglas Gregor29c42f22012-02-24 07:38:34 +00002328 /// \brief Build a new type trait expression.
2329 ///
2330 /// By default, performs semantic analysis to build the new expression.
2331 /// Subclasses may override this routine to provide different behavior.
2332 ExprResult RebuildTypeTrait(TypeTrait Trait,
2333 SourceLocation StartLoc,
2334 ArrayRef<TypeSourceInfo *> Args,
2335 SourceLocation RParenLoc) {
2336 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002338
John Wiegley6242b6a2011-04-28 00:16:57 +00002339 /// \brief Build a new array type trait expression.
2340 ///
2341 /// By default, performs semantic analysis to build the new expression.
2342 /// Subclasses may override this routine to provide different behavior.
2343 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2344 SourceLocation StartLoc,
2345 TypeSourceInfo *TSInfo,
2346 Expr *DimExpr,
2347 SourceLocation RParenLoc) {
2348 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2349 }
2350
John Wiegleyf9f65842011-04-25 06:54:41 +00002351 /// \brief Build a new expression trait expression.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
2355 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2356 SourceLocation StartLoc,
2357 Expr *Queried,
2358 SourceLocation RParenLoc) {
2359 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2360 }
2361
Mike Stump11289f42009-09-09 15:08:12 +00002362 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 /// expression.
2364 ///
2365 /// By default, performs semantic analysis to build the new expression.
2366 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002367 ExprResult RebuildDependentScopeDeclRefExpr(
2368 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002369 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002370 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002371 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002372 bool IsAddressOfOperand,
2373 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002375 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002376
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002377 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002378 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2379 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002380
Reid Kleckner32506ed2014-06-12 23:03:48 +00002381 return getSema().BuildQualifiedDeclarationNameExpr(
2382 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 }
2384
2385 /// \brief Build a new template-id expression.
2386 ///
2387 /// By default, performs semantic analysis to build the new expression.
2388 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002389 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002390 SourceLocation TemplateKWLoc,
2391 LookupResult &R,
2392 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002393 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002394 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2395 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 }
2397
2398 /// \brief Build a new object-construction expression.
2399 ///
2400 /// By default, performs semantic analysis to build the new expression.
2401 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002402 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002403 SourceLocation Loc,
2404 CXXConstructorDecl *Constructor,
2405 bool IsElidable,
2406 MultiExprArg Args,
2407 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002408 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002409 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002410 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002411 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002412 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002413 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002414 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002415 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002416 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002417
Douglas Gregordb121ba2009-12-14 16:27:04 +00002418 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002419 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002420 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002421 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002422 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002423 RequiresZeroInit, ConstructKind,
2424 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 }
2426
2427 /// \brief Build a new object-construction expression.
2428 ///
2429 /// By default, performs semantic analysis to build the new expression.
2430 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002431 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2432 SourceLocation LParenLoc,
2433 MultiExprArg Args,
2434 SourceLocation RParenLoc) {
2435 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002437 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 RParenLoc);
2439 }
2440
2441 /// \brief Build a new object-construction expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002445 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2446 SourceLocation LParenLoc,
2447 MultiExprArg Args,
2448 SourceLocation RParenLoc) {
2449 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002451 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 RParenLoc);
2453 }
Mike Stump11289f42009-09-09 15:08:12 +00002454
Douglas Gregora16548e2009-08-11 05:31:07 +00002455 /// \brief Build a new member reference expression.
2456 ///
2457 /// By default, performs semantic analysis to build the new expression.
2458 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002459 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002460 QualType BaseType,
2461 bool IsArrow,
2462 SourceLocation OperatorLoc,
2463 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002464 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002465 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002466 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002467 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002468 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002469 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002470
John McCallb268a282010-08-23 23:25:46 +00002471 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002472 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002473 SS, TemplateKWLoc,
2474 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002475 MemberNameInfo,
2476 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002477 }
2478
John McCall10eae182009-11-30 22:42:35 +00002479 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002483 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2484 SourceLocation OperatorLoc,
2485 bool IsArrow,
2486 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002487 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002488 NamedDecl *FirstQualifierInScope,
2489 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002490 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002491 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002492 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002493
John McCallb268a282010-08-23 23:25:46 +00002494 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002495 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002496 SS, TemplateKWLoc,
2497 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002498 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002499 }
Mike Stump11289f42009-09-09 15:08:12 +00002500
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002501 /// \brief Build a new noexcept expression.
2502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
2505 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2506 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2507 }
2508
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002509 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002510 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2511 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002512 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002513 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002514 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002515 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2516 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002517 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002518
2519 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2520 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002521 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002522 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002523
Patrick Beard0caa3942012-04-19 00:25:12 +00002524 /// \brief Build a new Objective-C boxed expression.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
2528 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2529 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002531
Ted Kremeneke65b0862012-03-06 20:05:56 +00002532 /// \brief Build a new Objective-C array literal.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
2536 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2537 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002538 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002539 MultiExprArg(Elements, NumElements));
2540 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002541
2542 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002543 Expr *Base, Expr *Key,
2544 ObjCMethodDecl *getterMethod,
2545 ObjCMethodDecl *setterMethod) {
2546 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2547 getterMethod, setterMethod);
2548 }
2549
2550 /// \brief Build a new Objective-C dictionary literal.
2551 ///
2552 /// By default, performs semantic analysis to build the new expression.
2553 /// Subclasses may override this routine to provide different behavior.
2554 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2555 ObjCDictionaryElement *Elements,
2556 unsigned NumElements) {
2557 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002559
James Dennett2a4d13c2012-06-15 07:13:21 +00002560 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 ///
2562 /// By default, performs semantic analysis to build the new expression.
2563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002564 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002565 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002566 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002567 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002568 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002569
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002570 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002571 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002572 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002573 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002574 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002575 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002576 MultiExprArg Args,
2577 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002578 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2579 ReceiverTypeInfo->getType(),
2580 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002581 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002582 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002583 }
2584
2585 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002586 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002587 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002588 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002589 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002590 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002591 MultiExprArg Args,
2592 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002593 return SemaRef.BuildInstanceMessage(Receiver,
2594 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002595 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002596 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002597 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002598 }
2599
Douglas Gregord51d90d2010-04-26 20:11:03 +00002600 /// \brief Build a new Objective-C ivar reference expression.
2601 ///
2602 /// By default, performs semantic analysis to build the new expression.
2603 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002604 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002605 SourceLocation IvarLoc,
2606 bool IsArrow, bool IsFreeIvar) {
2607 // FIXME: We lose track of the IsFreeIvar bit.
2608 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002609 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2610 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002611 /*FIXME:*/IvarLoc, IsArrow,
2612 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002613 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002614 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002615 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002616 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002617
2618 /// \brief Build a new Objective-C property reference expression.
2619 ///
2620 /// By default, performs semantic analysis to build the new expression.
2621 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002622 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002623 ObjCPropertyDecl *Property,
2624 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002625 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002626 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2627 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2628 /*FIXME:*/PropertyLoc,
2629 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002630 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002631 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002632 NameInfo,
2633 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002635
John McCallb7bd14f2010-12-02 01:19:52 +00002636 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002637 ///
2638 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002639 /// Subclasses may override this routine to provide different behavior.
2640 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2641 ObjCMethodDecl *Getter,
2642 ObjCMethodDecl *Setter,
2643 SourceLocation PropertyLoc) {
2644 // Since these expressions can only be value-dependent, we do not
2645 // need to perform semantic analysis again.
2646 return Owned(
2647 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2648 VK_LValue, OK_ObjCProperty,
2649 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002650 }
2651
Douglas Gregord51d90d2010-04-26 20:11:03 +00002652 /// \brief Build a new Objective-C "isa" expression.
2653 ///
2654 /// By default, performs semantic analysis to build the new expression.
2655 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002656 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002657 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002658 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002659 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2660 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002661 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002662 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002663 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002664 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002665 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002667
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 /// \brief Build a new shuffle vector expression.
2669 ///
2670 /// By default, performs semantic analysis to build the new expression.
2671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002672 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002673 MultiExprArg SubExprs,
2674 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002676 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002677 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2678 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2679 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002680 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002681
Douglas Gregora16548e2009-08-11 05:31:07 +00002682 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002683 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002684 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2685 SemaRef.Context.BuiltinFnTy,
2686 VK_RValue, BuiltinLoc);
2687 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2688 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002689 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002690
2691 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002692 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002693 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002694 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002695
Douglas Gregora16548e2009-08-11 05:31:07 +00002696 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002697 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002698 }
John McCall31f82722010-11-12 08:19:04 +00002699
Hal Finkelc4d7c822013-09-18 03:29:45 +00002700 /// \brief Build a new convert vector expression.
2701 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2702 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2703 SourceLocation RParenLoc) {
2704 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2705 BuiltinLoc, RParenLoc);
2706 }
2707
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002708 /// \brief Build a new template argument pack expansion.
2709 ///
2710 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002711 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002712 /// different behavior.
2713 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002714 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002715 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002716 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002717 case TemplateArgument::Expression: {
2718 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002719 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2720 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002721 if (Result.isInvalid())
2722 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002723
Douglas Gregor98318c22011-01-03 21:37:45 +00002724 return TemplateArgumentLoc(Result.get(), Result.get());
2725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002726
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002727 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002728 return TemplateArgumentLoc(TemplateArgument(
2729 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002730 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002731 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002732 Pattern.getTemplateNameLoc(),
2733 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002734
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002735 case TemplateArgument::Null:
2736 case TemplateArgument::Integral:
2737 case TemplateArgument::Declaration:
2738 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002739 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002740 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002741 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002742
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002743 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002744 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002745 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002746 EllipsisLoc,
2747 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002748 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2749 Expansion);
2750 break;
2751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002752
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002753 return TemplateArgumentLoc();
2754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002755
Douglas Gregor968f23a2011-01-03 19:31:53 +00002756 /// \brief Build a new expression pack expansion.
2757 ///
2758 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002759 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002760 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002761 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002762 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002763 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002764 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002765
2766 /// \brief Build a new atomic operation expression.
2767 ///
2768 /// By default, performs semantic analysis to build the new expression.
2769 /// Subclasses may override this routine to provide different behavior.
2770 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2771 MultiExprArg SubExprs,
2772 QualType RetTy,
2773 AtomicExpr::AtomicOp Op,
2774 SourceLocation RParenLoc) {
2775 // Just create the expression; there is not any interesting semantic
2776 // analysis here because we can't actually build an AtomicExpr until
2777 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002778 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002779 RParenLoc);
2780 }
2781
John McCall31f82722010-11-12 08:19:04 +00002782private:
Douglas Gregor14454802011-02-25 02:25:35 +00002783 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2784 QualType ObjectType,
2785 NamedDecl *FirstQualifierInScope,
2786 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002787
2788 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2789 QualType ObjectType,
2790 NamedDecl *FirstQualifierInScope,
2791 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002792
2793 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2794 NamedDecl *FirstQualifierInScope,
2795 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002796};
Douglas Gregora16548e2009-08-11 05:31:07 +00002797
Douglas Gregorebe10102009-08-20 07:17:43 +00002798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002799StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002800 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002801 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002802
Douglas Gregorebe10102009-08-20 07:17:43 +00002803 switch (S->getStmtClass()) {
2804 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002805
Douglas Gregorebe10102009-08-20 07:17:43 +00002806 // Transform individual statement nodes
2807#define STMT(Node, Parent) \
2808 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002809#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002810#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002811#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002812
Douglas Gregorebe10102009-08-20 07:17:43 +00002813 // Transform expressions by calling TransformExpr.
2814#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002815#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002816#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002817#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002818 {
John McCalldadc5752010-08-24 06:29:42 +00002819 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002820 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002821 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002822
Richard Smith945f8d32013-01-14 22:39:08 +00002823 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002824 }
Mike Stump11289f42009-09-09 15:08:12 +00002825 }
2826
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002827 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002828}
Mike Stump11289f42009-09-09 15:08:12 +00002829
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002830template<typename Derived>
2831OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2832 if (!S)
2833 return S;
2834
2835 switch (S->getClauseKind()) {
2836 default: break;
2837 // Transform individual clause nodes
2838#define OPENMP_CLAUSE(Name, Class) \
2839 case OMPC_ ## Name : \
2840 return getDerived().Transform ## Class(cast<Class>(S));
2841#include "clang/Basic/OpenMPKinds.def"
2842 }
2843
2844 return S;
2845}
2846
Mike Stump11289f42009-09-09 15:08:12 +00002847
Douglas Gregore922c772009-08-04 22:27:00 +00002848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002849ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002850 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002851 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002852
2853 switch (E->getStmtClass()) {
2854 case Stmt::NoStmtClass: break;
2855#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002856#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002857#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002858 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002859#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002860 }
2861
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002862 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002863}
2864
2865template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002866ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002867 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002868 // Initializers are instantiated like expressions, except that various outer
2869 // layers are stripped.
2870 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002871 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002872
2873 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2874 Init = ExprTemp->getSubExpr();
2875
Richard Smithe6ca4752013-05-30 22:40:16 +00002876 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2877 Init = MTE->GetTemporaryExpr();
2878
Richard Smithd59b8322012-12-19 01:39:02 +00002879 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2880 Init = Binder->getSubExpr();
2881
2882 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2883 Init = ICE->getSubExprAsWritten();
2884
Richard Smithcc1b96d2013-06-12 22:31:48 +00002885 if (CXXStdInitializerListExpr *ILE =
2886 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002887 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002888
Richard Smithc6abd962014-07-25 01:12:44 +00002889 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002890 // InitListExprs. Other forms of copy-initialization will be a no-op if
2891 // the initializer is already the right type.
2892 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002893 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002894 return getDerived().TransformExpr(Init);
2895
2896 // Revert value-initialization back to empty parens.
2897 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2898 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002899 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002900 Parens.getEnd());
2901 }
2902
2903 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2904 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002905 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002906 SourceLocation());
2907
2908 // Revert initialization by constructor back to a parenthesized or braced list
2909 // of expressions. Any other form of initializer can just be reused directly.
2910 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002911 return getDerived().TransformExpr(Init);
2912
Richard Smithf8adcdc2014-07-17 05:12:35 +00002913 // If the initialization implicitly converted an initializer list to a
2914 // std::initializer_list object, unwrap the std::initializer_list too.
2915 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002916 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002917
Richard Smithd59b8322012-12-19 01:39:02 +00002918 SmallVector<Expr*, 8> NewArgs;
2919 bool ArgChanged = false;
2920 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002921 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002922 return ExprError();
2923
2924 // If this was list initialization, revert to list form.
2925 if (Construct->isListInitialization())
2926 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2927 Construct->getLocEnd(),
2928 Construct->getType());
2929
Richard Smithd59b8322012-12-19 01:39:02 +00002930 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002931 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002932 if (Parens.isInvalid()) {
2933 // This was a variable declaration's initialization for which no initializer
2934 // was specified.
2935 assert(NewArgs.empty() &&
2936 "no parens or braces but have direct init with arguments?");
2937 return ExprEmpty();
2938 }
Richard Smithd59b8322012-12-19 01:39:02 +00002939 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2940 Parens.getEnd());
2941}
2942
2943template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002944bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2945 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002946 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002947 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002948 bool *ArgChanged) {
2949 for (unsigned I = 0; I != NumInputs; ++I) {
2950 // If requested, drop call arguments that need to be dropped.
2951 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2952 if (ArgChanged)
2953 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Douglas Gregora3efea12011-01-03 19:04:46 +00002955 break;
2956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002957
Douglas Gregor968f23a2011-01-03 19:31:53 +00002958 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2959 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
Chris Lattner01cf8db2011-07-20 06:58:45 +00002961 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002962 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2963 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002964
Douglas Gregor968f23a2011-01-03 19:31:53 +00002965 // Determine whether the set of unexpanded parameter packs can and should
2966 // be expanded.
2967 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002968 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002969 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2970 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002971 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2972 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002973 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002974 Expand, RetainExpansion,
2975 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002976 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
Douglas Gregor968f23a2011-01-03 19:31:53 +00002978 if (!Expand) {
2979 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002980 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002981 // expansion.
2982 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2983 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2984 if (OutPattern.isInvalid())
2985 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002986
2987 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002988 Expansion->getEllipsisLoc(),
2989 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002990 if (Out.isInvalid())
2991 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002992
Douglas Gregor968f23a2011-01-03 19:31:53 +00002993 if (ArgChanged)
2994 *ArgChanged = true;
2995 Outputs.push_back(Out.get());
2996 continue;
2997 }
John McCall542e7c62011-07-06 07:30:07 +00002998
2999 // Record right away that the argument was changed. This needs
3000 // to happen even if the array expands to nothing.
3001 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003002
Douglas Gregor968f23a2011-01-03 19:31:53 +00003003 // The transform has determined that we should perform an elementwise
3004 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003005 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003006 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3007 ExprResult Out = getDerived().TransformExpr(Pattern);
3008 if (Out.isInvalid())
3009 return true;
3010
Richard Smith9467be42014-06-06 17:33:35 +00003011 // FIXME: Can this happen? We should not try to expand the pack
3012 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003013 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003014 Out = getDerived().RebuildPackExpansion(
3015 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003016 if (Out.isInvalid())
3017 return true;
3018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003019
Douglas Gregor968f23a2011-01-03 19:31:53 +00003020 Outputs.push_back(Out.get());
3021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003022
Richard Smith9467be42014-06-06 17:33:35 +00003023 // If we're supposed to retain a pack expansion, do so by temporarily
3024 // forgetting the partially-substituted parameter pack.
3025 if (RetainExpansion) {
3026 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3027
3028 ExprResult Out = getDerived().TransformExpr(Pattern);
3029 if (Out.isInvalid())
3030 return true;
3031
3032 Out = getDerived().RebuildPackExpansion(
3033 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3034 if (Out.isInvalid())
3035 return true;
3036
3037 Outputs.push_back(Out.get());
3038 }
3039
Douglas Gregor968f23a2011-01-03 19:31:53 +00003040 continue;
3041 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
Richard Smithd59b8322012-12-19 01:39:02 +00003043 ExprResult Result =
3044 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3045 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003046 if (Result.isInvalid())
3047 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003048
Douglas Gregora3efea12011-01-03 19:04:46 +00003049 if (Result.get() != Inputs[I] && ArgChanged)
3050 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003051
3052 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003053 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003054
Douglas Gregora3efea12011-01-03 19:04:46 +00003055 return false;
3056}
3057
3058template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003059NestedNameSpecifierLoc
3060TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3061 NestedNameSpecifierLoc NNS,
3062 QualType ObjectType,
3063 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003064 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003065 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003066 Qualifier = Qualifier.getPrefix())
3067 Qualifiers.push_back(Qualifier);
3068
3069 CXXScopeSpec SS;
3070 while (!Qualifiers.empty()) {
3071 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3072 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor14454802011-02-25 02:25:35 +00003074 switch (QNNS->getKind()) {
3075 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003076 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003077 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003078 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003079 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003080 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003081 FirstQualifierInScope, false))
3082 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003083
Douglas Gregor14454802011-02-25 02:25:35 +00003084 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregor14454802011-02-25 02:25:35 +00003086 case NestedNameSpecifier::Namespace: {
3087 NamespaceDecl *NS
3088 = cast_or_null<NamespaceDecl>(
3089 getDerived().TransformDecl(
3090 Q.getLocalBeginLoc(),
3091 QNNS->getAsNamespace()));
3092 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3093 break;
3094 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003095
Douglas Gregor14454802011-02-25 02:25:35 +00003096 case NestedNameSpecifier::NamespaceAlias: {
3097 NamespaceAliasDecl *Alias
3098 = cast_or_null<NamespaceAliasDecl>(
3099 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3100 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003101 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003102 Q.getLocalEndLoc());
3103 break;
3104 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003105
Douglas Gregor14454802011-02-25 02:25:35 +00003106 case NestedNameSpecifier::Global:
3107 // There is no meaningful transformation that one could perform on the
3108 // global scope.
3109 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3110 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Nikola Smiljanic67860242014-09-26 00:28:20 +00003112 case NestedNameSpecifier::Super: {
3113 CXXRecordDecl *RD =
3114 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3115 SourceLocation(), QNNS->getAsRecordDecl()));
3116 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3117 break;
3118 }
3119
Douglas Gregor14454802011-02-25 02:25:35 +00003120 case NestedNameSpecifier::TypeSpecWithTemplate:
3121 case NestedNameSpecifier::TypeSpec: {
3122 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3123 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregor14454802011-02-25 02:25:35 +00003125 if (!TL)
3126 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
Douglas Gregor14454802011-02-25 02:25:35 +00003128 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003129 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003130 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003131 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003132 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003133 if (TL.getType()->isEnumeralType())
3134 SemaRef.Diag(TL.getBeginLoc(),
3135 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003136 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3137 Q.getLocalEndLoc());
3138 break;
3139 }
Richard Trieude756fb2011-05-07 01:36:37 +00003140 // If the nested-name-specifier is an invalid type def, don't emit an
3141 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003142 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3143 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003144 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003145 << TL.getType() << SS.getRange();
3146 }
Douglas Gregor14454802011-02-25 02:25:35 +00003147 return NestedNameSpecifierLoc();
3148 }
Douglas Gregore16af532011-02-28 18:50:33 +00003149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregore16af532011-02-28 18:50:33 +00003151 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003152 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003153 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003154 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003155
Douglas Gregor14454802011-02-25 02:25:35 +00003156 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003157 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003158 !getDerived().AlwaysRebuild())
3159 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003160
3161 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003162 // nested-name-specifier, do so.
3163 if (SS.location_size() == NNS.getDataLength() &&
3164 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3165 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3166
3167 // Allocate new nested-name-specifier location information.
3168 return SS.getWithLocInContext(SemaRef.Context);
3169}
3170
3171template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003172DeclarationNameInfo
3173TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003174::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003175 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003176 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003177 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003178
3179 switch (Name.getNameKind()) {
3180 case DeclarationName::Identifier:
3181 case DeclarationName::ObjCZeroArgSelector:
3182 case DeclarationName::ObjCOneArgSelector:
3183 case DeclarationName::ObjCMultiArgSelector:
3184 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003185 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003186 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003187 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003188
Douglas Gregorf816bd72009-09-03 22:13:48 +00003189 case DeclarationName::CXXConstructorName:
3190 case DeclarationName::CXXDestructorName:
3191 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003192 TypeSourceInfo *NewTInfo;
3193 CanQualType NewCanTy;
3194 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003195 NewTInfo = getDerived().TransformType(OldTInfo);
3196 if (!NewTInfo)
3197 return DeclarationNameInfo();
3198 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003199 }
3200 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003201 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003202 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003203 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003204 if (NewT.isNull())
3205 return DeclarationNameInfo();
3206 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3207 }
Mike Stump11289f42009-09-09 15:08:12 +00003208
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003209 DeclarationName NewName
3210 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3211 NewCanTy);
3212 DeclarationNameInfo NewNameInfo(NameInfo);
3213 NewNameInfo.setName(NewName);
3214 NewNameInfo.setNamedTypeInfo(NewTInfo);
3215 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003216 }
Mike Stump11289f42009-09-09 15:08:12 +00003217 }
3218
David Blaikie83d382b2011-09-23 05:06:16 +00003219 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003220}
3221
3222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003223TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003224TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3225 TemplateName Name,
3226 SourceLocation NameLoc,
3227 QualType ObjectType,
3228 NamedDecl *FirstQualifierInScope) {
3229 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3230 TemplateDecl *Template = QTN->getTemplateDecl();
3231 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Douglas Gregor9db53502011-03-02 18:07:45 +00003233 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003234 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003235 Template));
3236 if (!TransTemplate)
3237 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003238
Douglas Gregor9db53502011-03-02 18:07:45 +00003239 if (!getDerived().AlwaysRebuild() &&
3240 SS.getScopeRep() == QTN->getQualifier() &&
3241 TransTemplate == Template)
3242 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003243
Douglas Gregor9db53502011-03-02 18:07:45 +00003244 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3245 TransTemplate);
3246 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003247
Douglas Gregor9db53502011-03-02 18:07:45 +00003248 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3249 if (SS.getScopeRep()) {
3250 // These apply to the scope specifier, not the template.
3251 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003252 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003253 }
3254
Douglas Gregor9db53502011-03-02 18:07:45 +00003255 if (!getDerived().AlwaysRebuild() &&
3256 SS.getScopeRep() == DTN->getQualifier() &&
3257 ObjectType.isNull())
3258 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor9db53502011-03-02 18:07:45 +00003260 if (DTN->isIdentifier()) {
3261 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003262 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003263 NameLoc,
3264 ObjectType,
3265 FirstQualifierInScope);
3266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003267
Douglas Gregor9db53502011-03-02 18:07:45 +00003268 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3269 ObjectType);
3270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregor9db53502011-03-02 18:07:45 +00003272 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3273 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003274 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003275 Template));
3276 if (!TransTemplate)
3277 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003278
Douglas Gregor9db53502011-03-02 18:07:45 +00003279 if (!getDerived().AlwaysRebuild() &&
3280 TransTemplate == Template)
3281 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregor9db53502011-03-02 18:07:45 +00003283 return TemplateName(TransTemplate);
3284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregor9db53502011-03-02 18:07:45 +00003286 if (SubstTemplateTemplateParmPackStorage *SubstPack
3287 = Name.getAsSubstTemplateTemplateParmPack()) {
3288 TemplateTemplateParmDecl *TransParam
3289 = cast_or_null<TemplateTemplateParmDecl>(
3290 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3291 if (!TransParam)
3292 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003293
Douglas Gregor9db53502011-03-02 18:07:45 +00003294 if (!getDerived().AlwaysRebuild() &&
3295 TransParam == SubstPack->getParameterPack())
3296 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
3298 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003299 SubstPack->getArgumentPack());
3300 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
Douglas Gregor9db53502011-03-02 18:07:45 +00003302 // These should be getting filtered out before they reach the AST.
3303 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003304}
3305
3306template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003307void TreeTransform<Derived>::InventTemplateArgumentLoc(
3308 const TemplateArgument &Arg,
3309 TemplateArgumentLoc &Output) {
3310 SourceLocation Loc = getDerived().getBaseLocation();
3311 switch (Arg.getKind()) {
3312 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003313 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003314 break;
3315
3316 case TemplateArgument::Type:
3317 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003318 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003319
John McCall0ad16662009-10-29 08:12:44 +00003320 break;
3321
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003322 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003323 case TemplateArgument::TemplateExpansion: {
3324 NestedNameSpecifierLocBuilder Builder;
3325 TemplateName Template = Arg.getAsTemplate();
3326 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3327 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3328 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3329 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Douglas Gregor9d802122011-03-02 17:09:35 +00003331 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003332 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003333 Builder.getWithLocInContext(SemaRef.Context),
3334 Loc);
3335 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003336 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003337 Builder.getWithLocInContext(SemaRef.Context),
3338 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003340 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003341 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003342
John McCall0ad16662009-10-29 08:12:44 +00003343 case TemplateArgument::Expression:
3344 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3345 break;
3346
3347 case TemplateArgument::Declaration:
3348 case TemplateArgument::Integral:
3349 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003350 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003351 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003352 break;
3353 }
3354}
3355
3356template<typename Derived>
3357bool TreeTransform<Derived>::TransformTemplateArgument(
3358 const TemplateArgumentLoc &Input,
3359 TemplateArgumentLoc &Output) {
3360 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003361 switch (Arg.getKind()) {
3362 case TemplateArgument::Null:
3363 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003364 case TemplateArgument::Pack:
3365 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003366 case TemplateArgument::NullPtr:
3367 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregore922c772009-08-04 22:27:00 +00003369 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003370 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003371 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003372 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003373
3374 DI = getDerived().TransformType(DI);
3375 if (!DI) return true;
3376
3377 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3378 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003379 }
Mike Stump11289f42009-09-09 15:08:12 +00003380
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003381 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003382 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3383 if (QualifierLoc) {
3384 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3385 if (!QualifierLoc)
3386 return true;
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregordf846d12011-03-02 18:46:51 +00003389 CXXScopeSpec SS;
3390 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003391 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003392 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3393 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003394 if (Template.isNull())
3395 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
Douglas Gregor9d802122011-03-02 17:09:35 +00003397 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003398 Input.getTemplateNameLoc());
3399 return false;
3400 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003401
3402 case TemplateArgument::TemplateExpansion:
3403 llvm_unreachable("Caller should expand pack expansions");
3404
Douglas Gregore922c772009-08-04 22:27:00 +00003405 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003406 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003407 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003408 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003409
John McCall0ad16662009-10-29 08:12:44 +00003410 Expr *InputExpr = Input.getSourceExpression();
3411 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3412
Chris Lattnercdb591a2011-04-25 20:37:58 +00003413 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003414 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003415 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003416 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003417 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003418 }
Douglas Gregore922c772009-08-04 22:27:00 +00003419 }
Mike Stump11289f42009-09-09 15:08:12 +00003420
Douglas Gregore922c772009-08-04 22:27:00 +00003421 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003422 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003423}
3424
Douglas Gregorfe921a72010-12-20 23:36:19 +00003425/// \brief Iterator adaptor that invents template argument location information
3426/// for each of the template arguments in its underlying iterator.
3427template<typename Derived, typename InputIterator>
3428class TemplateArgumentLocInventIterator {
3429 TreeTransform<Derived> &Self;
3430 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
Douglas Gregorfe921a72010-12-20 23:36:19 +00003432public:
3433 typedef TemplateArgumentLoc value_type;
3434 typedef TemplateArgumentLoc reference;
3435 typedef typename std::iterator_traits<InputIterator>::difference_type
3436 difference_type;
3437 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregorfe921a72010-12-20 23:36:19 +00003439 class pointer {
3440 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregorfe921a72010-12-20 23:36:19 +00003442 public:
3443 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregorfe921a72010-12-20 23:36:19 +00003445 const TemplateArgumentLoc *operator->() const { return &Arg; }
3446 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregorfe921a72010-12-20 23:36:19 +00003448 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregorfe921a72010-12-20 23:36:19 +00003450 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3451 InputIterator Iter)
3452 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregorfe921a72010-12-20 23:36:19 +00003454 TemplateArgumentLocInventIterator &operator++() {
3455 ++Iter;
3456 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003458
Douglas Gregorfe921a72010-12-20 23:36:19 +00003459 TemplateArgumentLocInventIterator operator++(int) {
3460 TemplateArgumentLocInventIterator Old(*this);
3461 ++(*this);
3462 return Old;
3463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregorfe921a72010-12-20 23:36:19 +00003465 reference operator*() const {
3466 TemplateArgumentLoc Result;
3467 Self.InventTemplateArgumentLoc(*Iter, Result);
3468 return Result;
3469 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003470
Douglas Gregorfe921a72010-12-20 23:36:19 +00003471 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregorfe921a72010-12-20 23:36:19 +00003473 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3474 const TemplateArgumentLocInventIterator &Y) {
3475 return X.Iter == Y.Iter;
3476 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003477
Douglas Gregorfe921a72010-12-20 23:36:19 +00003478 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3479 const TemplateArgumentLocInventIterator &Y) {
3480 return X.Iter != Y.Iter;
3481 }
3482};
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregor42cafa82010-12-20 17:42:22 +00003484template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003485template<typename InputIterator>
3486bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3487 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003488 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003489 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003490 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003491 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003492
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003493 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3494 // Unpack argument packs, which we translate them into separate
3495 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003496 // FIXME: We could do much better if we could guarantee that the
3497 // TemplateArgumentLocInfo for the pack expansion would be usable for
3498 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003499 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003500 TemplateArgument::pack_iterator>
3501 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003502 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003503 In.getArgument().pack_begin()),
3504 PackLocIterator(*this,
3505 In.getArgument().pack_end()),
3506 Outputs))
3507 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003509 continue;
3510 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003512 if (In.getArgument().isPackExpansion()) {
3513 // We have a pack expansion, for which we will be substituting into
3514 // the pattern.
3515 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003516 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003517 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003518 = getSema().getTemplateArgumentPackExpansionPattern(
3519 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Chris Lattner01cf8db2011-07-20 06:58:45 +00003521 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003522 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3523 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003525 // Determine whether the set of unexpanded parameter packs can and should
3526 // be expanded.
3527 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003528 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003529 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003530 if (getDerived().TryExpandParameterPacks(Ellipsis,
3531 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003532 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003533 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003534 RetainExpansion,
3535 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003536 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003538 if (!Expand) {
3539 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003540 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003541 // expansion.
3542 TemplateArgumentLoc OutPattern;
3543 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3544 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3545 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003546
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003547 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3548 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003549 if (Out.getArgument().isNull())
3550 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003552 Outputs.addArgument(Out);
3553 continue;
3554 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003556 // The transform has determined that we should perform an elementwise
3557 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003558 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003559 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3560
3561 if (getDerived().TransformTemplateArgument(Pattern, Out))
3562 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003563
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003564 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003565 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3566 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003567 if (Out.getArgument().isNull())
3568 return true;
3569 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003570
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003571 Outputs.addArgument(Out);
3572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor48d24112011-01-10 20:53:55 +00003574 // If we're supposed to retain a pack expansion, do so by temporarily
3575 // forgetting the partially-substituted parameter pack.
3576 if (RetainExpansion) {
3577 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Douglas Gregor48d24112011-01-10 20:53:55 +00003579 if (getDerived().TransformTemplateArgument(Pattern, Out))
3580 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003581
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003582 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3583 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003584 if (Out.getArgument().isNull())
3585 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003586
Douglas Gregor48d24112011-01-10 20:53:55 +00003587 Outputs.addArgument(Out);
3588 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003590 continue;
3591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
3593 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003594 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003595 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregor42cafa82010-12-20 17:42:22 +00003597 Outputs.addArgument(Out);
3598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregor42cafa82010-12-20 17:42:22 +00003600 return false;
3601
3602}
3603
Douglas Gregord6ff3322009-08-04 16:50:30 +00003604//===----------------------------------------------------------------------===//
3605// Type transformation
3606//===----------------------------------------------------------------------===//
3607
3608template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003609QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003610 if (getDerived().AlreadyTransformed(T))
3611 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003612
John McCall550e0c22009-10-21 00:40:46 +00003613 // Temporary workaround. All of these transformations should
3614 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003615 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3616 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003617
John McCall31f82722010-11-12 08:19:04 +00003618 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003619
John McCall550e0c22009-10-21 00:40:46 +00003620 if (!NewDI)
3621 return QualType();
3622
3623 return NewDI->getType();
3624}
3625
3626template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003627TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003628 // Refine the base location to the type's location.
3629 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3630 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003631 if (getDerived().AlreadyTransformed(DI->getType()))
3632 return DI;
3633
3634 TypeLocBuilder TLB;
3635
3636 TypeLoc TL = DI->getTypeLoc();
3637 TLB.reserve(TL.getFullDataSize());
3638
John McCall31f82722010-11-12 08:19:04 +00003639 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003640 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003641 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003642
John McCallbcd03502009-12-07 02:54:59 +00003643 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003644}
3645
3646template<typename Derived>
3647QualType
John McCall31f82722010-11-12 08:19:04 +00003648TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003649 switch (T.getTypeLocClass()) {
3650#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003651#define TYPELOC(CLASS, PARENT) \
3652 case TypeLoc::CLASS: \
3653 return getDerived().Transform##CLASS##Type(TLB, \
3654 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003655#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003656 }
Mike Stump11289f42009-09-09 15:08:12 +00003657
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003658 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003659}
3660
3661/// FIXME: By default, this routine adds type qualifiers only to types
3662/// that can have qualifiers, and silently suppresses those qualifiers
3663/// that are not permitted (e.g., qualifiers on reference or function
3664/// types). This is the right thing for template instantiation, but
3665/// probably not for other clients.
3666template<typename Derived>
3667QualType
3668TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003669 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003670 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003671
John McCall31f82722010-11-12 08:19:04 +00003672 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003673 if (Result.isNull())
3674 return QualType();
3675
3676 // Silently suppress qualifiers if the result type can't be qualified.
3677 // FIXME: this is the right thing for template instantiation, but
3678 // probably not for other clients.
3679 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003681
John McCall31168b02011-06-15 23:02:42 +00003682 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003683 // resulting type.
3684 if (Quals.hasObjCLifetime()) {
3685 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3686 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003687 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003688 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003689 // A lifetime qualifier applied to a substituted template parameter
3690 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003691 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003692 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003693 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3694 QualType Replacement = SubstTypeParam->getReplacementType();
3695 Qualifiers Qs = Replacement.getQualifiers();
3696 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003697 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003698 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3699 Qs);
3700 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003701 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003702 Replacement);
3703 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003704 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3705 // 'auto' types behave the same way as template parameters.
3706 QualType Deduced = AutoTy->getDeducedType();
3707 Qualifiers Qs = Deduced.getQualifiers();
3708 Qs.removeObjCLifetime();
3709 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3710 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003711 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3712 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003713 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003714 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003715 // Otherwise, complain about the addition of a qualifier to an
3716 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003717 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003718 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003719 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregore46db902011-06-17 22:11:49 +00003721 Quals.removeObjCLifetime();
3722 }
3723 }
3724 }
John McCallcb0f89a2010-06-05 06:41:15 +00003725 if (!Quals.empty()) {
3726 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003727 // BuildQualifiedType might not add qualifiers if they are invalid.
3728 if (Result.hasLocalQualifiers())
3729 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003730 // No location information to preserve.
3731 }
John McCall550e0c22009-10-21 00:40:46 +00003732
3733 return Result;
3734}
3735
Douglas Gregor14454802011-02-25 02:25:35 +00003736template<typename Derived>
3737TypeLoc
3738TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3739 QualType ObjectType,
3740 NamedDecl *UnqualLookup,
3741 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003742 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003743 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003744
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003745 TypeSourceInfo *TSI =
3746 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3747 if (TSI)
3748 return TSI->getTypeLoc();
3749 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003750}
3751
Douglas Gregor579c15f2011-03-02 18:32:08 +00003752template<typename Derived>
3753TypeSourceInfo *
3754TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3755 QualType ObjectType,
3756 NamedDecl *UnqualLookup,
3757 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003758 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003759 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003761 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3762 UnqualLookup, SS);
3763}
3764
3765template <typename Derived>
3766TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3767 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3768 CXXScopeSpec &SS) {
3769 QualType T = TL.getType();
3770 assert(!getDerived().AlreadyTransformed(T));
3771
Douglas Gregor579c15f2011-03-02 18:32:08 +00003772 TypeLocBuilder TLB;
3773 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregor579c15f2011-03-02 18:32:08 +00003775 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003776 TemplateSpecializationTypeLoc SpecTL =
3777 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003778
Douglas Gregor579c15f2011-03-02 18:32:08 +00003779 TemplateName Template
3780 = getDerived().TransformTemplateName(SS,
3781 SpecTL.getTypePtr()->getTemplateName(),
3782 SpecTL.getTemplateNameLoc(),
3783 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003784 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003785 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
3787 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003788 Template);
3789 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003790 DependentTemplateSpecializationTypeLoc SpecTL =
3791 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003792
Douglas Gregor579c15f2011-03-02 18:32:08 +00003793 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003794 = getDerived().RebuildTemplateName(SS,
3795 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003796 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003797 ObjectType, UnqualLookup);
3798 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003799 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003800
3801 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003802 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003803 Template,
3804 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003805 } else {
3806 // Nothing special needs to be done for these.
3807 Result = getDerived().TransformType(TLB, TL);
3808 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003809
3810 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003811 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003812
Douglas Gregor579c15f2011-03-02 18:32:08 +00003813 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3814}
3815
John McCall550e0c22009-10-21 00:40:46 +00003816template <class TyLoc> static inline
3817QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3818 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3819 NewT.setNameLoc(T.getNameLoc());
3820 return T.getType();
3821}
3822
John McCall550e0c22009-10-21 00:40:46 +00003823template<typename Derived>
3824QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003825 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003826 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3827 NewT.setBuiltinLoc(T.getBuiltinLoc());
3828 if (T.needsExtraLocalData())
3829 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3830 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003831}
Mike Stump11289f42009-09-09 15:08:12 +00003832
Douglas Gregord6ff3322009-08-04 16:50:30 +00003833template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003834QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003835 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003836 // FIXME: recurse?
3837 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003838}
Mike Stump11289f42009-09-09 15:08:12 +00003839
Reid Kleckner0503a872013-12-05 01:23:43 +00003840template <typename Derived>
3841QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3842 AdjustedTypeLoc TL) {
3843 // Adjustments applied during transformation are handled elsewhere.
3844 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3845}
3846
Douglas Gregord6ff3322009-08-04 16:50:30 +00003847template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003848QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3849 DecayedTypeLoc TL) {
3850 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3851 if (OriginalType.isNull())
3852 return QualType();
3853
3854 QualType Result = TL.getType();
3855 if (getDerived().AlwaysRebuild() ||
3856 OriginalType != TL.getOriginalLoc().getType())
3857 Result = SemaRef.Context.getDecayedType(OriginalType);
3858 TLB.push<DecayedTypeLoc>(Result);
3859 // Nothing to set for DecayedTypeLoc.
3860 return Result;
3861}
3862
3863template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003864QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003865 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003866 QualType PointeeType
3867 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003868 if (PointeeType.isNull())
3869 return QualType();
3870
3871 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003872 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003873 // A dependent pointer type 'T *' has is being transformed such
3874 // that an Objective-C class type is being replaced for 'T'. The
3875 // resulting pointer type is an ObjCObjectPointerType, not a
3876 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003877 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003878
John McCall8b07ec22010-05-15 11:32:37 +00003879 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3880 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003881 return Result;
3882 }
John McCall31f82722010-11-12 08:19:04 +00003883
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003884 if (getDerived().AlwaysRebuild() ||
3885 PointeeType != TL.getPointeeLoc().getType()) {
3886 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3887 if (Result.isNull())
3888 return QualType();
3889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003890
John McCall31168b02011-06-15 23:02:42 +00003891 // Objective-C ARC can add lifetime qualifiers to the type that we're
3892 // pointing to.
3893 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003894
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003895 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3896 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003897 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003898}
Mike Stump11289f42009-09-09 15:08:12 +00003899
3900template<typename Derived>
3901QualType
John McCall550e0c22009-10-21 00:40:46 +00003902TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003903 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003904 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003905 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3906 if (PointeeType.isNull())
3907 return QualType();
3908
3909 QualType Result = TL.getType();
3910 if (getDerived().AlwaysRebuild() ||
3911 PointeeType != TL.getPointeeLoc().getType()) {
3912 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003913 TL.getSigilLoc());
3914 if (Result.isNull())
3915 return QualType();
3916 }
3917
Douglas Gregor049211a2010-04-22 16:50:51 +00003918 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003919 NewT.setSigilLoc(TL.getSigilLoc());
3920 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003921}
3922
John McCall70dd5f62009-10-30 00:06:24 +00003923/// Transforms a reference type. Note that somewhat paradoxically we
3924/// don't care whether the type itself is an l-value type or an r-value
3925/// type; we only care if the type was *written* as an l-value type
3926/// or an r-value type.
3927template<typename Derived>
3928QualType
3929TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003930 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003931 const ReferenceType *T = TL.getTypePtr();
3932
3933 // Note that this works with the pointee-as-written.
3934 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3935 if (PointeeType.isNull())
3936 return QualType();
3937
3938 QualType Result = TL.getType();
3939 if (getDerived().AlwaysRebuild() ||
3940 PointeeType != T->getPointeeTypeAsWritten()) {
3941 Result = getDerived().RebuildReferenceType(PointeeType,
3942 T->isSpelledAsLValue(),
3943 TL.getSigilLoc());
3944 if (Result.isNull())
3945 return QualType();
3946 }
3947
John McCall31168b02011-06-15 23:02:42 +00003948 // Objective-C ARC can add lifetime qualifiers to the type that we're
3949 // referring to.
3950 TLB.TypeWasModifiedSafely(
3951 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3952
John McCall70dd5f62009-10-30 00:06:24 +00003953 // r-value references can be rebuilt as l-value references.
3954 ReferenceTypeLoc NewTL;
3955 if (isa<LValueReferenceType>(Result))
3956 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3957 else
3958 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3959 NewTL.setSigilLoc(TL.getSigilLoc());
3960
3961 return Result;
3962}
3963
Mike Stump11289f42009-09-09 15:08:12 +00003964template<typename Derived>
3965QualType
John McCall550e0c22009-10-21 00:40:46 +00003966TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003967 LValueReferenceTypeLoc TL) {
3968 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003969}
3970
Mike Stump11289f42009-09-09 15:08:12 +00003971template<typename Derived>
3972QualType
John McCall550e0c22009-10-21 00:40:46 +00003973TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003974 RValueReferenceTypeLoc TL) {
3975 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003976}
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregord6ff3322009-08-04 16:50:30 +00003978template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003979QualType
John McCall550e0c22009-10-21 00:40:46 +00003980TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003981 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003982 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003983 if (PointeeType.isNull())
3984 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003985
Abramo Bagnara509357842011-03-05 14:42:21 +00003986 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003987 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003988 if (OldClsTInfo) {
3989 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3990 if (!NewClsTInfo)
3991 return QualType();
3992 }
3993
3994 const MemberPointerType *T = TL.getTypePtr();
3995 QualType OldClsType = QualType(T->getClass(), 0);
3996 QualType NewClsType;
3997 if (NewClsTInfo)
3998 NewClsType = NewClsTInfo->getType();
3999 else {
4000 NewClsType = getDerived().TransformType(OldClsType);
4001 if (NewClsType.isNull())
4002 return QualType();
4003 }
Mike Stump11289f42009-09-09 15:08:12 +00004004
John McCall550e0c22009-10-21 00:40:46 +00004005 QualType Result = TL.getType();
4006 if (getDerived().AlwaysRebuild() ||
4007 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004008 NewClsType != OldClsType) {
4009 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004010 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004011 if (Result.isNull())
4012 return QualType();
4013 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014
Reid Kleckner0503a872013-12-05 01:23:43 +00004015 // If we had to adjust the pointee type when building a member pointer, make
4016 // sure to push TypeLoc info for it.
4017 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4018 if (MPT && PointeeType != MPT->getPointeeType()) {
4019 assert(isa<AdjustedType>(MPT->getPointeeType()));
4020 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4021 }
4022
John McCall550e0c22009-10-21 00:40:46 +00004023 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4024 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004025 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004026
4027 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004028}
4029
Mike Stump11289f42009-09-09 15:08:12 +00004030template<typename Derived>
4031QualType
John McCall550e0c22009-10-21 00:40:46 +00004032TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004033 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004034 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004035 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036 if (ElementType.isNull())
4037 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004038
John McCall550e0c22009-10-21 00:40:46 +00004039 QualType Result = TL.getType();
4040 if (getDerived().AlwaysRebuild() ||
4041 ElementType != T->getElementType()) {
4042 Result = getDerived().RebuildConstantArrayType(ElementType,
4043 T->getSizeModifier(),
4044 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004045 T->getIndexTypeCVRQualifiers(),
4046 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004047 if (Result.isNull())
4048 return QualType();
4049 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004050
4051 // We might have either a ConstantArrayType or a VariableArrayType now:
4052 // a ConstantArrayType is allowed to have an element type which is a
4053 // VariableArrayType if the type is dependent. Fortunately, all array
4054 // types have the same location layout.
4055 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004056 NewTL.setLBracketLoc(TL.getLBracketLoc());
4057 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004058
John McCall550e0c22009-10-21 00:40:46 +00004059 Expr *Size = TL.getSizeExpr();
4060 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004061 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4062 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004063 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4064 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004065 }
4066 NewTL.setSizeExpr(Size);
4067
4068 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004069}
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004072QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004073 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004074 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004075 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004076 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077 if (ElementType.isNull())
4078 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004079
John McCall550e0c22009-10-21 00:40:46 +00004080 QualType Result = TL.getType();
4081 if (getDerived().AlwaysRebuild() ||
4082 ElementType != T->getElementType()) {
4083 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004084 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004085 T->getIndexTypeCVRQualifiers(),
4086 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004087 if (Result.isNull())
4088 return QualType();
4089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004090
John McCall550e0c22009-10-21 00:40:46 +00004091 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4092 NewTL.setLBracketLoc(TL.getLBracketLoc());
4093 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004094 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004095
4096 return Result;
4097}
4098
4099template<typename Derived>
4100QualType
4101TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004102 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004103 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004104 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4105 if (ElementType.isNull())
4106 return QualType();
4107
John McCalldadc5752010-08-24 06:29:42 +00004108 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004109 = getDerived().TransformExpr(T->getSizeExpr());
4110 if (SizeResult.isInvalid())
4111 return QualType();
4112
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004113 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004114
4115 QualType Result = TL.getType();
4116 if (getDerived().AlwaysRebuild() ||
4117 ElementType != T->getElementType() ||
4118 Size != T->getSizeExpr()) {
4119 Result = getDerived().RebuildVariableArrayType(ElementType,
4120 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004121 Size,
John McCall550e0c22009-10-21 00:40:46 +00004122 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004123 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004124 if (Result.isNull())
4125 return QualType();
4126 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004127
Serge Pavlov774c6d02014-02-06 03:49:11 +00004128 // We might have constant size array now, but fortunately it has the same
4129 // location layout.
4130 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004131 NewTL.setLBracketLoc(TL.getLBracketLoc());
4132 NewTL.setRBracketLoc(TL.getRBracketLoc());
4133 NewTL.setSizeExpr(Size);
4134
4135 return Result;
4136}
4137
4138template<typename Derived>
4139QualType
4140TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004141 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004142 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004143 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4144 if (ElementType.isNull())
4145 return QualType();
4146
Richard Smith764d2fe2011-12-20 02:08:33 +00004147 // Array bounds are constant expressions.
4148 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4149 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004150
John McCall33ddac02011-01-19 10:06:00 +00004151 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4152 Expr *origSize = TL.getSizeExpr();
4153 if (!origSize) origSize = T->getSizeExpr();
4154
4155 ExprResult sizeResult
4156 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004157 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004158 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004159 return QualType();
4160
John McCall33ddac02011-01-19 10:06:00 +00004161 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004162
4163 QualType Result = TL.getType();
4164 if (getDerived().AlwaysRebuild() ||
4165 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004166 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004167 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4168 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004169 size,
John McCall550e0c22009-10-21 00:40:46 +00004170 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004171 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004172 if (Result.isNull())
4173 return QualType();
4174 }
John McCall550e0c22009-10-21 00:40:46 +00004175
4176 // We might have any sort of array type now, but fortunately they
4177 // all have the same location layout.
4178 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4179 NewTL.setLBracketLoc(TL.getLBracketLoc());
4180 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004181 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004182
4183 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184}
Mike Stump11289f42009-09-09 15:08:12 +00004185
4186template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004187QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004188 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004189 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004190 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004191
4192 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193 QualType ElementType = getDerived().TransformType(T->getElementType());
4194 if (ElementType.isNull())
4195 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004196
Richard Smith764d2fe2011-12-20 02:08:33 +00004197 // Vector sizes are constant expressions.
4198 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4199 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004200
John McCalldadc5752010-08-24 06:29:42 +00004201 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004202 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004203 if (Size.isInvalid())
4204 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004205
John McCall550e0c22009-10-21 00:40:46 +00004206 QualType Result = TL.getType();
4207 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004208 ElementType != T->getElementType() ||
4209 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004210 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004211 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004213 if (Result.isNull())
4214 return QualType();
4215 }
John McCall550e0c22009-10-21 00:40:46 +00004216
4217 // Result might be dependent or not.
4218 if (isa<DependentSizedExtVectorType>(Result)) {
4219 DependentSizedExtVectorTypeLoc NewTL
4220 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4221 NewTL.setNameLoc(TL.getNameLoc());
4222 } else {
4223 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4224 NewTL.setNameLoc(TL.getNameLoc());
4225 }
4226
4227 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
4230template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004231QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004232 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004233 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004234 QualType ElementType = getDerived().TransformType(T->getElementType());
4235 if (ElementType.isNull())
4236 return QualType();
4237
John McCall550e0c22009-10-21 00:40:46 +00004238 QualType Result = TL.getType();
4239 if (getDerived().AlwaysRebuild() ||
4240 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004241 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004242 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004243 if (Result.isNull())
4244 return QualType();
4245 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004246
John McCall550e0c22009-10-21 00:40:46 +00004247 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4248 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004249
John McCall550e0c22009-10-21 00:40:46 +00004250 return Result;
4251}
4252
4253template<typename Derived>
4254QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004255 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004256 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004257 QualType ElementType = getDerived().TransformType(T->getElementType());
4258 if (ElementType.isNull())
4259 return QualType();
4260
4261 QualType Result = TL.getType();
4262 if (getDerived().AlwaysRebuild() ||
4263 ElementType != T->getElementType()) {
4264 Result = getDerived().RebuildExtVectorType(ElementType,
4265 T->getNumElements(),
4266 /*FIXME*/ SourceLocation());
4267 if (Result.isNull())
4268 return QualType();
4269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4272 NewTL.setNameLoc(TL.getNameLoc());
4273
4274 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275}
Mike Stump11289f42009-09-09 15:08:12 +00004276
David Blaikie05785d12013-02-20 22:23:23 +00004277template <typename Derived>
4278ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4279 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4280 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004281 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004282 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004283
Douglas Gregor715e4612011-01-14 22:40:04 +00004284 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004285 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004286 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004287 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004288 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004289
Douglas Gregor715e4612011-01-14 22:40:04 +00004290 TypeLocBuilder TLB;
4291 TypeLoc NewTL = OldDI->getTypeLoc();
4292 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004293
4294 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004295 OldExpansionTL.getPatternLoc());
4296 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004297 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004298
4299 Result = RebuildPackExpansionType(Result,
4300 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004301 OldExpansionTL.getEllipsisLoc(),
4302 NumExpansions);
4303 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004304 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004305
Douglas Gregor715e4612011-01-14 22:40:04 +00004306 PackExpansionTypeLoc NewExpansionTL
4307 = TLB.push<PackExpansionTypeLoc>(Result);
4308 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4309 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4310 } else
4311 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004312 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004313 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004314
John McCall8fb0d9d2011-05-01 22:35:37 +00004315 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004316 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004317
4318 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4319 OldParm->getDeclContext(),
4320 OldParm->getInnerLocStart(),
4321 OldParm->getLocation(),
4322 OldParm->getIdentifier(),
4323 NewDI->getType(),
4324 NewDI,
4325 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004326 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004327 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4328 OldParm->getFunctionScopeIndex() + indexAdjustment);
4329 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004330}
4331
4332template<typename Derived>
4333bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004334 TransformFunctionTypeParams(SourceLocation Loc,
4335 ParmVarDecl **Params, unsigned NumParams,
4336 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004337 SmallVectorImpl<QualType> &OutParamTypes,
4338 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004339 int indexAdjustment = 0;
4340
Douglas Gregordd472162011-01-07 00:20:55 +00004341 for (unsigned i = 0; i != NumParams; ++i) {
4342 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004343 assert(OldParm->getFunctionScopeIndex() == i);
4344
David Blaikie05785d12013-02-20 22:23:23 +00004345 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004346 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004347 if (OldParm->isParameterPack()) {
4348 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004349 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004350
Douglas Gregor5499af42011-01-05 23:12:31 +00004351 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004352 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004353 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004354 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4355 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004356 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4357
Douglas Gregor5499af42011-01-05 23:12:31 +00004358 // Determine whether we should expand the parameter packs.
4359 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004360 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004361 Optional<unsigned> OrigNumExpansions =
4362 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004363 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004364 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4365 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004366 Unexpanded,
4367 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004368 RetainExpansion,
4369 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004370 return true;
4371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor5499af42011-01-05 23:12:31 +00004373 if (ShouldExpand) {
4374 // Expand the function parameter pack into multiple, separate
4375 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004376 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004377 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004378 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
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 Gregor5499af42011-01-05 23:12:31 +00004384 if (!NewParm)
4385 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004386
Douglas Gregordd472162011-01-07 00:20:55 +00004387 OutParamTypes.push_back(NewParm->getType());
4388 if (PVars)
4389 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004390 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004391
4392 // If we're supposed to retain a pack expansion, do so by temporarily
4393 // forgetting the partially-substituted parameter pack.
4394 if (RetainExpansion) {
4395 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004396 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004397 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004398 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004399 OrigNumExpansions,
4400 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004401 if (!NewParm)
4402 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004403
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004404 OutParamTypes.push_back(NewParm->getType());
4405 if (PVars)
4406 PVars->push_back(NewParm);
4407 }
4408
John McCall8fb0d9d2011-05-01 22:35:37 +00004409 // The next parameter should have the same adjustment as the
4410 // last thing we pushed, but we post-incremented indexAdjustment
4411 // on every push. Also, if we push nothing, the adjustment should
4412 // go down by one.
4413 indexAdjustment--;
4414
Douglas Gregor5499af42011-01-05 23:12:31 +00004415 // We're done with the pack expansion.
4416 continue;
4417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004418
4419 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004420 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004421 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4422 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004423 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004424 NumExpansions,
4425 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004426 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004427 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004428 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004429 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004430
John McCall58f10c32010-03-11 09:03:00 +00004431 if (!NewParm)
4432 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004433
Douglas Gregordd472162011-01-07 00:20:55 +00004434 OutParamTypes.push_back(NewParm->getType());
4435 if (PVars)
4436 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004437 continue;
4438 }
John McCall58f10c32010-03-11 09:03:00 +00004439
4440 // Deal with the possibility that we don't have a parameter
4441 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004442 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004443 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004444 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004445 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004446 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004447 = dyn_cast<PackExpansionType>(OldType)) {
4448 // We have a function parameter pack that may need to be expanded.
4449 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004450 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004451 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
Douglas Gregor5499af42011-01-05 23:12:31 +00004453 // Determine whether we should expand the parameter packs.
4454 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004455 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004456 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004457 Unexpanded,
4458 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004459 RetainExpansion,
4460 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004461 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004463
Douglas Gregor5499af42011-01-05 23:12:31 +00004464 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004465 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004466 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004467 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004468 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4469 QualType NewType = getDerived().TransformType(Pattern);
4470 if (NewType.isNull())
4471 return true;
John McCall58f10c32010-03-11 09:03:00 +00004472
Douglas Gregordd472162011-01-07 00:20:55 +00004473 OutParamTypes.push_back(NewType);
4474 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004475 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004477
Douglas Gregor5499af42011-01-05 23:12:31 +00004478 // We're done with the pack expansion.
4479 continue;
4480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004481
Douglas Gregor48d24112011-01-10 20:53:55 +00004482 // If we're supposed to retain a pack expansion, do so by temporarily
4483 // forgetting the partially-substituted parameter pack.
4484 if (RetainExpansion) {
4485 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4486 QualType NewType = getDerived().TransformType(Pattern);
4487 if (NewType.isNull())
4488 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004489
Douglas Gregor48d24112011-01-10 20:53:55 +00004490 OutParamTypes.push_back(NewType);
4491 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004492 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004493 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004494
Chad Rosier1dcde962012-08-08 18:46:20 +00004495 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 // expansion.
4497 OldType = Expansion->getPattern();
4498 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004499 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4500 NewType = getDerived().TransformType(OldType);
4501 } else {
4502 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004504
Douglas Gregor5499af42011-01-05 23:12:31 +00004505 if (NewType.isNull())
4506 return true;
4507
4508 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004509 NewType = getSema().Context.getPackExpansionType(NewType,
4510 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004511
Douglas Gregordd472162011-01-07 00:20:55 +00004512 OutParamTypes.push_back(NewType);
4513 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004514 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004515 }
4516
John McCall8fb0d9d2011-05-01 22:35:37 +00004517#ifndef NDEBUG
4518 if (PVars) {
4519 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4520 if (ParmVarDecl *parm = (*PVars)[i])
4521 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004522 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004523#endif
4524
4525 return false;
4526}
John McCall58f10c32010-03-11 09:03:00 +00004527
4528template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004529QualType
John McCall550e0c22009-10-21 00:40:46 +00004530TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004531 FunctionProtoTypeLoc TL) {
Hans Wennborge113c202014-09-18 16:01:32 +00004532 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004533}
4534
Hans Wennborge113c202014-09-18 16:01:32 +00004535template<typename Derived>
4536QualType
4537TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4538 FunctionProtoTypeLoc TL,
4539 CXXRecordDecl *ThisContext,
4540 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004541 // Transform the parameters and return type.
4542 //
Richard Smithf623c962012-04-17 00:58:00 +00004543 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004544 // When the function has a trailing return type, we instantiate the
4545 // parameters before the return type, since the return type can then refer
4546 // to the parameters themselves (via decltype, sizeof, etc.).
4547 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004548 SmallVector<QualType, 4> ParamTypes;
4549 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004550 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004551
Douglas Gregor7fb25412010-10-01 18:44:50 +00004552 QualType ResultType;
4553
Richard Smith1226c602012-08-14 22:51:13 +00004554 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004555 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004556 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004557 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004558 return QualType();
4559
Douglas Gregor3024f072012-04-16 07:05:22 +00004560 {
4561 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004562 // If a declaration declares a member function or member function
4563 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004564 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004565 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004566 // declarator.
4567 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004568
Alp Toker42a16a62014-01-25 23:51:36 +00004569 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004570 if (ResultType.isNull())
4571 return QualType();
4572 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004573 }
4574 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004575 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004576 if (ResultType.isNull())
4577 return QualType();
4578
Alp Toker9cacbab2014-01-20 20:26:09 +00004579 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004580 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004581 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004582 return QualType();
4583 }
4584
Hans Wennborge113c202014-09-18 16:01:32 +00004585 // FIXME: Need to transform the exception-specification too.
Richard Smithf623c962012-04-17 00:58:00 +00004586
John McCall550e0c22009-10-21 00:40:46 +00004587 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004588 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004589 T->getNumParams() != ParamTypes.size() ||
4590 !std::equal(T->param_type_begin(), T->param_type_end(),
Hans Wennborge113c202014-09-18 16:01:32 +00004591 ParamTypes.begin())) {
4592 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4593 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004594 if (Result.isNull())
4595 return QualType();
4596 }
Mike Stump11289f42009-09-09 15:08:12 +00004597
John McCall550e0c22009-10-21 00:40:46 +00004598 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004599 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004600 NewTL.setLParenLoc(TL.getLParenLoc());
4601 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004602 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004603 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4604 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004605
4606 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004607}
Mike Stump11289f42009-09-09 15:08:12 +00004608
Douglas Gregord6ff3322009-08-04 16:50:30 +00004609template<typename Derived>
4610QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004611 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004612 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004613 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004614 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004615 if (ResultType.isNull())
4616 return QualType();
4617
4618 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004619 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004620 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4621
4622 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004623 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004624 NewTL.setLParenLoc(TL.getLParenLoc());
4625 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004626 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004627
4628 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004629}
Mike Stump11289f42009-09-09 15:08:12 +00004630
John McCallb96ec562009-12-04 22:46:56 +00004631template<typename Derived> QualType
4632TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004633 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004634 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004635 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004636 if (!D)
4637 return QualType();
4638
4639 QualType Result = TL.getType();
4640 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4641 Result = getDerived().RebuildUnresolvedUsingType(D);
4642 if (Result.isNull())
4643 return QualType();
4644 }
4645
4646 // We might get an arbitrary type spec type back. We should at
4647 // least always get a type spec type, though.
4648 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4649 NewTL.setNameLoc(TL.getNameLoc());
4650
4651 return Result;
4652}
4653
Douglas Gregord6ff3322009-08-04 16:50:30 +00004654template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004655QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004656 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004657 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004658 TypedefNameDecl *Typedef
4659 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4660 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004661 if (!Typedef)
4662 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004663
John McCall550e0c22009-10-21 00:40:46 +00004664 QualType Result = TL.getType();
4665 if (getDerived().AlwaysRebuild() ||
4666 Typedef != T->getDecl()) {
4667 Result = getDerived().RebuildTypedefType(Typedef);
4668 if (Result.isNull())
4669 return QualType();
4670 }
Mike Stump11289f42009-09-09 15:08:12 +00004671
John McCall550e0c22009-10-21 00:40:46 +00004672 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4673 NewTL.setNameLoc(TL.getNameLoc());
4674
4675 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004676}
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregord6ff3322009-08-04 16:50:30 +00004678template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004679QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004680 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004681 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004682 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4683 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004684
John McCalldadc5752010-08-24 06:29:42 +00004685 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686 if (E.isInvalid())
4687 return QualType();
4688
Eli Friedmane4f22df2012-02-29 04:03:55 +00004689 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4690 if (E.isInvalid())
4691 return QualType();
4692
John McCall550e0c22009-10-21 00:40:46 +00004693 QualType Result = TL.getType();
4694 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004695 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004696 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004697 if (Result.isNull())
4698 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004700 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004701
John McCall550e0c22009-10-21 00:40:46 +00004702 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004703 NewTL.setTypeofLoc(TL.getTypeofLoc());
4704 NewTL.setLParenLoc(TL.getLParenLoc());
4705 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004706
4707 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004708}
Mike Stump11289f42009-09-09 15:08:12 +00004709
4710template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004711QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004712 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004713 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4714 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4715 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004716 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004717
John McCall550e0c22009-10-21 00:40:46 +00004718 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004719 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4720 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004721 if (Result.isNull())
4722 return QualType();
4723 }
Mike Stump11289f42009-09-09 15:08:12 +00004724
John McCall550e0c22009-10-21 00:40:46 +00004725 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004726 NewTL.setTypeofLoc(TL.getTypeofLoc());
4727 NewTL.setLParenLoc(TL.getLParenLoc());
4728 NewTL.setRParenLoc(TL.getRParenLoc());
4729 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004730
4731 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004732}
Mike Stump11289f42009-09-09 15:08:12 +00004733
4734template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004735QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004736 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004737 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004738
Douglas Gregore922c772009-08-04 22:27:00 +00004739 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004740 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4741 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004742
John McCalldadc5752010-08-24 06:29:42 +00004743 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004744 if (E.isInvalid())
4745 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004746
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004747 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004748 if (E.isInvalid())
4749 return QualType();
4750
John McCall550e0c22009-10-21 00:40:46 +00004751 QualType Result = TL.getType();
4752 if (getDerived().AlwaysRebuild() ||
4753 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004754 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004755 if (Result.isNull())
4756 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004757 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004758 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004759
John McCall550e0c22009-10-21 00:40:46 +00004760 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4761 NewTL.setNameLoc(TL.getNameLoc());
4762
4763 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004764}
4765
4766template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004767QualType TreeTransform<Derived>::TransformUnaryTransformType(
4768 TypeLocBuilder &TLB,
4769 UnaryTransformTypeLoc TL) {
4770 QualType Result = TL.getType();
4771 if (Result->isDependentType()) {
4772 const UnaryTransformType *T = TL.getTypePtr();
4773 QualType NewBase =
4774 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4775 Result = getDerived().RebuildUnaryTransformType(NewBase,
4776 T->getUTTKind(),
4777 TL.getKWLoc());
4778 if (Result.isNull())
4779 return QualType();
4780 }
4781
4782 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4783 NewTL.setKWLoc(TL.getKWLoc());
4784 NewTL.setParensRange(TL.getParensRange());
4785 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4786 return Result;
4787}
4788
4789template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004790QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4791 AutoTypeLoc TL) {
4792 const AutoType *T = TL.getTypePtr();
4793 QualType OldDeduced = T->getDeducedType();
4794 QualType NewDeduced;
4795 if (!OldDeduced.isNull()) {
4796 NewDeduced = getDerived().TransformType(OldDeduced);
4797 if (NewDeduced.isNull())
4798 return QualType();
4799 }
4800
4801 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004802 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4803 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004804 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004805 if (Result.isNull())
4806 return QualType();
4807 }
4808
4809 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4810 NewTL.setNameLoc(TL.getNameLoc());
4811
4812 return Result;
4813}
4814
4815template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004816QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004817 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004818 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004819 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004820 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4821 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004822 if (!Record)
4823 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004824
John McCall550e0c22009-10-21 00:40:46 +00004825 QualType Result = TL.getType();
4826 if (getDerived().AlwaysRebuild() ||
4827 Record != T->getDecl()) {
4828 Result = getDerived().RebuildRecordType(Record);
4829 if (Result.isNull())
4830 return QualType();
4831 }
Mike Stump11289f42009-09-09 15:08:12 +00004832
John McCall550e0c22009-10-21 00:40:46 +00004833 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4834 NewTL.setNameLoc(TL.getNameLoc());
4835
4836 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004837}
Mike Stump11289f42009-09-09 15:08:12 +00004838
4839template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004840QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004841 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004842 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004843 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004844 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4845 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004846 if (!Enum)
4847 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004848
John McCall550e0c22009-10-21 00:40:46 +00004849 QualType Result = TL.getType();
4850 if (getDerived().AlwaysRebuild() ||
4851 Enum != T->getDecl()) {
4852 Result = getDerived().RebuildEnumType(Enum);
4853 if (Result.isNull())
4854 return QualType();
4855 }
Mike Stump11289f42009-09-09 15:08:12 +00004856
John McCall550e0c22009-10-21 00:40:46 +00004857 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4858 NewTL.setNameLoc(TL.getNameLoc());
4859
4860 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004861}
John McCallfcc33b02009-09-05 00:15:47 +00004862
John McCalle78aac42010-03-10 03:28:59 +00004863template<typename Derived>
4864QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4865 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004866 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004867 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4868 TL.getTypePtr()->getDecl());
4869 if (!D) return QualType();
4870
4871 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4872 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4873 return T;
4874}
4875
Douglas Gregord6ff3322009-08-04 16:50:30 +00004876template<typename Derived>
4877QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004878 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004879 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004880 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004881}
4882
Mike Stump11289f42009-09-09 15:08:12 +00004883template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004884QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004885 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004886 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004887 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004888
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004889 // Substitute into the replacement type, which itself might involve something
4890 // that needs to be transformed. This only tends to occur with default
4891 // template arguments of template template parameters.
4892 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4893 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4894 if (Replacement.isNull())
4895 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004896
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004897 // Always canonicalize the replacement type.
4898 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4899 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004900 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004901 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004902
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004903 // Propagate type-source information.
4904 SubstTemplateTypeParmTypeLoc NewTL
4905 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4906 NewTL.setNameLoc(TL.getNameLoc());
4907 return Result;
4908
John McCallcebee162009-10-18 09:09:24 +00004909}
4910
4911template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004912QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4913 TypeLocBuilder &TLB,
4914 SubstTemplateTypeParmPackTypeLoc TL) {
4915 return TransformTypeSpecType(TLB, TL);
4916}
4917
4918template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004919QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004920 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004921 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004922 const TemplateSpecializationType *T = TL.getTypePtr();
4923
Douglas Gregordf846d12011-03-02 18:46:51 +00004924 // The nested-name-specifier never matters in a TemplateSpecializationType,
4925 // because we can't have a dependent nested-name-specifier anyway.
4926 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004927 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004928 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4929 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004930 if (Template.isNull())
4931 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004932
John McCall31f82722010-11-12 08:19:04 +00004933 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4934}
4935
Eli Friedman0dfb8892011-10-06 23:00:33 +00004936template<typename Derived>
4937QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4938 AtomicTypeLoc TL) {
4939 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4940 if (ValueType.isNull())
4941 return QualType();
4942
4943 QualType Result = TL.getType();
4944 if (getDerived().AlwaysRebuild() ||
4945 ValueType != TL.getValueLoc().getType()) {
4946 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4947 if (Result.isNull())
4948 return QualType();
4949 }
4950
4951 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4952 NewTL.setKWLoc(TL.getKWLoc());
4953 NewTL.setLParenLoc(TL.getLParenLoc());
4954 NewTL.setRParenLoc(TL.getRParenLoc());
4955
4956 return Result;
4957}
4958
Chad Rosier1dcde962012-08-08 18:46:20 +00004959 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004960 /// container that provides a \c getArgLoc() member function.
4961 ///
4962 /// This iterator is intended to be used with the iterator form of
4963 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4964 template<typename ArgLocContainer>
4965 class TemplateArgumentLocContainerIterator {
4966 ArgLocContainer *Container;
4967 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004968
Douglas Gregorfe921a72010-12-20 23:36:19 +00004969 public:
4970 typedef TemplateArgumentLoc value_type;
4971 typedef TemplateArgumentLoc reference;
4972 typedef int difference_type;
4973 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004974
Douglas Gregorfe921a72010-12-20 23:36:19 +00004975 class pointer {
4976 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004977
Douglas Gregorfe921a72010-12-20 23:36:19 +00004978 public:
4979 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004980
Douglas Gregorfe921a72010-12-20 23:36:19 +00004981 const TemplateArgumentLoc *operator->() const {
4982 return &Arg;
4983 }
4984 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004985
4986
Douglas Gregorfe921a72010-12-20 23:36:19 +00004987 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004988
Douglas Gregorfe921a72010-12-20 23:36:19 +00004989 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4990 unsigned Index)
4991 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004992
Douglas Gregorfe921a72010-12-20 23:36:19 +00004993 TemplateArgumentLocContainerIterator &operator++() {
4994 ++Index;
4995 return *this;
4996 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004997
Douglas Gregorfe921a72010-12-20 23:36:19 +00004998 TemplateArgumentLocContainerIterator operator++(int) {
4999 TemplateArgumentLocContainerIterator Old(*this);
5000 ++(*this);
5001 return Old;
5002 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005003
Douglas Gregorfe921a72010-12-20 23:36:19 +00005004 TemplateArgumentLoc operator*() const {
5005 return Container->getArgLoc(Index);
5006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005007
Douglas Gregorfe921a72010-12-20 23:36:19 +00005008 pointer operator->() const {
5009 return pointer(Container->getArgLoc(Index));
5010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005011
Douglas Gregorfe921a72010-12-20 23:36:19 +00005012 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005013 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005014 return X.Container == Y.Container && X.Index == Y.Index;
5015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005016
Douglas Gregorfe921a72010-12-20 23:36:19 +00005017 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005018 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005019 return !(X == Y);
5020 }
5021 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005022
5023
John McCall31f82722010-11-12 08:19:04 +00005024template <typename Derived>
5025QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5026 TypeLocBuilder &TLB,
5027 TemplateSpecializationTypeLoc TL,
5028 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005029 TemplateArgumentListInfo NewTemplateArgs;
5030 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5031 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005032 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5033 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005034 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005035 ArgIterator(TL, TL.getNumArgs()),
5036 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005037 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005038
John McCall0ad16662009-10-29 08:12:44 +00005039 // FIXME: maybe don't rebuild if all the template arguments are the same.
5040
5041 QualType Result =
5042 getDerived().RebuildTemplateSpecializationType(Template,
5043 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005044 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005045
5046 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005047 // Specializations of template template parameters are represented as
5048 // TemplateSpecializationTypes, and substitution of type alias templates
5049 // within a dependent context can transform them into
5050 // DependentTemplateSpecializationTypes.
5051 if (isa<DependentTemplateSpecializationType>(Result)) {
5052 DependentTemplateSpecializationTypeLoc NewTL
5053 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005054 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005055 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005056 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005057 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005058 NewTL.setLAngleLoc(TL.getLAngleLoc());
5059 NewTL.setRAngleLoc(TL.getRAngleLoc());
5060 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5061 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5062 return Result;
5063 }
5064
John McCall0ad16662009-10-29 08:12:44 +00005065 TemplateSpecializationTypeLoc NewTL
5066 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005067 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005068 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5069 NewTL.setLAngleLoc(TL.getLAngleLoc());
5070 NewTL.setRAngleLoc(TL.getRAngleLoc());
5071 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5072 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005073 }
Mike Stump11289f42009-09-09 15:08:12 +00005074
John McCall0ad16662009-10-29 08:12:44 +00005075 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregor5a064722011-02-28 17:23:35 +00005078template <typename Derived>
5079QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5080 TypeLocBuilder &TLB,
5081 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005082 TemplateName Template,
5083 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005084 TemplateArgumentListInfo NewTemplateArgs;
5085 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5086 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5087 typedef TemplateArgumentLocContainerIterator<
5088 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005089 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005090 ArgIterator(TL, TL.getNumArgs()),
5091 NewTemplateArgs))
5092 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005093
Douglas Gregor5a064722011-02-28 17:23:35 +00005094 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005095
Douglas Gregor5a064722011-02-28 17:23:35 +00005096 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5097 QualType Result
5098 = getSema().Context.getDependentTemplateSpecializationType(
5099 TL.getTypePtr()->getKeyword(),
5100 DTN->getQualifier(),
5101 DTN->getIdentifier(),
5102 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005103
Douglas Gregor5a064722011-02-28 17:23:35 +00005104 DependentTemplateSpecializationTypeLoc NewTL
5105 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005106 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005107 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005108 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005109 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005110 NewTL.setLAngleLoc(TL.getLAngleLoc());
5111 NewTL.setRAngleLoc(TL.getRAngleLoc());
5112 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5113 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5114 return Result;
5115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005116
5117 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005118 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005119 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005120 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005121
Douglas Gregor5a064722011-02-28 17:23:35 +00005122 if (!Result.isNull()) {
5123 /// FIXME: Wrap this in an elaborated-type-specifier?
5124 TemplateSpecializationTypeLoc NewTL
5125 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005126 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005127 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005128 NewTL.setLAngleLoc(TL.getLAngleLoc());
5129 NewTL.setRAngleLoc(TL.getRAngleLoc());
5130 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5131 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5132 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005133
Douglas Gregor5a064722011-02-28 17:23:35 +00005134 return Result;
5135}
5136
Mike Stump11289f42009-09-09 15:08:12 +00005137template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005138QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005139TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005140 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005141 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005142
Douglas Gregor844cb502011-03-01 18:12:44 +00005143 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005144 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005145 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005146 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005147 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5148 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005149 return QualType();
5150 }
Mike Stump11289f42009-09-09 15:08:12 +00005151
John McCall31f82722010-11-12 08:19:04 +00005152 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5153 if (NamedT.isNull())
5154 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005155
Richard Smith3f1b5d02011-05-05 21:57:07 +00005156 // C++0x [dcl.type.elab]p2:
5157 // If the identifier resolves to a typedef-name or the simple-template-id
5158 // resolves to an alias template specialization, the
5159 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005160 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5161 if (const TemplateSpecializationType *TST =
5162 NamedT->getAs<TemplateSpecializationType>()) {
5163 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005164 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5165 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005166 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5167 diag::err_tag_reference_non_tag) << 4;
5168 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5169 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005170 }
5171 }
5172
John McCall550e0c22009-10-21 00:40:46 +00005173 QualType Result = TL.getType();
5174 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005175 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005176 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005177 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005178 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005179 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005180 if (Result.isNull())
5181 return QualType();
5182 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005183
Abramo Bagnara6150c882010-05-11 21:36:43 +00005184 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005185 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005186 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005187 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005188}
Mike Stump11289f42009-09-09 15:08:12 +00005189
5190template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005191QualType TreeTransform<Derived>::TransformAttributedType(
5192 TypeLocBuilder &TLB,
5193 AttributedTypeLoc TL) {
5194 const AttributedType *oldType = TL.getTypePtr();
5195 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5196 if (modifiedType.isNull())
5197 return QualType();
5198
5199 QualType result = TL.getType();
5200
5201 // FIXME: dependent operand expressions?
5202 if (getDerived().AlwaysRebuild() ||
5203 modifiedType != oldType->getModifiedType()) {
5204 // TODO: this is really lame; we should really be rebuilding the
5205 // equivalent type from first principles.
5206 QualType equivalentType
5207 = getDerived().TransformType(oldType->getEquivalentType());
5208 if (equivalentType.isNull())
5209 return QualType();
5210 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5211 modifiedType,
5212 equivalentType);
5213 }
5214
5215 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5216 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5217 if (TL.hasAttrOperand())
5218 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5219 if (TL.hasAttrExprOperand())
5220 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5221 else if (TL.hasAttrEnumOperand())
5222 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5223
5224 return result;
5225}
5226
5227template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005228QualType
5229TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5230 ParenTypeLoc TL) {
5231 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5232 if (Inner.isNull())
5233 return QualType();
5234
5235 QualType Result = TL.getType();
5236 if (getDerived().AlwaysRebuild() ||
5237 Inner != TL.getInnerLoc().getType()) {
5238 Result = getDerived().RebuildParenType(Inner);
5239 if (Result.isNull())
5240 return QualType();
5241 }
5242
5243 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5244 NewTL.setLParenLoc(TL.getLParenLoc());
5245 NewTL.setRParenLoc(TL.getRParenLoc());
5246 return Result;
5247}
5248
5249template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005250QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005251 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005252 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005253
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005254 NestedNameSpecifierLoc QualifierLoc
5255 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5256 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005257 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005258
John McCallc392f372010-06-11 00:33:02 +00005259 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005260 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005261 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005262 QualifierLoc,
5263 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005264 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005265 if (Result.isNull())
5266 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005267
Abramo Bagnarad7548482010-05-19 21:37:53 +00005268 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5269 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005270 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5271
Abramo Bagnarad7548482010-05-19 21:37:53 +00005272 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005273 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005274 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005275 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005276 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005277 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005278 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005279 NewTL.setNameLoc(TL.getNameLoc());
5280 }
John McCall550e0c22009-10-21 00:40:46 +00005281 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005282}
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregord6ff3322009-08-04 16:50:30 +00005284template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005285QualType TreeTransform<Derived>::
5286 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005287 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005288 NestedNameSpecifierLoc QualifierLoc;
5289 if (TL.getQualifierLoc()) {
5290 QualifierLoc
5291 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5292 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005293 return QualType();
5294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005295
John McCall31f82722010-11-12 08:19:04 +00005296 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005297 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005298}
5299
5300template<typename Derived>
5301QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005302TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5303 DependentTemplateSpecializationTypeLoc TL,
5304 NestedNameSpecifierLoc QualifierLoc) {
5305 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005306
Douglas Gregora7a795b2011-03-01 20:11:18 +00005307 TemplateArgumentListInfo NewTemplateArgs;
5308 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5309 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005310
Douglas Gregora7a795b2011-03-01 20:11:18 +00005311 typedef TemplateArgumentLocContainerIterator<
5312 DependentTemplateSpecializationTypeLoc> ArgIterator;
5313 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5314 ArgIterator(TL, TL.getNumArgs()),
5315 NewTemplateArgs))
5316 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005317
Douglas Gregora7a795b2011-03-01 20:11:18 +00005318 QualType Result
5319 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5320 QualifierLoc,
5321 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005322 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005323 NewTemplateArgs);
5324 if (Result.isNull())
5325 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregora7a795b2011-03-01 20:11:18 +00005327 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5328 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005329
Douglas Gregora7a795b2011-03-01 20:11:18 +00005330 // Copy information relevant to the template specialization.
5331 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005332 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005333 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005334 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005335 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5336 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005337 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005338 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005339
Douglas Gregora7a795b2011-03-01 20:11:18 +00005340 // Copy information relevant to the elaborated type.
5341 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005342 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005343 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005344 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5345 DependentTemplateSpecializationTypeLoc SpecTL
5346 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005347 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005348 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005349 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005350 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005351 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5352 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005353 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005354 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005355 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005356 TemplateSpecializationTypeLoc SpecTL
5357 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005358 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005359 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005360 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5361 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005362 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005363 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005364 }
5365 return Result;
5366}
5367
5368template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005369QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5370 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005371 QualType Pattern
5372 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005373 if (Pattern.isNull())
5374 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005375
5376 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005377 if (getDerived().AlwaysRebuild() ||
5378 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005379 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005380 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005381 TL.getEllipsisLoc(),
5382 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005383 if (Result.isNull())
5384 return QualType();
5385 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005386
Douglas Gregor822d0302011-01-12 17:07:58 +00005387 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5388 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5389 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005390}
5391
5392template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005393QualType
5394TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005395 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005396 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005397 TLB.pushFullCopy(TL);
5398 return TL.getType();
5399}
5400
5401template<typename Derived>
5402QualType
5403TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005404 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005405 // ObjCObjectType is never dependent.
5406 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005407 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005408}
Mike Stump11289f42009-09-09 15:08:12 +00005409
5410template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005411QualType
5412TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005413 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005414 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005415 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005416 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005417}
5418
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005420// Statement transformation
5421//===----------------------------------------------------------------------===//
5422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005423StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005424TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005425 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005426}
5427
5428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005429StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005430TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5431 return getDerived().TransformCompoundStmt(S, false);
5432}
5433
5434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005435StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005436TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005437 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005438 Sema::CompoundScopeRAII CompoundScope(getSema());
5439
John McCall1ababa62010-08-27 19:56:05 +00005440 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005442 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005443 for (auto *B : S->body()) {
5444 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005445 if (Result.isInvalid()) {
5446 // Immediately fail if this was a DeclStmt, since it's very
5447 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005448 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005449 return StmtError();
5450
5451 // Otherwise, just keep processing substatements and fail later.
5452 SubStmtInvalid = true;
5453 continue;
5454 }
Mike Stump11289f42009-09-09 15:08:12 +00005455
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005456 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005457 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005458 }
Mike Stump11289f42009-09-09 15:08:12 +00005459
John McCall1ababa62010-08-27 19:56:05 +00005460 if (SubStmtInvalid)
5461 return StmtError();
5462
Douglas Gregorebe10102009-08-20 07:17:43 +00005463 if (!getDerived().AlwaysRebuild() &&
5464 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005465 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005466
5467 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005468 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005469 S->getRBracLoc(),
5470 IsStmtExpr);
5471}
Mike Stump11289f42009-09-09 15:08:12 +00005472
Douglas Gregorebe10102009-08-20 07:17:43 +00005473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005474StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005475TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005476 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005477 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005478 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5479 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005480
Eli Friedman06577382009-11-19 03:14:00 +00005481 // Transform the left-hand case value.
5482 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005483 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005484 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
Eli Friedman06577382009-11-19 03:14:00 +00005487 // Transform the right-hand case value (for the GNU case-range extension).
5488 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005489 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005490 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005492 }
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 // Build the case statement.
5495 // Case statements are always rebuilt so that they will attached to their
5496 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005497 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005498 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005499 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005500 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 S->getColonLoc());
5502 if (Case.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 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005506 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005507 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005509
Douglas Gregorebe10102009-08-20 07:17:43 +00005510 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005511 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005512}
5513
5514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005515StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005516TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005518 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005519 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005521
Douglas Gregorebe10102009-08-20 07:17:43 +00005522 // Default statements are always rebuilt
5523 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005524 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005525}
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregorebe10102009-08-20 07:17:43 +00005527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005528StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005529TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005530 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005531 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005532 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005533
Chris Lattnercab02a62011-02-17 20:34:02 +00005534 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5535 S->getDecl());
5536 if (!LD)
5537 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005538
5539
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005541 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005542 cast<LabelDecl>(LD), SourceLocation(),
5543 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005544}
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregorebe10102009-08-20 07:17:43 +00005546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005547StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005548TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5549 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5550 if (SubStmt.isInvalid())
5551 return StmtError();
5552
5553 // TODO: transform attributes
5554 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5555 return S;
5556
5557 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5558 S->getAttrs(),
5559 SubStmt.get());
5560}
5561
5562template<typename Derived>
5563StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005564TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005565 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005566 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005567 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005568 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005569 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005570 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005571 getDerived().TransformDefinition(
5572 S->getConditionVariable()->getLocation(),
5573 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005574 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005575 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005576 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005577 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005578
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005579 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005580 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005581
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005582 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005583 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005584 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005585 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005586 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005588
John McCallb268a282010-08-23 23:25:46 +00005589 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005590 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005592
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005593 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005594 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005596
Douglas Gregorebe10102009-08-20 07:17:43 +00005597 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005598 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005599 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005603 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005605 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005606
Douglas Gregorebe10102009-08-20 07:17:43 +00005607 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005608 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005609 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005610 Then.get() == S->getThen() &&
5611 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005612 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005614 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005615 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005616 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005617}
5618
5619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005620StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005621TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005622 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005623 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005624 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005625 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005626 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005627 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005628 getDerived().TransformDefinition(
5629 S->getConditionVariable()->getLocation(),
5630 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005631 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005633 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005634 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005635
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005636 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005638 }
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005641 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005642 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005643 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005644 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005645 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005646
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005648 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005649 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorebe10102009-08-20 07:17:43 +00005652 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005653 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5654 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005655}
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005658StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005659TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005660 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005661 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005662 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005663 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005664 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005665 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005666 getDerived().TransformDefinition(
5667 S->getConditionVariable()->getLocation(),
5668 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005669 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005670 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005671 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005672 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005673
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005674 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005676
5677 if (S->getCond()) {
5678 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005679 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5680 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005681 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005682 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005683 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005684 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005685 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005686 }
Mike Stump11289f42009-09-09 15:08:12 +00005687
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005688 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005689 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005691
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005693 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005698 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005699 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005700 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005701 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005703 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005704 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregorebe10102009-08-20 07:17:43 +00005707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005708StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005709TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005711 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005712 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005713 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005715 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005716 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005717 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005718 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005719
Douglas Gregorebe10102009-08-20 07:17:43 +00005720 if (!getDerived().AlwaysRebuild() &&
5721 Cond.get() == S->getCond() &&
5722 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005723 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005724
John McCallb268a282010-08-23 23:25:46 +00005725 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5726 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005727 S->getRParenLoc());
5728}
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregorebe10102009-08-20 07:17:43 +00005730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005732TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005733 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005734 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005735 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregorebe10102009-08-20 07:17:43 +00005738 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005739 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005740 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005741 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005742 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005743 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005744 getDerived().TransformDefinition(
5745 S->getConditionVariable()->getLocation(),
5746 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005747 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005748 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005749 } else {
5750 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005751
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005752 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005753 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005754
5755 if (S->getCond()) {
5756 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005757 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5758 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005759 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005760 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005762
John McCallb268a282010-08-23 23:25:46 +00005763 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005764 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005765 }
Mike Stump11289f42009-09-09 15:08:12 +00005766
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005767 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005768 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005769 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005770
Douglas Gregorebe10102009-08-20 07:17:43 +00005771 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005772 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005773 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
Richard Smith945f8d32013-01-14 22:39:08 +00005776 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005777 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005779
Douglas Gregorebe10102009-08-20 07:17:43 +00005780 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005781 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005782 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005783 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregorebe10102009-08-20 07:17:43 +00005785 if (!getDerived().AlwaysRebuild() &&
5786 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005787 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005788 Inc.get() == S->getInc() &&
5789 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005790 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregorebe10102009-08-20 07:17:43 +00005792 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005793 Init.get(), FullCond, ConditionVar,
5794 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005795}
5796
5797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005798StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005799TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005800 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5801 S->getLabel());
5802 if (!LD)
5803 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005804
Douglas Gregorebe10102009-08-20 07:17:43 +00005805 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005806 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005807 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005808}
5809
5810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005811StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005812TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005813 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005814 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005816 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005817
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 if (!getDerived().AlwaysRebuild() &&
5819 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005820 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005821
5822 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005823 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005824}
5825
5826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005827StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005828TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005829 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005830}
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregorebe10102009-08-20 07:17:43 +00005832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005833StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005834TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005835 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005836}
Mike Stump11289f42009-09-09 15:08:12 +00005837
Douglas Gregorebe10102009-08-20 07:17:43 +00005838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005839StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005840TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00005841 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
5842 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00005843 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005845
Mike Stump11289f42009-09-09 15:08:12 +00005846 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005848 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005849}
Mike Stump11289f42009-09-09 15:08:12 +00005850
Douglas Gregorebe10102009-08-20 07:17:43 +00005851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005852StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005853TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005854 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005855 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005856 for (auto *D : S->decls()) {
5857 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005858 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005859 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005860
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005861 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005862 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregorebe10102009-08-20 07:17:43 +00005864 Decls.push_back(Transformed);
5865 }
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregorebe10102009-08-20 07:17:43 +00005867 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005868 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005869
Rafael Espindolaab417692013-07-09 12:05:01 +00005870 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005871}
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregorebe10102009-08-20 07:17:43 +00005873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005874StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005875TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Benjamin Kramerf0623432012-08-23 22:51:59 +00005877 SmallVector<Expr*, 8> Constraints;
5878 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005879 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005880
John McCalldadc5752010-08-24 06:29:42 +00005881 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005882 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005883
5884 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005885
Anders Carlssonaaeef072010-01-24 05:50:09 +00005886 // Go through the outputs.
5887 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005888 Names.push_back(S->getOutputIdentifier(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->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Anders Carlssonaaeef072010-01-24 05:50:09 +00005893 // Transform the output expr.
5894 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005895 ExprResult Result = getDerived().TransformExpr(OutputExpr);
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() != OutputExpr;
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 // Go through the inputs.
5905 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005906 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005907
Anders Carlssonaaeef072010-01-24 05:50:09 +00005908 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005909 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005910
Anders Carlssonaaeef072010-01-24 05:50:09 +00005911 // Transform the input expr.
5912 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005913 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005914 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005916
Anders Carlssonaaeef072010-01-24 05:50:09 +00005917 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005918
John McCallb268a282010-08-23 23:25:46 +00005919 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005920 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005921
Anders Carlssonaaeef072010-01-24 05:50:09 +00005922 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005923 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005924
5925 // Go through the clobbers.
5926 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005927 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005928
5929 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005930 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005931 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5932 S->isVolatile(), S->getNumOutputs(),
5933 S->getNumInputs(), Names.data(),
5934 Constraints, Exprs, AsmString.get(),
5935 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005936}
5937
Chad Rosier32503022012-06-11 20:47:18 +00005938template<typename Derived>
5939StmtResult
5940TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005941 ArrayRef<Token> AsmToks =
5942 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005943
John McCallf413f5e2013-05-03 00:10:13 +00005944 bool HadError = false, HadChange = false;
5945
5946 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5947 SmallVector<Expr*, 8> TransformedExprs;
5948 TransformedExprs.reserve(SrcExprs.size());
5949 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5950 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5951 if (!Result.isUsable()) {
5952 HadError = true;
5953 } else {
5954 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005955 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005956 }
5957 }
5958
5959 if (HadError) return StmtError();
5960 if (!HadChange && !getDerived().AlwaysRebuild())
5961 return Owned(S);
5962
Chad Rosierb6f46c12012-08-15 16:53:30 +00005963 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005964 AsmToks, S->getAsmString(),
5965 S->getNumOutputs(), S->getNumInputs(),
5966 S->getAllConstraints(), S->getClobbers(),
5967 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005968}
Douglas Gregorebe10102009-08-20 07:17:43 +00005969
5970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005971StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005972TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005973 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005974 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005975 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005976 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005977
Douglas Gregor96c79492010-04-23 22:50:49 +00005978 // Transform the @catch statements (if present).
5979 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005980 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005981 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005982 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005983 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005984 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005985 if (Catch.get() != S->getCatchStmt(I))
5986 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005987 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
Douglas Gregor306de2f2010-04-22 23:59:56 +00005990 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005991 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005992 if (S->getFinallyStmt()) {
5993 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5994 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005996 }
5997
5998 // If nothing changed, just retain this statement.
5999 if (!getDerived().AlwaysRebuild() &&
6000 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006001 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006002 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006003 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006004
Douglas Gregor306de2f2010-04-22 23:59:56 +00006005 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006006 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006007 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006008}
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregorebe10102009-08-20 07:17:43 +00006010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006011StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006012TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006013 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006014 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006015 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006016 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006017 if (FromVar->getTypeSourceInfo()) {
6018 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6019 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006020 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006022
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006023 QualType T;
6024 if (TSInfo)
6025 T = TSInfo->getType();
6026 else {
6027 T = getDerived().TransformType(FromVar->getType());
6028 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006029 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006031
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006032 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6033 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006036
John McCalldadc5752010-08-24 06:29:42 +00006037 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006038 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006039 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006040
6041 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006042 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006043 Var, 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>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006049 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006050 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006051 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006052 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006053
Douglas Gregor306de2f2010-04-22 23:59:56 +00006054 // If nothing changed, just retain this statement.
6055 if (!getDerived().AlwaysRebuild() &&
6056 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006057 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006058
6059 // Build a new statement.
6060 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006061 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006062}
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregorebe10102009-08-20 07:17:43 +00006064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006065StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006066TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006067 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006068 if (S->getThrowExpr()) {
6069 Operand = getDerived().TransformExpr(S->getThrowExpr());
6070 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006072 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006073
Douglas Gregor2900c162010-04-22 21:44:01 +00006074 if (!getDerived().AlwaysRebuild() &&
6075 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006076 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
John McCallb268a282010-08-23 23:25:46 +00006078 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006079}
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregorebe10102009-08-20 07:17:43 +00006081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006082StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006083TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006084 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006085 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006086 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006087 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006089 Object =
6090 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6091 Object.get());
6092 if (Object.isInvalid())
6093 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006094
Douglas Gregor6148de72010-04-22 22:01:21 +00006095 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006096 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006097 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006098 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006099
Douglas Gregor6148de72010-04-22 22:01:21 +00006100 // If nothing change, just retain the current statement.
6101 if (!getDerived().AlwaysRebuild() &&
6102 Object.get() == S->getSynchExpr() &&
6103 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006104 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006105
6106 // Build a new statement.
6107 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006108 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006109}
6110
6111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006112StmtResult
John McCall31168b02011-06-15 23:02:42 +00006113TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6114 ObjCAutoreleasePoolStmt *S) {
6115 // Transform the body.
6116 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6117 if (Body.isInvalid())
6118 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
John McCall31168b02011-06-15 23:02:42 +00006120 // If nothing changed, just retain this statement.
6121 if (!getDerived().AlwaysRebuild() &&
6122 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006123 return S;
John McCall31168b02011-06-15 23:02:42 +00006124
6125 // Build a new statement.
6126 return getDerived().RebuildObjCAutoreleasePoolStmt(
6127 S->getAtLoc(), Body.get());
6128}
6129
6130template<typename Derived>
6131StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006132TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006133 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006134 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006135 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006136 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006137 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006138
Douglas Gregorf68a5082010-04-22 23:10:45 +00006139 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006140 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006141 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006142 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006143
Douglas Gregorf68a5082010-04-22 23:10:45 +00006144 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006145 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006146 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006148
Douglas Gregorf68a5082010-04-22 23:10:45 +00006149 // If nothing changed, just retain this statement.
6150 if (!getDerived().AlwaysRebuild() &&
6151 Element.get() == S->getElement() &&
6152 Collection.get() == S->getCollection() &&
6153 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006154 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregorf68a5082010-04-22 23:10:45 +00006156 // Build a new statement.
6157 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006158 Element.get(),
6159 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006160 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006161 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006162}
6163
David Majnemer5f7efef2013-10-15 09:50:08 +00006164template <typename Derived>
6165StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006167 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006168 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6169 TypeSourceInfo *T =
6170 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006171 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006172 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006173
David Majnemer5f7efef2013-10-15 09:50:08 +00006174 Var = getDerived().RebuildExceptionDecl(
6175 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6176 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006177 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 }
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006182 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006183 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006185
David Majnemer5f7efef2013-10-15 09:50:08 +00006186 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006188 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006189
David Majnemer5f7efef2013-10-15 09:50:08 +00006190 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006191}
Mike Stump11289f42009-09-09 15:08:12 +00006192
David Majnemer5f7efef2013-10-15 09:50:08 +00006193template <typename Derived>
6194StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006195 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006196 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006197 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006199
Douglas Gregorebe10102009-08-20 07:17:43 +00006200 // Transform the handlers.
6201 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006202 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006203 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006204 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006205 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006207
Douglas Gregorebe10102009-08-20 07:17:43 +00006208 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006209 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006210 }
Mike Stump11289f42009-09-09 15:08:12 +00006211
David Majnemer5f7efef2013-10-15 09:50:08 +00006212 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006213 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006214 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006215
John McCallb268a282010-08-23 23:25:46 +00006216 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006217 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006218}
Mike Stump11289f42009-09-09 15:08:12 +00006219
Richard Smith02e85f32011-04-14 22:09:26 +00006220template<typename Derived>
6221StmtResult
6222TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6223 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6224 if (Range.isInvalid())
6225 return StmtError();
6226
6227 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6228 if (BeginEnd.isInvalid())
6229 return StmtError();
6230
6231 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6232 if (Cond.isInvalid())
6233 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006234 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006235 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006236 if (Cond.isInvalid())
6237 return StmtError();
6238 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006239 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006240
6241 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6242 if (Inc.isInvalid())
6243 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006244 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006245 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006246
6247 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6248 if (LoopVar.isInvalid())
6249 return StmtError();
6250
6251 StmtResult NewStmt = S;
6252 if (getDerived().AlwaysRebuild() ||
6253 Range.get() != S->getRangeStmt() ||
6254 BeginEnd.get() != S->getBeginEndStmt() ||
6255 Cond.get() != S->getCond() ||
6256 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006257 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006258 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6259 S->getColonLoc(), Range.get(),
6260 BeginEnd.get(), Cond.get(),
6261 Inc.get(), LoopVar.get(),
6262 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006263 if (NewStmt.isInvalid())
6264 return StmtError();
6265 }
Richard Smith02e85f32011-04-14 22:09:26 +00006266
6267 StmtResult Body = getDerived().TransformStmt(S->getBody());
6268 if (Body.isInvalid())
6269 return StmtError();
6270
6271 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6272 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006273 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006274 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6275 S->getColonLoc(), Range.get(),
6276 BeginEnd.get(), Cond.get(),
6277 Inc.get(), LoopVar.get(),
6278 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006279 if (NewStmt.isInvalid())
6280 return StmtError();
6281 }
Richard Smith02e85f32011-04-14 22:09:26 +00006282
6283 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006284 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006285
6286 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6287}
6288
John Wiegley1c0675e2011-04-28 01:08:34 +00006289template<typename Derived>
6290StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006291TreeTransform<Derived>::TransformMSDependentExistsStmt(
6292 MSDependentExistsStmt *S) {
6293 // Transform the nested-name-specifier, if any.
6294 NestedNameSpecifierLoc QualifierLoc;
6295 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006296 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006297 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6298 if (!QualifierLoc)
6299 return StmtError();
6300 }
6301
6302 // Transform the declaration name.
6303 DeclarationNameInfo NameInfo = S->getNameInfo();
6304 if (NameInfo.getName()) {
6305 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6306 if (!NameInfo.getName())
6307 return StmtError();
6308 }
6309
6310 // Check whether anything changed.
6311 if (!getDerived().AlwaysRebuild() &&
6312 QualifierLoc == S->getQualifierLoc() &&
6313 NameInfo.getName() == S->getNameInfo().getName())
6314 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006315
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006316 // Determine whether this name exists, if we can.
6317 CXXScopeSpec SS;
6318 SS.Adopt(QualifierLoc);
6319 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006320 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006321 case Sema::IER_Exists:
6322 if (S->isIfExists())
6323 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006324
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006325 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6326
6327 case Sema::IER_DoesNotExist:
6328 if (S->isIfNotExists())
6329 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006330
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006331 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006333 case Sema::IER_Dependent:
6334 Dependent = true;
6335 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006336
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006337 case Sema::IER_Error:
6338 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006339 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006340
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006341 // We need to continue with the instantiation, so do so now.
6342 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6343 if (SubStmt.isInvalid())
6344 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006345
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006346 // If we have resolved the name, just transform to the substatement.
6347 if (!Dependent)
6348 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006349
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006350 // The name is still dependent, so build a dependent expression again.
6351 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6352 S->isIfExists(),
6353 QualifierLoc,
6354 NameInfo,
6355 SubStmt.get());
6356}
6357
6358template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006359ExprResult
6360TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6361 NestedNameSpecifierLoc QualifierLoc;
6362 if (E->getQualifierLoc()) {
6363 QualifierLoc
6364 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6365 if (!QualifierLoc)
6366 return ExprError();
6367 }
6368
6369 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6370 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6371 if (!PD)
6372 return ExprError();
6373
6374 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6375 if (Base.isInvalid())
6376 return ExprError();
6377
6378 return new (SemaRef.getASTContext())
6379 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6380 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6381 QualifierLoc, E->getMemberLoc());
6382}
6383
David Majnemerfad8f482013-10-15 09:33:02 +00006384template <typename Derived>
6385StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006386 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006387 if (TryBlock.isInvalid())
6388 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006389
6390 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006391 if (Handler.isInvalid())
6392 return StmtError();
6393
David Majnemerfad8f482013-10-15 09:33:02 +00006394 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6395 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006396 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006397
Warren Huntf6be4cb2014-07-25 20:52:51 +00006398 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6399 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006400}
6401
David Majnemerfad8f482013-10-15 09:33:02 +00006402template <typename Derived>
6403StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006404 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006405 if (Block.isInvalid())
6406 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006407
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006408 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006409}
6410
David Majnemerfad8f482013-10-15 09:33:02 +00006411template <typename Derived>
6412StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006413 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006414 if (FilterExpr.isInvalid())
6415 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006416
David Majnemer7e755502013-10-15 09:30:14 +00006417 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006418 if (Block.isInvalid())
6419 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006420
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006421 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6422 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006423}
6424
David Majnemerfad8f482013-10-15 09:33:02 +00006425template <typename Derived>
6426StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6427 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006428 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6429 else
6430 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6431}
6432
Nico Weber9b982072014-07-07 00:12:30 +00006433template<typename Derived>
6434StmtResult
6435TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6436 return S;
6437}
6438
Alexander Musman64d33f12014-06-04 07:53:32 +00006439//===----------------------------------------------------------------------===//
6440// OpenMP directive transformation
6441//===----------------------------------------------------------------------===//
6442template <typename Derived>
6443StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6444 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006445
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006446 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006447 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006448 ArrayRef<OMPClause *> Clauses = D->clauses();
6449 TClauses.reserve(Clauses.size());
6450 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6451 I != E; ++I) {
6452 if (*I) {
6453 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006454 if (Clause)
6455 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006456 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006457 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006458 }
6459 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006460 StmtResult AssociatedStmt;
6461 if (D->hasAssociatedStmt()) {
6462 if (!D->getAssociatedStmt()) {
6463 return StmtError();
6464 }
6465 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6466 if (AssociatedStmt.isInvalid()) {
6467 return StmtError();
6468 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006469 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006470 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006471 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006472 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006473
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006474 // Transform directive name for 'omp critical' directive.
6475 DeclarationNameInfo DirName;
6476 if (D->getDirectiveKind() == OMPD_critical) {
6477 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6478 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6479 }
6480
Alexander Musman64d33f12014-06-04 07:53:32 +00006481 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006482 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6483 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006484}
6485
Alexander Musman64d33f12014-06-04 07:53:32 +00006486template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006487StmtResult
6488TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6489 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006490 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6491 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006492 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6493 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6494 return Res;
6495}
6496
Alexander Musman64d33f12014-06-04 07:53:32 +00006497template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006498StmtResult
6499TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6500 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006501 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6502 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006503 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6504 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006505 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006506}
6507
Alexey Bataevf29276e2014-06-18 04:14:57 +00006508template <typename Derived>
6509StmtResult
6510TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6511 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006512 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6513 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006514 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6515 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6516 return Res;
6517}
6518
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006519template <typename Derived>
6520StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006521TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6522 DeclarationNameInfo DirName;
6523 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6524 D->getLocStart());
6525 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6526 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6527 return Res;
6528}
6529
6530template <typename Derived>
6531StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006532TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6533 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006534 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6535 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006536 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6537 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6538 return Res;
6539}
6540
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006541template <typename Derived>
6542StmtResult
6543TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6544 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006545 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6546 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006547 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6548 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6549 return Res;
6550}
6551
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006552template <typename Derived>
6553StmtResult
6554TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6555 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006556 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6557 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6559 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6560 return Res;
6561}
6562
Alexey Bataev4acb8592014-07-07 13:01:15 +00006563template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006564StmtResult
6565TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6566 DeclarationNameInfo DirName;
6567 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6568 D->getLocStart());
6569 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6570 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6571 return Res;
6572}
6573
6574template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006575StmtResult
6576TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6577 getDerived().getSema().StartOpenMPDSABlock(
6578 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6579 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6580 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6581 return Res;
6582}
6583
6584template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006585StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6586 OMPParallelForDirective *D) {
6587 DeclarationNameInfo DirName;
6588 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6589 nullptr, D->getLocStart());
6590 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6591 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6592 return Res;
6593}
6594
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006595template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006596StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6597 OMPParallelForSimdDirective *D) {
6598 DeclarationNameInfo DirName;
6599 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6600 nullptr, D->getLocStart());
6601 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6602 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6603 return Res;
6604}
6605
6606template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006607StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6608 OMPParallelSectionsDirective *D) {
6609 DeclarationNameInfo DirName;
6610 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6611 nullptr, D->getLocStart());
6612 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6613 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6614 return Res;
6615}
6616
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006617template <typename Derived>
6618StmtResult
6619TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6620 DeclarationNameInfo DirName;
6621 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6622 D->getLocStart());
6623 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6624 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6625 return Res;
6626}
6627
Alexey Bataev68446b72014-07-18 07:47:19 +00006628template <typename Derived>
6629StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6630 OMPTaskyieldDirective *D) {
6631 DeclarationNameInfo DirName;
6632 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6633 D->getLocStart());
6634 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6635 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6636 return Res;
6637}
6638
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006639template <typename Derived>
6640StmtResult
6641TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6642 DeclarationNameInfo DirName;
6643 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6644 D->getLocStart());
6645 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6646 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6647 return Res;
6648}
6649
Alexey Bataev2df347a2014-07-18 10:17:07 +00006650template <typename Derived>
6651StmtResult
6652TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6653 DeclarationNameInfo DirName;
6654 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6655 D->getLocStart());
6656 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6657 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6658 return Res;
6659}
6660
Alexey Bataev6125da92014-07-21 11:26:11 +00006661template <typename Derived>
6662StmtResult
6663TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6664 DeclarationNameInfo DirName;
6665 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6666 D->getLocStart());
6667 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6668 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6669 return Res;
6670}
6671
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006672template <typename Derived>
6673StmtResult
6674TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6675 DeclarationNameInfo DirName;
6676 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6677 D->getLocStart());
6678 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6679 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6680 return Res;
6681}
6682
Alexey Bataev0162e452014-07-22 10:10:35 +00006683template <typename Derived>
6684StmtResult
6685TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6686 DeclarationNameInfo DirName;
6687 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6688 D->getLocStart());
6689 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6690 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6691 return Res;
6692}
6693
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006694template <typename Derived>
6695StmtResult
6696TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6697 DeclarationNameInfo DirName;
6698 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6699 D->getLocStart());
6700 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6701 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6702 return Res;
6703}
6704
Alexey Bataev13314bf2014-10-09 04:18:56 +00006705template <typename Derived>
6706StmtResult
6707TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6708 DeclarationNameInfo DirName;
6709 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6710 D->getLocStart());
6711 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6712 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6713 return Res;
6714}
6715
Alexander Musman64d33f12014-06-04 07:53:32 +00006716//===----------------------------------------------------------------------===//
6717// OpenMP clause transformation
6718//===----------------------------------------------------------------------===//
6719template <typename Derived>
6720OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006721 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6722 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006723 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006724 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006725 C->getLParenLoc(), C->getLocEnd());
6726}
6727
Alexander Musman64d33f12014-06-04 07:53:32 +00006728template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006729OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6730 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6731 if (Cond.isInvalid())
6732 return nullptr;
6733 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6734 C->getLParenLoc(), C->getLocEnd());
6735}
6736
6737template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006738OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006739TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6740 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6741 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006742 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006743 return getDerived().RebuildOMPNumThreadsClause(
6744 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006745}
6746
Alexey Bataev62c87d22014-03-21 04:51:18 +00006747template <typename Derived>
6748OMPClause *
6749TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6750 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6751 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006752 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006753 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006754 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006755}
6756
Alexander Musman8bd31e62014-05-27 15:12:19 +00006757template <typename Derived>
6758OMPClause *
6759TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6760 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6761 if (E.isInvalid())
6762 return 0;
6763 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006764 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006765}
6766
Alexander Musman64d33f12014-06-04 07:53:32 +00006767template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006768OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006769TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006770 return getDerived().RebuildOMPDefaultClause(
6771 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6772 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006773}
6774
Alexander Musman64d33f12014-06-04 07:53:32 +00006775template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006776OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006777TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006778 return getDerived().RebuildOMPProcBindClause(
6779 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6780 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006781}
6782
Alexander Musman64d33f12014-06-04 07:53:32 +00006783template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006784OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006785TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6786 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6787 if (E.isInvalid())
6788 return nullptr;
6789 return getDerived().RebuildOMPScheduleClause(
6790 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6791 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6792}
6793
6794template <typename Derived>
6795OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006796TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6797 // No need to rebuild this clause, no template-dependent parameters.
6798 return C;
6799}
6800
6801template <typename Derived>
6802OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006803TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6804 // No need to rebuild this clause, no template-dependent parameters.
6805 return C;
6806}
6807
6808template <typename Derived>
6809OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006810TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6811 // No need to rebuild this clause, no template-dependent parameters.
6812 return C;
6813}
6814
6815template <typename Derived>
6816OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006817TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6818 // No need to rebuild this clause, no template-dependent parameters.
6819 return C;
6820}
6821
6822template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006823OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6824 // No need to rebuild this clause, no template-dependent parameters.
6825 return C;
6826}
6827
6828template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006829OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6830 // No need to rebuild this clause, no template-dependent parameters.
6831 return C;
6832}
6833
6834template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006835OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006836TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6837 // No need to rebuild this clause, no template-dependent parameters.
6838 return C;
6839}
6840
6841template <typename Derived>
6842OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006843TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6844 // No need to rebuild this clause, no template-dependent parameters.
6845 return C;
6846}
6847
6848template <typename Derived>
6849OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006850TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6851 // No need to rebuild this clause, no template-dependent parameters.
6852 return C;
6853}
6854
6855template <typename Derived>
6856OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006857TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006858 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006859 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006860 for (auto *VE : C->varlists()) {
6861 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006862 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006863 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006864 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006865 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006866 return getDerived().RebuildOMPPrivateClause(
6867 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006868}
6869
Alexander Musman64d33f12014-06-04 07:53:32 +00006870template <typename Derived>
6871OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6872 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006873 llvm::SmallVector<Expr *, 16> Vars;
6874 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006875 for (auto *VE : C->varlists()) {
6876 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006877 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006878 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006879 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006880 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006881 return getDerived().RebuildOMPFirstprivateClause(
6882 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006883}
6884
Alexander Musman64d33f12014-06-04 07:53:32 +00006885template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006886OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006887TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6888 llvm::SmallVector<Expr *, 16> Vars;
6889 Vars.reserve(C->varlist_size());
6890 for (auto *VE : C->varlists()) {
6891 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6892 if (EVar.isInvalid())
6893 return nullptr;
6894 Vars.push_back(EVar.get());
6895 }
6896 return getDerived().RebuildOMPLastprivateClause(
6897 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6898}
6899
6900template <typename Derived>
6901OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006902TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6903 llvm::SmallVector<Expr *, 16> Vars;
6904 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006905 for (auto *VE : C->varlists()) {
6906 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006907 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006908 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006909 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006910 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006911 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6912 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006913}
6914
Alexander Musman64d33f12014-06-04 07:53:32 +00006915template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006916OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006917TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6918 llvm::SmallVector<Expr *, 16> Vars;
6919 Vars.reserve(C->varlist_size());
6920 for (auto *VE : C->varlists()) {
6921 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6922 if (EVar.isInvalid())
6923 return nullptr;
6924 Vars.push_back(EVar.get());
6925 }
6926 CXXScopeSpec ReductionIdScopeSpec;
6927 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6928
6929 DeclarationNameInfo NameInfo = C->getNameInfo();
6930 if (NameInfo.getName()) {
6931 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6932 if (!NameInfo.getName())
6933 return nullptr;
6934 }
6935 return getDerived().RebuildOMPReductionClause(
6936 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6937 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6938}
6939
6940template <typename Derived>
6941OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006942TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6943 llvm::SmallVector<Expr *, 16> Vars;
6944 Vars.reserve(C->varlist_size());
6945 for (auto *VE : C->varlists()) {
6946 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6947 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006948 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006949 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006950 }
6951 ExprResult Step = getDerived().TransformExpr(C->getStep());
6952 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006953 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006954 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6955 C->getLParenLoc(),
6956 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006957}
6958
Alexander Musman64d33f12014-06-04 07:53:32 +00006959template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006960OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006961TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6962 llvm::SmallVector<Expr *, 16> Vars;
6963 Vars.reserve(C->varlist_size());
6964 for (auto *VE : C->varlists()) {
6965 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6966 if (EVar.isInvalid())
6967 return nullptr;
6968 Vars.push_back(EVar.get());
6969 }
6970 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6971 if (Alignment.isInvalid())
6972 return nullptr;
6973 return getDerived().RebuildOMPAlignedClause(
6974 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6975 C->getColonLoc(), C->getLocEnd());
6976}
6977
Alexander Musman64d33f12014-06-04 07:53:32 +00006978template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006979OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006980TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6981 llvm::SmallVector<Expr *, 16> Vars;
6982 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006983 for (auto *VE : C->varlists()) {
6984 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006985 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006986 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006987 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006988 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006989 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6990 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006991}
6992
Alexey Bataevbae9a792014-06-27 10:37:06 +00006993template <typename Derived>
6994OMPClause *
6995TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6996 llvm::SmallVector<Expr *, 16> Vars;
6997 Vars.reserve(C->varlist_size());
6998 for (auto *VE : C->varlists()) {
6999 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7000 if (EVar.isInvalid())
7001 return nullptr;
7002 Vars.push_back(EVar.get());
7003 }
7004 return getDerived().RebuildOMPCopyprivateClause(
7005 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7006}
7007
Alexey Bataev6125da92014-07-21 11:26:11 +00007008template <typename Derived>
7009OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7010 llvm::SmallVector<Expr *, 16> Vars;
7011 Vars.reserve(C->varlist_size());
7012 for (auto *VE : C->varlists()) {
7013 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7014 if (EVar.isInvalid())
7015 return nullptr;
7016 Vars.push_back(EVar.get());
7017 }
7018 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7019 C->getLParenLoc(), C->getLocEnd());
7020}
7021
Douglas Gregorebe10102009-08-20 07:17:43 +00007022//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007023// Expression transformation
7024//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007027TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007028 if (!E->isTypeDependent())
7029 return E;
7030
7031 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7032 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007033}
Mike Stump11289f42009-09-09 15:08:12 +00007034
7035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007037TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007038 NestedNameSpecifierLoc QualifierLoc;
7039 if (E->getQualifierLoc()) {
7040 QualifierLoc
7041 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7042 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007043 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007044 }
John McCallce546572009-12-08 09:08:17 +00007045
7046 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007047 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7048 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007049 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007051
John McCall815039a2010-08-17 21:27:17 +00007052 DeclarationNameInfo NameInfo = E->getNameInfo();
7053 if (NameInfo.getName()) {
7054 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7055 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007057 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007058
7059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007060 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007061 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007062 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007063 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007064
7065 // Mark it referenced in the new context regardless.
7066 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007067 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007068
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007069 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007070 }
John McCallce546572009-12-08 09:08:17 +00007071
Craig Topperc3ec1492014-05-26 06:22:03 +00007072 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007073 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007074 TemplateArgs = &TransArgs;
7075 TransArgs.setLAngleLoc(E->getLAngleLoc());
7076 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007077 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7078 E->getNumTemplateArgs(),
7079 TransArgs))
7080 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007081 }
7082
Chad Rosier1dcde962012-08-08 18:46:20 +00007083 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007084 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007085}
Mike Stump11289f42009-09-09 15:08:12 +00007086
Douglas Gregora16548e2009-08-11 05:31:07 +00007087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007088ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007089TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007090 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007091}
Mike Stump11289f42009-09-09 15:08:12 +00007092
Douglas Gregora16548e2009-08-11 05:31:07 +00007093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007095TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007096 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007097}
Mike Stump11289f42009-09-09 15:08:12 +00007098
Douglas Gregora16548e2009-08-11 05:31:07 +00007099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007101TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007103}
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregora16548e2009-08-11 05:31:07 +00007105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007107TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007108 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007109}
Mike Stump11289f42009-09-09 15:08:12 +00007110
Douglas Gregora16548e2009-08-11 05:31:07 +00007111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007113TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007114 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007115}
7116
7117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007118ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007119TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007120 if (FunctionDecl *FD = E->getDirectCallee())
7121 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007122 return SemaRef.MaybeBindToTemporary(E);
7123}
7124
7125template<typename Derived>
7126ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007127TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7128 ExprResult ControllingExpr =
7129 getDerived().TransformExpr(E->getControllingExpr());
7130 if (ControllingExpr.isInvalid())
7131 return ExprError();
7132
Chris Lattner01cf8db2011-07-20 06:58:45 +00007133 SmallVector<Expr *, 4> AssocExprs;
7134 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007135 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7136 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7137 if (TS) {
7138 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7139 if (!AssocType)
7140 return ExprError();
7141 AssocTypes.push_back(AssocType);
7142 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007143 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007144 }
7145
7146 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7147 if (AssocExpr.isInvalid())
7148 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007149 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007150 }
7151
7152 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7153 E->getDefaultLoc(),
7154 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007155 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007156 AssocTypes,
7157 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007158}
7159
7160template<typename Derived>
7161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007163 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007164 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007165 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007166
Douglas Gregora16548e2009-08-11 05:31:07 +00007167 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007168 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007169
John McCallb268a282010-08-23 23:25:46 +00007170 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 E->getRParen());
7172}
7173
Richard Smithdb2630f2012-10-21 03:28:35 +00007174/// \brief The operand of a unary address-of operator has special rules: it's
7175/// allowed to refer to a non-static member of a class even if there's no 'this'
7176/// object available.
7177template<typename Derived>
7178ExprResult
7179TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7180 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007181 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007182 else
7183 return getDerived().TransformExpr(E);
7184}
7185
Mike Stump11289f42009-09-09 15:08:12 +00007186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007188TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007189 ExprResult SubExpr;
7190 if (E->getOpcode() == UO_AddrOf)
7191 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7192 else
7193 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007196
Douglas Gregora16548e2009-08-11 05:31:07 +00007197 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007198 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007199
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7201 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007202 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007203}
Mike Stump11289f42009-09-09 15:08:12 +00007204
Douglas Gregora16548e2009-08-11 05:31:07 +00007205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007206ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007207TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7208 // Transform the type.
7209 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7210 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007211 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007212
Douglas Gregor882211c2010-04-28 22:16:22 +00007213 // Transform all of the components into components similar to what the
7214 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007215 // FIXME: It would be slightly more efficient in the non-dependent case to
7216 // just map FieldDecls, rather than requiring the rebuilder to look for
7217 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007218 // template code that we don't care.
7219 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007220 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007221 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007222 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007223 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7224 const Node &ON = E->getComponent(I);
7225 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007226 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007227 Comp.LocStart = ON.getSourceRange().getBegin();
7228 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007229 switch (ON.getKind()) {
7230 case Node::Array: {
7231 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007232 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007233 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007234 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007235
Douglas Gregor882211c2010-04-28 22:16:22 +00007236 ExprChanged = ExprChanged || Index.get() != FromIndex;
7237 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007238 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007239 break;
7240 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007241
Douglas Gregor882211c2010-04-28 22:16:22 +00007242 case Node::Field:
7243 case Node::Identifier:
7244 Comp.isBrackets = false;
7245 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007246 if (!Comp.U.IdentInfo)
7247 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007248
Douglas Gregor882211c2010-04-28 22:16:22 +00007249 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007250
Douglas Gregord1702062010-04-29 00:18:15 +00007251 case Node::Base:
7252 // Will be recomputed during the rebuild.
7253 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007254 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007255
Douglas Gregor882211c2010-04-28 22:16:22 +00007256 Components.push_back(Comp);
7257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007258
Douglas Gregor882211c2010-04-28 22:16:22 +00007259 // If nothing changed, retain the existing expression.
7260 if (!getDerived().AlwaysRebuild() &&
7261 Type == E->getTypeSourceInfo() &&
7262 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007263 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007264
Douglas Gregor882211c2010-04-28 22:16:22 +00007265 // Build a new offsetof expression.
7266 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7267 Components.data(), Components.size(),
7268 E->getRParenLoc());
7269}
7270
7271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007272ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007273TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7274 assert(getDerived().AlreadyTransformed(E->getType()) &&
7275 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007276 return E;
John McCall8d69a212010-11-15 23:31:06 +00007277}
7278
7279template<typename Derived>
7280ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007281TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007282 // Rebuild the syntactic form. The original syntactic form has
7283 // opaque-value expressions in it, so strip those away and rebuild
7284 // the result. This is a really awful way of doing this, but the
7285 // better solution (rebuilding the semantic expressions and
7286 // rebinding OVEs as necessary) doesn't work; we'd need
7287 // TreeTransform to not strip away implicit conversions.
7288 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7289 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007290 if (result.isInvalid()) return ExprError();
7291
7292 // If that gives us a pseudo-object result back, the pseudo-object
7293 // expression must have been an lvalue-to-rvalue conversion which we
7294 // should reapply.
7295 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007296 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007297
7298 return result;
7299}
7300
7301template<typename Derived>
7302ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007303TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7304 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007305 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007306 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007307
John McCallbcd03502009-12-07 02:54:59 +00007308 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007309 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007310 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007311
John McCall4c98fd82009-11-04 07:28:41 +00007312 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007313 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007314
Peter Collingbournee190dee2011-03-11 19:24:49 +00007315 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7316 E->getKind(),
7317 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007318 }
Mike Stump11289f42009-09-09 15:08:12 +00007319
Eli Friedmane4f22df2012-02-29 04:03:55 +00007320 // C++0x [expr.sizeof]p1:
7321 // The operand is either an expression, which is an unevaluated operand
7322 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007323 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7324 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007325
Reid Kleckner32506ed2014-06-12 23:03:48 +00007326 // Try to recover if we have something like sizeof(T::X) where X is a type.
7327 // Notably, there must be *exactly* one set of parens if X is a type.
7328 TypeSourceInfo *RecoveryTSI = nullptr;
7329 ExprResult SubExpr;
7330 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7331 if (auto *DRE =
7332 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7333 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7334 PE, DRE, false, &RecoveryTSI);
7335 else
7336 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7337
7338 if (RecoveryTSI) {
7339 return getDerived().RebuildUnaryExprOrTypeTrait(
7340 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7341 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007343
Eli Friedmane4f22df2012-02-29 04:03:55 +00007344 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007345 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007346
Peter Collingbournee190dee2011-03-11 19:24:49 +00007347 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7348 E->getOperatorLoc(),
7349 E->getKind(),
7350 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007351}
Mike Stump11289f42009-09-09 15:08:12 +00007352
Douglas Gregora16548e2009-08-11 05:31:07 +00007353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007354ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007355TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007356 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007358 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007359
John McCalldadc5752010-08-24 06:29:42 +00007360 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007361 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007363
7364
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 if (!getDerived().AlwaysRebuild() &&
7366 LHS.get() == E->getLHS() &&
7367 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007368 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007369
John McCallb268a282010-08-23 23:25:46 +00007370 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007372 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007373 E->getRBracketLoc());
7374}
Mike Stump11289f42009-09-09 15:08:12 +00007375
7376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007378TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007380 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007381 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007383
7384 // Transform arguments.
7385 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007386 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007387 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007388 &ArgChanged))
7389 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007390
Douglas Gregora16548e2009-08-11 05:31:07 +00007391 if (!getDerived().AlwaysRebuild() &&
7392 Callee.get() == E->getCallee() &&
7393 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007394 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007397 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007398 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007399 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007400 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 E->getRParenLoc());
7402}
Mike Stump11289f42009-09-09 15:08:12 +00007403
7404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007406TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007407 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregorea972d32011-02-28 21:54:11 +00007411 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007412 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007413 QualifierLoc
7414 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007415
Douglas Gregorea972d32011-02-28 21:54:11 +00007416 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007417 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007418 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007419 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007420
Eli Friedman2cfcef62009-12-04 06:40:45 +00007421 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007422 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7423 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007424 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007426
John McCall16df1e52010-03-30 21:47:33 +00007427 NamedDecl *FoundDecl = E->getFoundDecl();
7428 if (FoundDecl == E->getMemberDecl()) {
7429 FoundDecl = Member;
7430 } else {
7431 FoundDecl = cast_or_null<NamedDecl>(
7432 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7433 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007434 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007435 }
7436
Douglas Gregora16548e2009-08-11 05:31:07 +00007437 if (!getDerived().AlwaysRebuild() &&
7438 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007439 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007440 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007441 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007442 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007443
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007444 // Mark it referenced in the new context regardless.
7445 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007446 SemaRef.MarkMemberReferenced(E);
7447
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007448 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007449 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007450
John McCall6b51f282009-11-23 01:53:49 +00007451 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007452 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007453 TransArgs.setLAngleLoc(E->getLAngleLoc());
7454 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007455 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7456 E->getNumTemplateArgs(),
7457 TransArgs))
7458 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007460
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007462 SourceLocation FakeOperatorLoc =
7463 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007464
John McCall38836f02010-01-15 08:34:02 +00007465 // FIXME: to do this check properly, we will need to preserve the
7466 // first-qualifier-in-scope here, just in case we had a dependent
7467 // base (and therefore couldn't do the check) and a
7468 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007469 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007470
John McCallb268a282010-08-23 23:25:46 +00007471 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007473 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007474 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007475 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007476 Member,
John McCall16df1e52010-03-30 21:47:33 +00007477 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007478 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007479 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007480 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007481}
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregora16548e2009-08-11 05:31:07 +00007483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007485TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007486 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007487 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007489
John McCalldadc5752010-08-24 06:29:42 +00007490 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007491 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregora16548e2009-08-11 05:31:07 +00007494 if (!getDerived().AlwaysRebuild() &&
7495 LHS.get() == E->getLHS() &&
7496 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007497 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007498
Lang Hames5de91cc2012-10-02 04:45:10 +00007499 Sema::FPContractStateRAII FPContractState(getSema());
7500 getSema().FPFeatures.fp_contract = E->isFPContractable();
7501
Douglas Gregora16548e2009-08-11 05:31:07 +00007502 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007503 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007504}
7505
Mike Stump11289f42009-09-09 15:08:12 +00007506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007507ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007508TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007509 CompoundAssignOperator *E) {
7510 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007511}
Mike Stump11289f42009-09-09 15:08:12 +00007512
Douglas Gregora16548e2009-08-11 05:31:07 +00007513template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007514ExprResult TreeTransform<Derived>::
7515TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7516 // Just rebuild the common and RHS expressions and see whether we
7517 // get any changes.
7518
7519 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7520 if (commonExpr.isInvalid())
7521 return ExprError();
7522
7523 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7524 if (rhs.isInvalid())
7525 return ExprError();
7526
7527 if (!getDerived().AlwaysRebuild() &&
7528 commonExpr.get() == e->getCommon() &&
7529 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007530 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007531
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007532 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007533 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007534 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007535 e->getColonLoc(),
7536 rhs.get());
7537}
7538
7539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007541TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007542 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007545
John McCalldadc5752010-08-24 06:29:42 +00007546 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007549
John McCalldadc5752010-08-24 06:29:42 +00007550 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007553
Douglas Gregora16548e2009-08-11 05:31:07 +00007554 if (!getDerived().AlwaysRebuild() &&
7555 Cond.get() == E->getCond() &&
7556 LHS.get() == E->getLHS() &&
7557 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007558 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007559
John McCallb268a282010-08-23 23:25:46 +00007560 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007561 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007562 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007563 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007564 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007565}
Mike Stump11289f42009-09-09 15:08:12 +00007566
7567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007569TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007570 // Implicit casts are eliminated during transformation, since they
7571 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007572 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007573}
Mike Stump11289f42009-09-09 15:08:12 +00007574
Douglas Gregora16548e2009-08-11 05:31:07 +00007575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007577TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007578 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7579 if (!Type)
7580 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007581
John McCalldadc5752010-08-24 06:29:42 +00007582 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007583 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007584 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007588 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007590 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007591
John McCall97513962010-01-15 18:39:57 +00007592 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007593 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007595 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007596}
Mike Stump11289f42009-09-09 15:08:12 +00007597
Douglas Gregora16548e2009-08-11 05:31:07 +00007598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007600TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007601 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7602 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7603 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007605
John McCalldadc5752010-08-24 06:29:42 +00007606 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007608 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007609
Douglas Gregora16548e2009-08-11 05:31:07 +00007610 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007611 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007612 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007613 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007614
John McCall5d7aa7f2010-01-19 22:33:45 +00007615 // Note: the expression type doesn't necessarily match the
7616 // type-as-written, but that's okay, because it should always be
7617 // derivable from the initializer.
7618
John McCalle15bbff2010-01-18 19:35:47 +00007619 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007620 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007621 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007622}
Mike Stump11289f42009-09-09 15:08:12 +00007623
Douglas Gregora16548e2009-08-11 05:31:07 +00007624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007626TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007627 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 if (!getDerived().AlwaysRebuild() &&
7632 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007633 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007634
Douglas Gregora16548e2009-08-11 05:31:07 +00007635 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007636 SourceLocation FakeOperatorLoc =
7637 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007638 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007639 E->getAccessorLoc(),
7640 E->getAccessor());
7641}
Mike Stump11289f42009-09-09 15:08:12 +00007642
Douglas Gregora16548e2009-08-11 05:31:07 +00007643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007645TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007646 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007647
Benjamin Kramerf0623432012-08-23 22:51:59 +00007648 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007649 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007650 Inits, &InitChanged))
7651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007654 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007655
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007656 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007657 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007658}
Mike Stump11289f42009-09-09 15:08:12 +00007659
Douglas Gregora16548e2009-08-11 05:31:07 +00007660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007661ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007662TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007663 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007664
Douglas Gregorebe10102009-08-20 07:17:43 +00007665 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007666 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007669
Douglas Gregorebe10102009-08-20 07:17:43 +00007670 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007671 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007672 bool ExprChanged = false;
7673 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7674 DEnd = E->designators_end();
7675 D != DEnd; ++D) {
7676 if (D->isFieldDesignator()) {
7677 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7678 D->getDotLoc(),
7679 D->getFieldLoc()));
7680 continue;
7681 }
Mike Stump11289f42009-09-09 15:08:12 +00007682
Douglas Gregora16548e2009-08-11 05:31:07 +00007683 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007684 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007685 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007687
7688 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007690
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007692 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 continue;
7694 }
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007697 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007698 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7699 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007701
John McCalldadc5752010-08-24 06:29:42 +00007702 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007703 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007705
7706 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007707 End.get(),
7708 D->getLBracketLoc(),
7709 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7712 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007713
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007714 ArrayExprs.push_back(Start.get());
7715 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 }
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 if (!getDerived().AlwaysRebuild() &&
7719 Init.get() == E->getInit() &&
7720 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007721 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007722
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007723 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007725 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007726}
Mike Stump11289f42009-09-09 15:08:12 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007729ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007730TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007731 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007732 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007733
Douglas Gregor3da3c062009-10-28 00:29:27 +00007734 // FIXME: Will we ever have proper type location here? Will we actually
7735 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007736 QualType T = getDerived().TransformType(E->getType());
7737 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007739
Douglas Gregora16548e2009-08-11 05:31:07 +00007740 if (!getDerived().AlwaysRebuild() &&
7741 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007742 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007743
Douglas Gregora16548e2009-08-11 05:31:07 +00007744 return getDerived().RebuildImplicitValueInitExpr(T);
7745}
Mike Stump11289f42009-09-09 15:08:12 +00007746
Douglas Gregora16548e2009-08-11 05:31:07 +00007747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007748ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007749TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007750 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7751 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007753
John McCalldadc5752010-08-24 06:29:42 +00007754 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007755 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007756 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007757
Douglas Gregora16548e2009-08-11 05:31:07 +00007758 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007759 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007760 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007761 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007762
John McCallb268a282010-08-23 23:25:46 +00007763 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007764 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007765}
7766
7767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007769TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007771 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007772 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7773 &ArgumentChanged))
7774 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007775
Douglas Gregora16548e2009-08-11 05:31:07 +00007776 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007777 Inits,
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 +00007781/// \brief Transform an address-of-label expression.
7782///
7783/// By default, the transformation of an address-of-label expression always
7784/// rebuilds the expression, so that the label identifier can be resolved to
7785/// the corresponding label statement by semantic analysis.
7786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007788TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007789 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7790 E->getLabel());
7791 if (!LD)
7792 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007793
Douglas Gregora16548e2009-08-11 05:31:07 +00007794 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007795 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007796}
Mike Stump11289f42009-09-09 15:08:12 +00007797
7798template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007800TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007801 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007802 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007803 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007804 if (SubStmt.isInvalid()) {
7805 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007806 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007807 }
Mike Stump11289f42009-09-09 15:08:12 +00007808
Douglas Gregora16548e2009-08-11 05:31:07 +00007809 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007810 SubStmt.get() == E->getSubStmt()) {
7811 // Calling this an 'error' is unintuitive, but it does the right thing.
7812 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007813 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007814 }
Mike Stump11289f42009-09-09 15:08:12 +00007815
7816 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007817 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 E->getRParenLoc());
7819}
Mike Stump11289f42009-09-09 15:08:12 +00007820
Douglas Gregora16548e2009-08-11 05:31:07 +00007821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007823TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007824 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007825 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007827
John McCalldadc5752010-08-24 06:29:42 +00007828 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007829 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007831
John McCalldadc5752010-08-24 06:29:42 +00007832 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007833 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007835
Douglas Gregora16548e2009-08-11 05:31:07 +00007836 if (!getDerived().AlwaysRebuild() &&
7837 Cond.get() == E->getCond() &&
7838 LHS.get() == E->getLHS() &&
7839 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007840 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007841
Douglas Gregora16548e2009-08-11 05:31:07 +00007842 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007843 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007844 E->getRParenLoc());
7845}
Mike Stump11289f42009-09-09 15:08:12 +00007846
Douglas Gregora16548e2009-08-11 05:31:07 +00007847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007848ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007849TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007850 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007851}
7852
7853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007855TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007856 switch (E->getOperator()) {
7857 case OO_New:
7858 case OO_Delete:
7859 case OO_Array_New:
7860 case OO_Array_Delete:
7861 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007862
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007863 case OO_Call: {
7864 // This is a call to an object's operator().
7865 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7866
7867 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007868 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007869 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007870 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007871
7872 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007873 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7874 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007875
7876 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007877 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007878 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007879 Args))
7880 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007881
John McCallb268a282010-08-23 23:25:46 +00007882 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007883 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007884 E->getLocEnd());
7885 }
7886
7887#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7888 case OO_##Name:
7889#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7890#include "clang/Basic/OperatorKinds.def"
7891 case OO_Subscript:
7892 // Handled below.
7893 break;
7894
7895 case OO_Conditional:
7896 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007897
7898 case OO_None:
7899 case NUM_OVERLOADED_OPERATORS:
7900 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007901 }
7902
John McCalldadc5752010-08-24 06:29:42 +00007903 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007904 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007906
Richard Smithdb2630f2012-10-21 03:28:35 +00007907 ExprResult First;
7908 if (E->getOperator() == OO_Amp)
7909 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7910 else
7911 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007912 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007913 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007914
John McCalldadc5752010-08-24 06:29:42 +00007915 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007916 if (E->getNumArgs() == 2) {
7917 Second = getDerived().TransformExpr(E->getArg(1));
7918 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007919 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 }
Mike Stump11289f42009-09-09 15:08:12 +00007921
Douglas Gregora16548e2009-08-11 05:31:07 +00007922 if (!getDerived().AlwaysRebuild() &&
7923 Callee.get() == E->getCallee() &&
7924 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007925 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007926 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007927
Lang Hames5de91cc2012-10-02 04:45:10 +00007928 Sema::FPContractStateRAII FPContractState(getSema());
7929 getSema().FPFeatures.fp_contract = E->isFPContractable();
7930
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7932 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007933 Callee.get(),
7934 First.get(),
7935 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007936}
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregora16548e2009-08-11 05:31:07 +00007938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007940TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7941 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007942}
Mike Stump11289f42009-09-09 15:08:12 +00007943
Douglas Gregora16548e2009-08-11 05:31:07 +00007944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007945ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007946TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7947 // Transform the callee.
7948 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7949 if (Callee.isInvalid())
7950 return ExprError();
7951
7952 // Transform exec config.
7953 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7954 if (EC.isInvalid())
7955 return ExprError();
7956
7957 // Transform arguments.
7958 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007959 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007960 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007961 &ArgChanged))
7962 return ExprError();
7963
7964 if (!getDerived().AlwaysRebuild() &&
7965 Callee.get() == E->getCallee() &&
7966 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007967 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007968
7969 // FIXME: Wrong source location information for the '('.
7970 SourceLocation FakeLParenLoc
7971 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7972 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007973 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007974 E->getRParenLoc(), EC.get());
7975}
7976
7977template<typename Derived>
7978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007979TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007980 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7981 if (!Type)
7982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007983
John McCalldadc5752010-08-24 06:29:42 +00007984 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007985 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007986 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007988
Douglas Gregora16548e2009-08-11 05:31:07 +00007989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007990 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007992 return E;
Nico Weberc153d242014-07-28 00:02:09 +00007993 return getDerived().RebuildCXXNamedCastExpr(
7994 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
7995 Type, E->getAngleBrackets().getEnd(),
7996 // FIXME. this should be '(' location
7997 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007998}
Mike Stump11289f42009-09-09 15:08:12 +00007999
Douglas Gregora16548e2009-08-11 05:31:07 +00008000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008002TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8003 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008004}
Mike Stump11289f42009-09-09 15:08:12 +00008005
8006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008008TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8009 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008010}
8011
Douglas Gregora16548e2009-08-11 05:31:07 +00008012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008013ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008014TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008015 CXXReinterpretCastExpr *E) {
8016 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008017}
Mike Stump11289f42009-09-09 15:08:12 +00008018
Douglas Gregora16548e2009-08-11 05:31:07 +00008019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008021TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8022 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008023}
Mike Stump11289f42009-09-09 15:08:12 +00008024
Douglas Gregora16548e2009-08-11 05:31:07 +00008025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008026ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008027TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008028 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008029 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8030 if (!Type)
8031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008032
John McCalldadc5752010-08-24 06:29:42 +00008033 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008034 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008035 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008036 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008037
Douglas Gregora16548e2009-08-11 05:31:07 +00008038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008039 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008040 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008041 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008042
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008043 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008044 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008045 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008046 E->getRParenLoc());
8047}
Mike Stump11289f42009-09-09 15:08:12 +00008048
Douglas Gregora16548e2009-08-11 05:31:07 +00008049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008051TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008052 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008053 TypeSourceInfo *TInfo
8054 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8055 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008057
Douglas Gregora16548e2009-08-11 05:31:07 +00008058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008059 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008060 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008061
Douglas Gregor9da64192010-04-26 22:37:10 +00008062 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8063 E->getLocStart(),
8064 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008065 E->getLocEnd());
8066 }
Mike Stump11289f42009-09-09 15:08:12 +00008067
Eli Friedman456f0182012-01-20 01:26:23 +00008068 // We don't know whether the subexpression is potentially evaluated until
8069 // after we perform semantic analysis. We speculatively assume it is
8070 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008071 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008072 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8073 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008074
John McCalldadc5752010-08-24 06:29:42 +00008075 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008076 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008077 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008078
Douglas Gregora16548e2009-08-11 05:31:07 +00008079 if (!getDerived().AlwaysRebuild() &&
8080 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008081 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008082
Douglas Gregor9da64192010-04-26 22:37:10 +00008083 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8084 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008085 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008086 E->getLocEnd());
8087}
8088
8089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008090ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008091TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8092 if (E->isTypeOperand()) {
8093 TypeSourceInfo *TInfo
8094 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8095 if (!TInfo)
8096 return ExprError();
8097
8098 if (!getDerived().AlwaysRebuild() &&
8099 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008100 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008101
Douglas Gregor69735112011-03-06 17:40:41 +00008102 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008103 E->getLocStart(),
8104 TInfo,
8105 E->getLocEnd());
8106 }
8107
Francois Pichet9f4f2072010-09-08 12:20:18 +00008108 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8109
8110 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8111 if (SubExpr.isInvalid())
8112 return ExprError();
8113
8114 if (!getDerived().AlwaysRebuild() &&
8115 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008116 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008117
8118 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8119 E->getLocStart(),
8120 SubExpr.get(),
8121 E->getLocEnd());
8122}
8123
8124template<typename Derived>
8125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008126TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008127 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008128}
Mike Stump11289f42009-09-09 15:08:12 +00008129
Douglas Gregora16548e2009-08-11 05:31:07 +00008130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008131ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008132TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008133 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008134 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008135}
Mike Stump11289f42009-09-09 15:08:12 +00008136
Douglas Gregora16548e2009-08-11 05:31:07 +00008137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008138ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008139TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008140 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008141
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008142 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8143 // Make sure that we capture 'this'.
8144 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008145 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008146 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008147
Douglas Gregorb15af892010-01-07 23:12:05 +00008148 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008149}
Mike Stump11289f42009-09-09 15:08:12 +00008150
Douglas Gregora16548e2009-08-11 05:31:07 +00008151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008152ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008153TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008154 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008157
Douglas Gregora16548e2009-08-11 05:31:07 +00008158 if (!getDerived().AlwaysRebuild() &&
8159 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008160 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008161
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008162 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8163 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008164}
Mike Stump11289f42009-09-09 15:08:12 +00008165
Douglas Gregora16548e2009-08-11 05:31:07 +00008166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008168TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008169 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008170 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8171 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008172 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008174
Chandler Carruth794da4c2010-02-08 06:42:49 +00008175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008176 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008177 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008178
Douglas Gregor033f6752009-12-23 23:03:06 +00008179 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008180}
Mike Stump11289f42009-09-09 15:08:12 +00008181
Douglas Gregora16548e2009-08-11 05:31:07 +00008182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008183ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008184TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8185 FieldDecl *Field
8186 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8187 E->getField()));
8188 if (!Field)
8189 return ExprError();
8190
8191 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008192 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008193
8194 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8195}
8196
8197template<typename Derived>
8198ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008199TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8200 CXXScalarValueInitExpr *E) {
8201 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8202 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008203 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008204
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008206 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008207 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008208
Chad Rosier1dcde962012-08-08 18:46:20 +00008209 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008210 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008211 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008212}
Mike Stump11289f42009-09-09 15:08:12 +00008213
Douglas Gregora16548e2009-08-11 05:31:07 +00008214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008216TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008217 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008218 TypeSourceInfo *AllocTypeInfo
8219 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8220 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008221 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008222
Douglas Gregora16548e2009-08-11 05:31:07 +00008223 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008224 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228 // Transform the placement arguments (if any).
8229 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008230 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008231 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008232 E->getNumPlacementArgs(), true,
8233 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008234 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008235
Sebastian Redl6047f072012-02-16 12:22:20 +00008236 // Transform the initializer (if any).
8237 Expr *OldInit = E->getInitializer();
8238 ExprResult NewInit;
8239 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008240 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008241 if (NewInit.isInvalid())
8242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008243
Sebastian Redl6047f072012-02-16 12:22:20 +00008244 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008245 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008246 if (E->getOperatorNew()) {
8247 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008248 getDerived().TransformDecl(E->getLocStart(),
8249 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008250 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008251 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008252 }
8253
Craig Topperc3ec1492014-05-26 06:22:03 +00008254 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008255 if (E->getOperatorDelete()) {
8256 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008257 getDerived().TransformDecl(E->getLocStart(),
8258 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008259 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008260 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008262
Douglas Gregora16548e2009-08-11 05:31:07 +00008263 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008264 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008265 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008266 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008267 OperatorNew == E->getOperatorNew() &&
8268 OperatorDelete == E->getOperatorDelete() &&
8269 !ArgumentChanged) {
8270 // Mark any declarations we need as referenced.
8271 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008272 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008273 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008274 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008275 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008276
Sebastian Redl6047f072012-02-16 12:22:20 +00008277 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008278 QualType ElementType
8279 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8280 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8281 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8282 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008283 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008284 }
8285 }
8286 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008287
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008288 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008289 }
Mike Stump11289f42009-09-09 15:08:12 +00008290
Douglas Gregor0744ef62010-09-07 21:49:58 +00008291 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008292 if (!ArraySize.get()) {
8293 // If no array size was specified, but the new expression was
8294 // instantiated with an array type (e.g., "new T" where T is
8295 // instantiated with "int[4]"), extract the outer bound from the
8296 // array type as our array size. We do this with constant and
8297 // dependently-sized array types.
8298 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8299 if (!ArrayT) {
8300 // Do nothing
8301 } else if (const ConstantArrayType *ConsArrayT
8302 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008303 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8304 SemaRef.Context.getSizeType(),
8305 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008306 AllocType = ConsArrayT->getElementType();
8307 } else if (const DependentSizedArrayType *DepArrayT
8308 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8309 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008310 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008311 AllocType = DepArrayT->getElementType();
8312 }
8313 }
8314 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008315
Douglas Gregora16548e2009-08-11 05:31:07 +00008316 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8317 E->isGlobalNew(),
8318 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008319 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008321 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008322 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008323 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008324 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008325 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008326 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008327}
Mike Stump11289f42009-09-09 15:08:12 +00008328
Douglas Gregora16548e2009-08-11 05:31:07 +00008329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008331TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008332 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008333 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008334 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008335
Douglas Gregord2d9da02010-02-26 00:38:10 +00008336 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008337 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008338 if (E->getOperatorDelete()) {
8339 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008340 getDerived().TransformDecl(E->getLocStart(),
8341 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008342 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008343 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008345
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008347 Operand.get() == E->getArgument() &&
8348 OperatorDelete == E->getOperatorDelete()) {
8349 // Mark any declarations we need as referenced.
8350 // FIXME: instantiation-specific.
8351 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008352 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008353
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008354 if (!E->getArgument()->isTypeDependent()) {
8355 QualType Destroyed = SemaRef.Context.getBaseElementType(
8356 E->getDestroyedType());
8357 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8358 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008359 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008360 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008361 }
8362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008363
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008364 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008365 }
Mike Stump11289f42009-09-09 15:08:12 +00008366
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8368 E->isGlobalDelete(),
8369 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008370 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008371}
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008374ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008375TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008376 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008377 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008378 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008380
John McCallba7bf592010-08-24 05:47:05 +00008381 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008382 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008383 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008384 E->getOperatorLoc(),
8385 E->isArrow()? tok::arrow : tok::period,
8386 ObjectTypePtr,
8387 MayBePseudoDestructor);
8388 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008389 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008390
John McCallba7bf592010-08-24 05:47:05 +00008391 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008392 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8393 if (QualifierLoc) {
8394 QualifierLoc
8395 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8396 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008397 return ExprError();
8398 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008399 CXXScopeSpec SS;
8400 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008401
Douglas Gregor678f90d2010-02-25 01:56:36 +00008402 PseudoDestructorTypeStorage Destroyed;
8403 if (E->getDestroyedTypeInfo()) {
8404 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008405 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008406 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008407 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008408 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008409 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008410 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008411 // We aren't likely to be able to resolve the identifier down to a type
8412 // now anyway, so just retain the identifier.
8413 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8414 E->getDestroyedTypeLoc());
8415 } else {
8416 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008417 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008418 *E->getDestroyedTypeIdentifier(),
8419 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008420 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008421 SS, ObjectTypePtr,
8422 false);
8423 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008424 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008425
Douglas Gregor678f90d2010-02-25 01:56:36 +00008426 Destroyed
8427 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8428 E->getDestroyedTypeLoc());
8429 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008430
Craig Topperc3ec1492014-05-26 06:22:03 +00008431 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008432 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008433 CXXScopeSpec EmptySS;
8434 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008435 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008436 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008437 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008439
John McCallb268a282010-08-23 23:25:46 +00008440 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008441 E->getOperatorLoc(),
8442 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008443 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008444 ScopeTypeInfo,
8445 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008446 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008447 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008448}
Mike Stump11289f42009-09-09 15:08:12 +00008449
Douglas Gregorad8a3362009-09-04 17:36:40 +00008450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008451ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008452TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008453 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008454 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8455 Sema::LookupOrdinaryName);
8456
8457 // Transform all the decls.
8458 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8459 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008460 NamedDecl *InstD = static_cast<NamedDecl*>(
8461 getDerived().TransformDecl(Old->getNameLoc(),
8462 *I));
John McCall84d87672009-12-10 09:41:52 +00008463 if (!InstD) {
8464 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8465 // This can happen because of dependent hiding.
8466 if (isa<UsingShadowDecl>(*I))
8467 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008468 else {
8469 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008470 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008471 }
John McCall84d87672009-12-10 09:41:52 +00008472 }
John McCalle66edc12009-11-24 19:00:30 +00008473
8474 // Expand using declarations.
8475 if (isa<UsingDecl>(InstD)) {
8476 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008477 for (auto *I : UD->shadows())
8478 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008479 continue;
8480 }
8481
8482 R.addDecl(InstD);
8483 }
8484
8485 // Resolve a kind, but don't do any further analysis. If it's
8486 // ambiguous, the callee needs to deal with it.
8487 R.resolveKind();
8488
8489 // Rebuild the nested-name qualifier, if present.
8490 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008491 if (Old->getQualifierLoc()) {
8492 NestedNameSpecifierLoc QualifierLoc
8493 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8494 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008495 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008496
Douglas Gregor0da1d432011-02-28 20:01:57 +00008497 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008498 }
8499
Douglas Gregor9262f472010-04-27 18:19:34 +00008500 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008501 CXXRecordDecl *NamingClass
8502 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8503 Old->getNameLoc(),
8504 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008505 if (!NamingClass) {
8506 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008507 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008509
Douglas Gregorda7be082010-04-27 16:10:10 +00008510 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008511 }
8512
Abramo Bagnara7945c982012-01-27 09:46:47 +00008513 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8514
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008515 // If we have neither explicit template arguments, nor the template keyword,
8516 // it's a normal declaration name.
8517 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008518 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8519
8520 // If we have template arguments, rebuild them, then rebuild the
8521 // templateid expression.
8522 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008523 if (Old->hasExplicitTemplateArgs() &&
8524 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008525 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008526 TransArgs)) {
8527 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008528 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008529 }
John McCalle66edc12009-11-24 19:00:30 +00008530
Abramo Bagnara7945c982012-01-27 09:46:47 +00008531 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008532 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008533}
Mike Stump11289f42009-09-09 15:08:12 +00008534
Douglas Gregora16548e2009-08-11 05:31:07 +00008535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008536ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008537TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8538 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008539 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008540 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8541 TypeSourceInfo *From = E->getArg(I);
8542 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008543 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008544 TypeLocBuilder TLB;
8545 TLB.reserve(FromTL.getFullDataSize());
8546 QualType To = getDerived().TransformType(TLB, FromTL);
8547 if (To.isNull())
8548 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008549
Douglas Gregor29c42f22012-02-24 07:38:34 +00008550 if (To == From->getType())
8551 Args.push_back(From);
8552 else {
8553 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8554 ArgChanged = true;
8555 }
8556 continue;
8557 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008558
Douglas Gregor29c42f22012-02-24 07:38:34 +00008559 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008560
Douglas Gregor29c42f22012-02-24 07:38:34 +00008561 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008562 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008563 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8564 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8565 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008566
Douglas Gregor29c42f22012-02-24 07:38:34 +00008567 // Determine whether the set of unexpanded parameter packs can and should
8568 // be expanded.
8569 bool Expand = true;
8570 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008571 Optional<unsigned> OrigNumExpansions =
8572 ExpansionTL.getTypePtr()->getNumExpansions();
8573 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008574 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8575 PatternTL.getSourceRange(),
8576 Unexpanded,
8577 Expand, RetainExpansion,
8578 NumExpansions))
8579 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008580
Douglas Gregor29c42f22012-02-24 07:38:34 +00008581 if (!Expand) {
8582 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008583 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008584 // expansion.
8585 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008586
Douglas Gregor29c42f22012-02-24 07:38:34 +00008587 TypeLocBuilder TLB;
8588 TLB.reserve(From->getTypeLoc().getFullDataSize());
8589
8590 QualType To = getDerived().TransformType(TLB, PatternTL);
8591 if (To.isNull())
8592 return ExprError();
8593
Chad Rosier1dcde962012-08-08 18:46:20 +00008594 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008595 PatternTL.getSourceRange(),
8596 ExpansionTL.getEllipsisLoc(),
8597 NumExpansions);
8598 if (To.isNull())
8599 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008600
Douglas Gregor29c42f22012-02-24 07:38:34 +00008601 PackExpansionTypeLoc ToExpansionTL
8602 = TLB.push<PackExpansionTypeLoc>(To);
8603 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8604 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8605 continue;
8606 }
8607
8608 // Expand the pack expansion by substituting for each argument in the
8609 // pack(s).
8610 for (unsigned I = 0; I != *NumExpansions; ++I) {
8611 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8612 TypeLocBuilder TLB;
8613 TLB.reserve(PatternTL.getFullDataSize());
8614 QualType To = getDerived().TransformType(TLB, PatternTL);
8615 if (To.isNull())
8616 return ExprError();
8617
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008618 if (To->containsUnexpandedParameterPack()) {
8619 To = getDerived().RebuildPackExpansionType(To,
8620 PatternTL.getSourceRange(),
8621 ExpansionTL.getEllipsisLoc(),
8622 NumExpansions);
8623 if (To.isNull())
8624 return ExprError();
8625
8626 PackExpansionTypeLoc ToExpansionTL
8627 = TLB.push<PackExpansionTypeLoc>(To);
8628 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8629 }
8630
Douglas Gregor29c42f22012-02-24 07:38:34 +00008631 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008633
Douglas Gregor29c42f22012-02-24 07:38:34 +00008634 if (!RetainExpansion)
8635 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008636
Douglas Gregor29c42f22012-02-24 07:38:34 +00008637 // If we're supposed to retain a pack expansion, do so by temporarily
8638 // forgetting the partially-substituted parameter pack.
8639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8640
8641 TypeLocBuilder TLB;
8642 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008643
Douglas Gregor29c42f22012-02-24 07:38:34 +00008644 QualType To = getDerived().TransformType(TLB, PatternTL);
8645 if (To.isNull())
8646 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008647
8648 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008649 PatternTL.getSourceRange(),
8650 ExpansionTL.getEllipsisLoc(),
8651 NumExpansions);
8652 if (To.isNull())
8653 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008654
Douglas Gregor29c42f22012-02-24 07:38:34 +00008655 PackExpansionTypeLoc ToExpansionTL
8656 = TLB.push<PackExpansionTypeLoc>(To);
8657 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8658 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8659 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008660
Douglas Gregor29c42f22012-02-24 07:38:34 +00008661 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008662 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008663
8664 return getDerived().RebuildTypeTrait(E->getTrait(),
8665 E->getLocStart(),
8666 Args,
8667 E->getLocEnd());
8668}
8669
8670template<typename Derived>
8671ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008672TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8673 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8674 if (!T)
8675 return ExprError();
8676
8677 if (!getDerived().AlwaysRebuild() &&
8678 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008679 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008680
8681 ExprResult SubExpr;
8682 {
8683 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8684 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8685 if (SubExpr.isInvalid())
8686 return ExprError();
8687
8688 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008689 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008690 }
8691
8692 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8693 E->getLocStart(),
8694 T,
8695 SubExpr.get(),
8696 E->getLocEnd());
8697}
8698
8699template<typename Derived>
8700ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008701TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8702 ExprResult SubExpr;
8703 {
8704 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8705 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8706 if (SubExpr.isInvalid())
8707 return ExprError();
8708
8709 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008710 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008711 }
8712
8713 return getDerived().RebuildExpressionTrait(
8714 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8715}
8716
Reid Kleckner32506ed2014-06-12 23:03:48 +00008717template <typename Derived>
8718ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8719 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8720 TypeSourceInfo **RecoveryTSI) {
8721 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8722 DRE, AddrTaken, RecoveryTSI);
8723
8724 // Propagate both errors and recovered types, which return ExprEmpty.
8725 if (!NewDRE.isUsable())
8726 return NewDRE;
8727
8728 // We got an expr, wrap it up in parens.
8729 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8730 return PE;
8731 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8732 PE->getRParen());
8733}
8734
8735template <typename Derived>
8736ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8737 DependentScopeDeclRefExpr *E) {
8738 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8739 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008740}
8741
8742template<typename Derived>
8743ExprResult
8744TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8745 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008746 bool IsAddressOfOperand,
8747 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008748 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008749 NestedNameSpecifierLoc QualifierLoc
8750 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8751 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008752 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008753 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008754
John McCall31f82722010-11-12 08:19:04 +00008755 // TODO: If this is a conversion-function-id, verify that the
8756 // destination type name (if present) resolves the same way after
8757 // instantiation as it did in the local scope.
8758
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008759 DeclarationNameInfo NameInfo
8760 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8761 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008763
John McCalle66edc12009-11-24 19:00:30 +00008764 if (!E->hasExplicitTemplateArgs()) {
8765 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008766 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008767 // Note: it is sufficient to compare the Name component of NameInfo:
8768 // if name has not changed, DNLoc has not changed either.
8769 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008770 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008771
Reid Kleckner32506ed2014-06-12 23:03:48 +00008772 return getDerived().RebuildDependentScopeDeclRefExpr(
8773 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8774 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008775 }
John McCall6b51f282009-11-23 01:53:49 +00008776
8777 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008778 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8779 E->getNumTemplateArgs(),
8780 TransArgs))
8781 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008782
Reid Kleckner32506ed2014-06-12 23:03:48 +00008783 return getDerived().RebuildDependentScopeDeclRefExpr(
8784 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8785 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008786}
8787
8788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008790TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008791 // CXXConstructExprs other than for list-initialization and
8792 // CXXTemporaryObjectExpr are always implicit, so when we have
8793 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008794 if ((E->getNumArgs() == 1 ||
8795 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008796 (!getDerived().DropCallArgument(E->getArg(0))) &&
8797 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008798 return getDerived().TransformExpr(E->getArg(0));
8799
Douglas Gregora16548e2009-08-11 05:31:07 +00008800 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8801
8802 QualType T = getDerived().TransformType(E->getType());
8803 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008804 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008805
8806 CXXConstructorDecl *Constructor
8807 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008808 getDerived().TransformDecl(E->getLocStart(),
8809 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008810 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008812
Douglas Gregora16548e2009-08-11 05:31:07 +00008813 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008814 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008815 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008816 &ArgumentChanged))
8817 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008818
Douglas Gregora16548e2009-08-11 05:31:07 +00008819 if (!getDerived().AlwaysRebuild() &&
8820 T == E->getType() &&
8821 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008822 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008823 // Mark the constructor as referenced.
8824 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008825 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008826 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008827 }
Mike Stump11289f42009-09-09 15:08:12 +00008828
Douglas Gregordb121ba2009-12-14 16:27:04 +00008829 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8830 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008831 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008832 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008833 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008834 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008835 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008836 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008837 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008838}
Mike Stump11289f42009-09-09 15:08:12 +00008839
Douglas Gregora16548e2009-08-11 05:31:07 +00008840/// \brief Transform a C++ temporary-binding expression.
8841///
Douglas Gregor363b1512009-12-24 18:51:59 +00008842/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8843/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008846TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008847 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008848}
Mike Stump11289f42009-09-09 15:08:12 +00008849
John McCall5d413782010-12-06 08:20:24 +00008850/// \brief Transform a C++ expression that contains cleanups that should
8851/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008852///
John McCall5d413782010-12-06 08:20:24 +00008853/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008854/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008856ExprResult
John McCall5d413782010-12-06 08:20:24 +00008857TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008858 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008859}
Mike Stump11289f42009-09-09 15:08:12 +00008860
Douglas Gregora16548e2009-08-11 05:31:07 +00008861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008862ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008863TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008864 CXXTemporaryObjectExpr *E) {
8865 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8866 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008868
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 CXXConstructorDecl *Constructor
8870 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008871 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008872 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008873 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008875
Douglas Gregora16548e2009-08-11 05:31:07 +00008876 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008877 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008878 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008879 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008880 &ArgumentChanged))
8881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008882
Douglas Gregora16548e2009-08-11 05:31:07 +00008883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008884 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008885 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008886 !ArgumentChanged) {
8887 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008888 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008889 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008891
Richard Smithd59b8322012-12-19 01:39:02 +00008892 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008893 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8894 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008895 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 E->getLocEnd());
8897}
Mike Stump11289f42009-09-09 15:08:12 +00008898
Douglas Gregora16548e2009-08-11 05:31:07 +00008899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008900ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008901TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008902
8903 // Transform any init-capture expressions before entering the scope of the
8904 // lambda body, because they are not semantically within that scope.
8905 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8906 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8907 E->explicit_capture_begin());
8908
8909 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8910 CEnd = E->capture_end();
8911 C != CEnd; ++C) {
8912 if (!C->isInitCapture())
8913 continue;
8914 EnterExpressionEvaluationContext EEEC(getSema(),
8915 Sema::PotentiallyEvaluated);
8916 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8917 C->getCapturedVar()->getInit(),
8918 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8919
8920 if (NewExprInitResult.isInvalid())
8921 return ExprError();
8922 Expr *NewExprInit = NewExprInitResult.get();
8923
8924 VarDecl *OldVD = C->getCapturedVar();
8925 QualType NewInitCaptureType =
8926 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8927 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8928 NewExprInit);
8929 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008930 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8931 std::make_pair(NewExprInitResult, NewInitCaptureType);
8932
8933 }
8934
Faisal Vali524ca282013-11-12 01:40:44 +00008935 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008936 // Transform the template parameters, and add them to the current
8937 // instantiation scope. The null case is handled correctly.
8938 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8939 E->getTemplateParameterList());
8940
8941 // Check to see if the TypeSourceInfo of the call operator needs to
8942 // be transformed, and if so do the transformation in the
8943 // CurrentInstantiationScope.
8944
8945 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8946 FunctionProtoTypeLoc OldCallOpFPTL =
8947 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008948 TypeSourceInfo *NewCallOpTSI = nullptr;
8949
Faisal Vali2cba1332013-10-23 06:44:28 +00008950 const bool CallOpWasAlreadyTransformed =
8951 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8952
8953 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8954 if (CallOpWasAlreadyTransformed)
8955 NewCallOpTSI = OldCallOpTSI;
8956 else {
8957 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8958 // The transformation MUST be done in the CurrentInstantiationScope since
8959 // it introduces a mapping of the original to the newly created
8960 // transformed parameters.
8961
8962 TypeLocBuilder NewCallOpTLBuilder;
Hans Wennborge113c202014-09-18 16:01:32 +00008963 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8964 OldCallOpFPTL,
8965 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008966 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8967 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008968 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008969 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8970 // the vector below - this will be used to synthesize the
8971 // NewCallOperator. Additionally, add the parameters of the untransformed
8972 // lambda call operator to the CurrentInstantiationScope.
8973 SmallVector<ParmVarDecl *, 4> Params;
8974 {
8975 FunctionProtoTypeLoc NewCallOpFPTL =
8976 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8977 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008978 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008979
8980 for (unsigned I = 0; I < NewNumArgs; ++I) {
8981 // If this call operator's type does not require transformation,
8982 // the parameters do not get added to the current instantiation scope,
8983 // - so ADD them! This allows the following to compile when the enclosing
8984 // template is specialized and the entire lambda expression has to be
8985 // transformed.
8986 // template<class T> void foo(T t) {
8987 // auto L = [](auto a) {
8988 // auto M = [](char b) { <-- note: non-generic lambda
8989 // auto N = [](auto c) {
8990 // int x = sizeof(a);
8991 // x = sizeof(b); <-- specifically this line
8992 // x = sizeof(c);
8993 // };
8994 // };
8995 // };
8996 // }
8997 // foo('a')
8998 if (CallOpWasAlreadyTransformed)
8999 getDerived().transformedLocalDecl(NewParamDeclArray[I],
9000 NewParamDeclArray[I]);
9001 // Add to Params array, so these parameters can be used to create
9002 // the newly transformed call operator.
9003 Params.push_back(NewParamDeclArray[I]);
9004 }
9005 }
9006
9007 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009008 return ExprError();
9009
Eli Friedmand564afb2012-09-19 01:18:11 +00009010 // Create the local class that will describe the lambda.
9011 CXXRecordDecl *Class
9012 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009013 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009014 /*KnownDependent=*/false,
9015 E->getCaptureDefault());
9016
Eli Friedmand564afb2012-09-19 01:18:11 +00009017 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9018
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009019 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00009020 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009021 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009022 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00009023 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00009024 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00009025 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009026
Faisal Vali2cba1332013-10-23 06:44:28 +00009027 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9028
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009029 return getDerived().TransformLambdaScope(E, NewCallOperator,
9030 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00009031}
9032
9033template<typename Derived>
9034ExprResult
9035TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009036 CXXMethodDecl *CallOperator,
9037 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00009038 bool Invalid = false;
9039
Douglas Gregorb4328232012-02-14 00:00:48 +00009040 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009041 Sema::ContextRAII SavedContext(getSema(), CallOperator,
9042 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009043
Faisal Vali2b391ab2013-09-26 19:54:12 +00009044 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009045 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009046 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009047 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009048 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009049 E->hasExplicitParameters(),
9050 E->hasExplicitResultType(),
9051 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009052
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009053 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009054 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009055 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009056 CEnd = E->capture_end();
9057 C != CEnd; ++C) {
9058 // When we hit the first implicit capture, tell Sema that we've finished
9059 // the list of explicit captures.
9060 if (!FinishedExplicitCaptures && C->isImplicit()) {
9061 getSema().finishLambdaExplicitCaptures(LSI);
9062 FinishedExplicitCaptures = true;
9063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009064
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009065 // Capturing 'this' is trivial.
9066 if (C->capturesThis()) {
9067 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9068 continue;
9069 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009070 // Captured expression will be recaptured during captured variables
9071 // rebuilding.
9072 if (C->capturesVLAType())
9073 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009074
Richard Smithba71c082013-05-16 06:20:58 +00009075 // Rebuild init-captures, including the implied field declaration.
9076 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009077
9078 InitCaptureInfoTy InitExprTypePair =
9079 InitCaptureExprsAndTypes[C - E->capture_begin()];
9080 ExprResult Init = InitExprTypePair.first;
9081 QualType InitQualType = InitExprTypePair.second;
9082 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009083 Invalid = true;
9084 continue;
9085 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009086 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009087 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9088 OldVD->getLocation(), InitExprTypePair.second,
9089 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009090 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009091 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009092 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009093 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009094 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009095 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009096 continue;
9097 }
9098
9099 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9100
Douglas Gregor3e308b12012-02-14 19:27:52 +00009101 // Determine the capture kind for Sema.
9102 Sema::TryCaptureKind Kind
9103 = C->isImplicit()? Sema::TryCapture_Implicit
9104 : C->getCaptureKind() == LCK_ByCopy
9105 ? Sema::TryCapture_ExplicitByVal
9106 : Sema::TryCapture_ExplicitByRef;
9107 SourceLocation EllipsisLoc;
9108 if (C->isPackExpansion()) {
9109 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9110 bool ShouldExpand = false;
9111 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009112 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009113 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9114 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009115 Unexpanded,
9116 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009117 NumExpansions)) {
9118 Invalid = true;
9119 continue;
9120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
Douglas Gregor3e308b12012-02-14 19:27:52 +00009122 if (ShouldExpand) {
9123 // The transform has determined that we should perform an expansion;
9124 // transform and capture each of the arguments.
9125 // expansion of the pattern. Do so.
9126 VarDecl *Pack = C->getCapturedVar();
9127 for (unsigned I = 0; I != *NumExpansions; ++I) {
9128 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9129 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009130 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009131 Pack));
9132 if (!CapturedVar) {
9133 Invalid = true;
9134 continue;
9135 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009136
Douglas Gregor3e308b12012-02-14 19:27:52 +00009137 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009138 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9139 }
Richard Smith9467be42014-06-06 17:33:35 +00009140
9141 // FIXME: Retain a pack expansion if RetainExpansion is true.
9142
Douglas Gregor3e308b12012-02-14 19:27:52 +00009143 continue;
9144 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009145
Douglas Gregor3e308b12012-02-14 19:27:52 +00009146 EllipsisLoc = C->getEllipsisLoc();
9147 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009148
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009149 // Transform the captured variable.
9150 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009151 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009152 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009153 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009154 Invalid = true;
9155 continue;
9156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009157
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009158 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009159 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009160 }
9161 if (!FinishedExplicitCaptures)
9162 getSema().finishLambdaExplicitCaptures(LSI);
9163
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009164
9165 // Enter a new evaluation context to insulate the lambda from any
9166 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009167 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009168
9169 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009170 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009171 /*IsInstantiation=*/true);
9172 return ExprError();
9173 }
9174
9175 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009176 StmtResult Body = getDerived().TransformStmt(E->getBody());
9177 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009178 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009179 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009180 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009181 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009182
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009183 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009184 /*CurScope=*/nullptr,
9185 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009186}
9187
9188template<typename Derived>
9189ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009190TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009191 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009192 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9193 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009195
Douglas Gregora16548e2009-08-11 05:31:07 +00009196 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009197 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009198 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009199 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009200 &ArgumentChanged))
9201 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009202
Douglas Gregora16548e2009-08-11 05:31:07 +00009203 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009204 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009205 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009206 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009207
Douglas Gregora16548e2009-08-11 05:31:07 +00009208 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009209 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009210 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009211 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009212 E->getRParenLoc());
9213}
Mike Stump11289f42009-09-09 15:08:12 +00009214
Douglas Gregora16548e2009-08-11 05:31:07 +00009215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009216ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009217TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009218 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009219 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009220 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009221 Expr *OldBase;
9222 QualType BaseType;
9223 QualType ObjectType;
9224 if (!E->isImplicitAccess()) {
9225 OldBase = E->getBase();
9226 Base = getDerived().TransformExpr(OldBase);
9227 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009228 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009229
John McCall2d74de92009-12-01 22:10:20 +00009230 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009231 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009232 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009233 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009234 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009235 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009236 ObjectTy,
9237 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009238 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009239 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009240
John McCallba7bf592010-08-24 05:47:05 +00009241 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009242 BaseType = ((Expr*) Base.get())->getType();
9243 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009244 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009245 BaseType = getDerived().TransformType(E->getBaseType());
9246 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9247 }
Mike Stump11289f42009-09-09 15:08:12 +00009248
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009249 // Transform the first part of the nested-name-specifier that qualifies
9250 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009251 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009252 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009253 E->getFirstQualifierFoundInScope(),
9254 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009255
Douglas Gregore16af532011-02-28 18:50:33 +00009256 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009257 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009258 QualifierLoc
9259 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9260 ObjectType,
9261 FirstQualifierInScope);
9262 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009263 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009264 }
Mike Stump11289f42009-09-09 15:08:12 +00009265
Abramo Bagnara7945c982012-01-27 09:46:47 +00009266 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9267
John McCall31f82722010-11-12 08:19:04 +00009268 // TODO: If this is a conversion-function-id, verify that the
9269 // destination type name (if present) resolves the same way after
9270 // instantiation as it did in the local scope.
9271
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009272 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009273 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009274 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009276
John McCall2d74de92009-12-01 22:10:20 +00009277 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009278 // This is a reference to a member without an explicitly-specified
9279 // template argument list. Optimize for this common case.
9280 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009281 Base.get() == OldBase &&
9282 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009283 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009284 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009285 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009286 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009287
John McCallb268a282010-08-23 23:25:46 +00009288 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009289 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009290 E->isArrow(),
9291 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009292 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009293 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009294 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009295 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009296 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009297 }
9298
John McCall6b51f282009-11-23 01:53:49 +00009299 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009300 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9301 E->getNumTemplateArgs(),
9302 TransArgs))
9303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009304
John McCallb268a282010-08-23 23:25:46 +00009305 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009306 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009307 E->isArrow(),
9308 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009309 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009310 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009311 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009312 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009313 &TransArgs);
9314}
9315
9316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009318TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009319 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009320 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009321 QualType BaseType;
9322 if (!Old->isImplicitAccess()) {
9323 Base = getDerived().TransformExpr(Old->getBase());
9324 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009325 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009326 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009327 Old->isArrow());
9328 if (Base.isInvalid())
9329 return ExprError();
9330 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009331 } else {
9332 BaseType = getDerived().TransformType(Old->getBaseType());
9333 }
John McCall10eae182009-11-30 22:42:35 +00009334
Douglas Gregor0da1d432011-02-28 20:01:57 +00009335 NestedNameSpecifierLoc QualifierLoc;
9336 if (Old->getQualifierLoc()) {
9337 QualifierLoc
9338 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9339 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009340 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009341 }
9342
Abramo Bagnara7945c982012-01-27 09:46:47 +00009343 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9344
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009345 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009346 Sema::LookupOrdinaryName);
9347
9348 // Transform all the decls.
9349 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9350 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009351 NamedDecl *InstD = static_cast<NamedDecl*>(
9352 getDerived().TransformDecl(Old->getMemberLoc(),
9353 *I));
John McCall84d87672009-12-10 09:41:52 +00009354 if (!InstD) {
9355 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9356 // This can happen because of dependent hiding.
9357 if (isa<UsingShadowDecl>(*I))
9358 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009359 else {
9360 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009361 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009362 }
John McCall84d87672009-12-10 09:41:52 +00009363 }
John McCall10eae182009-11-30 22:42:35 +00009364
9365 // Expand using declarations.
9366 if (isa<UsingDecl>(InstD)) {
9367 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009368 for (auto *I : UD->shadows())
9369 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009370 continue;
9371 }
9372
9373 R.addDecl(InstD);
9374 }
9375
9376 R.resolveKind();
9377
Douglas Gregor9262f472010-04-27 18:19:34 +00009378 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009379 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009380 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009381 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009382 Old->getMemberLoc(),
9383 Old->getNamingClass()));
9384 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009385 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009386
Douglas Gregorda7be082010-04-27 16:10:10 +00009387 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009388 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009389
John McCall10eae182009-11-30 22:42:35 +00009390 TemplateArgumentListInfo TransArgs;
9391 if (Old->hasExplicitTemplateArgs()) {
9392 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9393 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009394 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9395 Old->getNumTemplateArgs(),
9396 TransArgs))
9397 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009398 }
John McCall38836f02010-01-15 08:34:02 +00009399
9400 // FIXME: to do this check properly, we will need to preserve the
9401 // first-qualifier-in-scope here, just in case we had a dependent
9402 // base (and therefore couldn't do the check) and a
9403 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009404 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009405
John McCallb268a282010-08-23 23:25:46 +00009406 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009407 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009408 Old->getOperatorLoc(),
9409 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009410 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009411 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009412 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009413 R,
9414 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009415 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009416}
9417
9418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009419ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009420TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009422 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9423 if (SubExpr.isInvalid())
9424 return ExprError();
9425
9426 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009427 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009428
9429 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9430}
9431
9432template<typename Derived>
9433ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009434TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009435 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9436 if (Pattern.isInvalid())
9437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009438
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009439 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009440 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009441
Douglas Gregorb8840002011-01-14 21:20:45 +00009442 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9443 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009444}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009445
9446template<typename Derived>
9447ExprResult
9448TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9449 // If E is not value-dependent, then nothing will change when we transform it.
9450 // Note: This is an instantiation-centric view.
9451 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009452 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009453
9454 // Note: None of the implementations of TryExpandParameterPacks can ever
9455 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009456 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009457 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9458 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009459 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009460 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009461 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009462 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009463 ShouldExpand, RetainExpansion,
9464 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009465 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009466
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009467 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009468 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009469
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009470 NamedDecl *Pack = E->getPack();
9471 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009472 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009473 Pack));
9474 if (!Pack)
9475 return ExprError();
9476 }
9477
Chad Rosier1dcde962012-08-08 18:46:20 +00009478
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009479 // We now know the length of the parameter pack, so build a new expression
9480 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009481 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9482 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009483 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009484}
9485
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009486template<typename Derived>
9487ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009488TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9489 SubstNonTypeTemplateParmPackExpr *E) {
9490 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009491 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009492}
9493
9494template<typename Derived>
9495ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009496TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9497 SubstNonTypeTemplateParmExpr *E) {
9498 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009499 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009500}
9501
9502template<typename Derived>
9503ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009504TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9505 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009506 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009507}
9508
9509template<typename Derived>
9510ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009511TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9512 MaterializeTemporaryExpr *E) {
9513 return getDerived().TransformExpr(E->GetTemporaryExpr());
9514}
Chad Rosier1dcde962012-08-08 18:46:20 +00009515
Douglas Gregorfe314812011-06-21 17:03:29 +00009516template<typename Derived>
9517ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009518TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9519 CXXStdInitializerListExpr *E) {
9520 return getDerived().TransformExpr(E->getSubExpr());
9521}
9522
9523template<typename Derived>
9524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009525TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009526 return SemaRef.MaybeBindToTemporary(E);
9527}
9528
9529template<typename Derived>
9530ExprResult
9531TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009532 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009533}
9534
9535template<typename Derived>
9536ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009537TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9538 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9539 if (SubExpr.isInvalid())
9540 return ExprError();
9541
9542 if (!getDerived().AlwaysRebuild() &&
9543 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009544 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009545
9546 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009547}
9548
9549template<typename Derived>
9550ExprResult
9551TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9552 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009553 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009554 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009555 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009556 /*IsCall=*/false, Elements, &ArgChanged))
9557 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009558
Ted Kremeneke65b0862012-03-06 20:05:56 +00009559 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9560 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009561
Ted Kremeneke65b0862012-03-06 20:05:56 +00009562 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9563 Elements.data(),
9564 Elements.size());
9565}
9566
9567template<typename Derived>
9568ExprResult
9569TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009570 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009571 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009572 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009573 bool ArgChanged = false;
9574 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9575 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009576
Ted Kremeneke65b0862012-03-06 20:05:56 +00009577 if (OrigElement.isPackExpansion()) {
9578 // This key/value element is a pack expansion.
9579 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9580 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9581 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9582 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9583
9584 // Determine whether the set of unexpanded parameter packs can
9585 // and should be expanded.
9586 bool Expand = true;
9587 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009588 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9589 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009590 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9591 OrigElement.Value->getLocEnd());
9592 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9593 PatternRange,
9594 Unexpanded,
9595 Expand, RetainExpansion,
9596 NumExpansions))
9597 return ExprError();
9598
9599 if (!Expand) {
9600 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009601 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009602 // expansion.
9603 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9604 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9605 if (Key.isInvalid())
9606 return ExprError();
9607
9608 if (Key.get() != OrigElement.Key)
9609 ArgChanged = true;
9610
9611 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9612 if (Value.isInvalid())
9613 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009614
Ted Kremeneke65b0862012-03-06 20:05:56 +00009615 if (Value.get() != OrigElement.Value)
9616 ArgChanged = true;
9617
Chad Rosier1dcde962012-08-08 18:46:20 +00009618 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009619 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9620 };
9621 Elements.push_back(Expansion);
9622 continue;
9623 }
9624
9625 // Record right away that the argument was changed. This needs
9626 // to happen even if the array expands to nothing.
9627 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009628
Ted Kremeneke65b0862012-03-06 20:05:56 +00009629 // The transform has determined that we should perform an elementwise
9630 // expansion of the pattern. Do so.
9631 for (unsigned I = 0; I != *NumExpansions; ++I) {
9632 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9633 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9634 if (Key.isInvalid())
9635 return ExprError();
9636
9637 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9638 if (Value.isInvalid())
9639 return ExprError();
9640
Chad Rosier1dcde962012-08-08 18:46:20 +00009641 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009642 Key.get(), Value.get(), SourceLocation(), NumExpansions
9643 };
9644
9645 // If any unexpanded parameter packs remain, we still have a
9646 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009647 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009648 if (Key.get()->containsUnexpandedParameterPack() ||
9649 Value.get()->containsUnexpandedParameterPack())
9650 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009651
Ted Kremeneke65b0862012-03-06 20:05:56 +00009652 Elements.push_back(Element);
9653 }
9654
Richard Smith9467be42014-06-06 17:33:35 +00009655 // FIXME: Retain a pack expansion if RetainExpansion is true.
9656
Ted Kremeneke65b0862012-03-06 20:05:56 +00009657 // We've finished with this pack expansion.
9658 continue;
9659 }
9660
9661 // Transform and check key.
9662 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9663 if (Key.isInvalid())
9664 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009665
Ted Kremeneke65b0862012-03-06 20:05:56 +00009666 if (Key.get() != OrigElement.Key)
9667 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009668
Ted Kremeneke65b0862012-03-06 20:05:56 +00009669 // Transform and check value.
9670 ExprResult Value
9671 = getDerived().TransformExpr(OrigElement.Value);
9672 if (Value.isInvalid())
9673 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009674
Ted Kremeneke65b0862012-03-06 20:05:56 +00009675 if (Value.get() != OrigElement.Value)
9676 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009677
9678 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009679 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009680 };
9681 Elements.push_back(Element);
9682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009683
Ted Kremeneke65b0862012-03-06 20:05:56 +00009684 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9685 return SemaRef.MaybeBindToTemporary(E);
9686
9687 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9688 Elements.data(),
9689 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009690}
9691
Mike Stump11289f42009-09-09 15:08:12 +00009692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009694TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009695 TypeSourceInfo *EncodedTypeInfo
9696 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9697 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009698 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009699
Douglas Gregora16548e2009-08-11 05:31:07 +00009700 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009701 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009702 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009703
9704 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009705 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 E->getRParenLoc());
9707}
Mike Stump11289f42009-09-09 15:08:12 +00009708
Douglas Gregora16548e2009-08-11 05:31:07 +00009709template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009710ExprResult TreeTransform<Derived>::
9711TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009712 // This is a kind of implicit conversion, and it needs to get dropped
9713 // and recomputed for the same general reasons that ImplicitCastExprs
9714 // do, as well a more specific one: this expression is only valid when
9715 // it appears *immediately* as an argument expression.
9716 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009717}
9718
9719template<typename Derived>
9720ExprResult TreeTransform<Derived>::
9721TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009722 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009723 = getDerived().TransformType(E->getTypeInfoAsWritten());
9724 if (!TSInfo)
9725 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009726
John McCall31168b02011-06-15 23:02:42 +00009727 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009728 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009729 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009730
John McCall31168b02011-06-15 23:02:42 +00009731 if (!getDerived().AlwaysRebuild() &&
9732 TSInfo == E->getTypeInfoAsWritten() &&
9733 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009734 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009735
John McCall31168b02011-06-15 23:02:42 +00009736 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009737 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009738 Result.get());
9739}
9740
9741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009743TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009744 // Transform arguments.
9745 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009746 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009747 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009748 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009749 &ArgChanged))
9750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009751
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009752 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9753 // Class message: transform the receiver type.
9754 TypeSourceInfo *ReceiverTypeInfo
9755 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9756 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009757 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009758
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009759 // If nothing changed, just retain the existing message send.
9760 if (!getDerived().AlwaysRebuild() &&
9761 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009762 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009763
9764 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009765 SmallVector<SourceLocation, 16> SelLocs;
9766 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009767 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9768 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009769 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009770 E->getMethodDecl(),
9771 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009772 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009773 E->getRightLoc());
9774 }
9775
9776 // Instance message: transform the receiver
9777 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9778 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009779 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009780 = getDerived().TransformExpr(E->getInstanceReceiver());
9781 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009782 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009783
9784 // If nothing changed, just retain the existing message send.
9785 if (!getDerived().AlwaysRebuild() &&
9786 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009787 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009788
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009789 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009790 SmallVector<SourceLocation, 16> SelLocs;
9791 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009792 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009793 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009794 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009795 E->getMethodDecl(),
9796 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009797 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009798 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009799}
9800
Mike Stump11289f42009-09-09 15:08:12 +00009801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009803TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009804 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009805}
9806
Mike Stump11289f42009-09-09 15:08:12 +00009807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009808ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009809TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009810 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009811}
9812
Mike Stump11289f42009-09-09 15:08:12 +00009813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009814ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009815TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009816 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009817 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009818 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009819 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009820
9821 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009822
Douglas Gregord51d90d2010-04-26 20:11:03 +00009823 // If nothing changed, just retain the existing expression.
9824 if (!getDerived().AlwaysRebuild() &&
9825 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009826 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009827
John McCallb268a282010-08-23 23:25:46 +00009828 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009829 E->getLocation(),
9830 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009831}
9832
Mike Stump11289f42009-09-09 15:08:12 +00009833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009835TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009836 // 'super' and types never change. Property never changes. Just
9837 // retain the existing expression.
9838 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009839 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009840
Douglas Gregor9faee212010-04-26 20:47:02 +00009841 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009842 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009843 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009844 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009845
Douglas Gregor9faee212010-04-26 20:47:02 +00009846 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009847
Douglas Gregor9faee212010-04-26 20:47:02 +00009848 // If nothing changed, just retain the existing expression.
9849 if (!getDerived().AlwaysRebuild() &&
9850 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009851 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009852
John McCallb7bd14f2010-12-02 01:19:52 +00009853 if (E->isExplicitProperty())
9854 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9855 E->getExplicitProperty(),
9856 E->getLocation());
9857
9858 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009859 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009860 E->getImplicitPropertyGetter(),
9861 E->getImplicitPropertySetter(),
9862 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009863}
9864
Mike Stump11289f42009-09-09 15:08:12 +00009865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009866ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009867TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9868 // Transform the base expression.
9869 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9870 if (Base.isInvalid())
9871 return ExprError();
9872
9873 // Transform the key expression.
9874 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9875 if (Key.isInvalid())
9876 return ExprError();
9877
9878 // If nothing changed, just retain the existing expression.
9879 if (!getDerived().AlwaysRebuild() &&
9880 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009881 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009882
Chad Rosier1dcde962012-08-08 18:46:20 +00009883 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009884 Base.get(), Key.get(),
9885 E->getAtIndexMethodDecl(),
9886 E->setAtIndexMethodDecl());
9887}
9888
9889template<typename Derived>
9890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009891TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009892 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009893 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009894 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009895 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009896
Douglas Gregord51d90d2010-04-26 20:11:03 +00009897 // If nothing changed, just retain the existing expression.
9898 if (!getDerived().AlwaysRebuild() &&
9899 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009900 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009901
John McCallb268a282010-08-23 23:25:46 +00009902 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009903 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009904 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009905}
9906
Mike Stump11289f42009-09-09 15:08:12 +00009907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009909TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009910 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009911 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009912 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009913 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009914 SubExprs, &ArgumentChanged))
9915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009916
Douglas Gregora16548e2009-08-11 05:31:07 +00009917 if (!getDerived().AlwaysRebuild() &&
9918 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009919 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009920
Douglas Gregora16548e2009-08-11 05:31:07 +00009921 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009922 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009923 E->getRParenLoc());
9924}
9925
Mike Stump11289f42009-09-09 15:08:12 +00009926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009927ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009928TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9929 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9930 if (SrcExpr.isInvalid())
9931 return ExprError();
9932
9933 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9934 if (!Type)
9935 return ExprError();
9936
9937 if (!getDerived().AlwaysRebuild() &&
9938 Type == E->getTypeSourceInfo() &&
9939 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009940 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009941
9942 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9943 SrcExpr.get(), Type,
9944 E->getRParenLoc());
9945}
9946
9947template<typename Derived>
9948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009949TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009950 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009951
Craig Topperc3ec1492014-05-26 06:22:03 +00009952 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009953 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9954
9955 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009956 blockScope->TheDecl->setBlockMissingReturnType(
9957 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009958
Chris Lattner01cf8db2011-07-20 06:58:45 +00009959 SmallVector<ParmVarDecl*, 4> params;
9960 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009961
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009962 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009963 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9964 oldBlock->param_begin(),
9965 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009966 nullptr, paramTypes, &params)) {
9967 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009968 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009969 }
John McCall490112f2011-02-04 18:33:18 +00009970
Jordan Rosea0a86be2013-03-08 22:25:36 +00009971 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009972 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009973 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009974
Jordan Rose5c382722013-03-08 21:51:21 +00009975 QualType functionType =
9976 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009977 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009978 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009979
9980 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009981 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009982 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009983
9984 if (!oldBlock->blockMissingReturnType()) {
9985 blockScope->HasImplicitReturnType = false;
9986 blockScope->ReturnType = exprResultType;
9987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009988
John McCall3882ace2011-01-05 12:14:39 +00009989 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009990 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009991 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009992 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009993 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009994 }
John McCall3882ace2011-01-05 12:14:39 +00009995
John McCall490112f2011-02-04 18:33:18 +00009996#ifndef NDEBUG
9997 // In builds with assertions, make sure that we captured everything we
9998 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009999 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010000 for (const auto &I : oldBlock->captures()) {
10001 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010002
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010003 // Ignore parameter packs.
10004 if (isa<ParmVarDecl>(oldCapture) &&
10005 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10006 continue;
John McCall490112f2011-02-04 18:33:18 +000010007
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010008 VarDecl *newCapture =
10009 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10010 oldCapture));
10011 assert(blockScope->CaptureMap.count(newCapture));
10012 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010013 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010014 }
10015#endif
10016
10017 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010018 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010019}
10020
Mike Stump11289f42009-09-09 15:08:12 +000010021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010022ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010023TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010024 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010025}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010026
10027template<typename Derived>
10028ExprResult
10029TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010030 QualType RetTy = getDerived().TransformType(E->getType());
10031 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010032 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010033 SubExprs.reserve(E->getNumSubExprs());
10034 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10035 SubExprs, &ArgumentChanged))
10036 return ExprError();
10037
10038 if (!getDerived().AlwaysRebuild() &&
10039 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010040 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010041
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010042 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010043 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010044}
Chad Rosier1dcde962012-08-08 18:46:20 +000010045
Douglas Gregora16548e2009-08-11 05:31:07 +000010046//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010047// Type reconstruction
10048//===----------------------------------------------------------------------===//
10049
Mike Stump11289f42009-09-09 15:08:12 +000010050template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010051QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10052 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010053 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010054 getDerived().getBaseEntity());
10055}
10056
Mike Stump11289f42009-09-09 15:08:12 +000010057template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010058QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10059 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010060 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010061 getDerived().getBaseEntity());
10062}
10063
Mike Stump11289f42009-09-09 15:08:12 +000010064template<typename Derived>
10065QualType
John McCall70dd5f62009-10-30 00:06:24 +000010066TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10067 bool WrittenAsLValue,
10068 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010069 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010070 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010071}
10072
10073template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010074QualType
John McCall70dd5f62009-10-30 00:06:24 +000010075TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10076 QualType ClassType,
10077 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010078 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10079 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010080}
10081
10082template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010083QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010084TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10085 ArrayType::ArraySizeModifier SizeMod,
10086 const llvm::APInt *Size,
10087 Expr *SizeExpr,
10088 unsigned IndexTypeQuals,
10089 SourceRange BracketsRange) {
10090 if (SizeExpr || !Size)
10091 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10092 IndexTypeQuals, BracketsRange,
10093 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010094
10095 QualType Types[] = {
10096 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10097 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10098 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010099 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010100 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010101 QualType SizeType;
10102 for (unsigned I = 0; I != NumTypes; ++I)
10103 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10104 SizeType = Types[I];
10105 break;
10106 }
Mike Stump11289f42009-09-09 15:08:12 +000010107
Eli Friedman9562f392012-01-25 23:20:27 +000010108 // Note that we can return a VariableArrayType here in the case where
10109 // the element type was a dependent VariableArrayType.
10110 IntegerLiteral *ArraySize
10111 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10112 /*FIXME*/BracketsRange.getBegin());
10113 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010114 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010115 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010116}
Mike Stump11289f42009-09-09 15:08:12 +000010117
Douglas Gregord6ff3322009-08-04 16:50:30 +000010118template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010119QualType
10120TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010121 ArrayType::ArraySizeModifier SizeMod,
10122 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010123 unsigned IndexTypeQuals,
10124 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010125 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010126 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010127}
10128
10129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010130QualType
Mike Stump11289f42009-09-09 15:08:12 +000010131TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010132 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010133 unsigned IndexTypeQuals,
10134 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010135 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010136 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010137}
Mike Stump11289f42009-09-09 15:08:12 +000010138
Douglas Gregord6ff3322009-08-04 16:50:30 +000010139template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010140QualType
10141TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010142 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010143 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010144 unsigned IndexTypeQuals,
10145 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010146 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010147 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010148 IndexTypeQuals, BracketsRange);
10149}
10150
10151template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010152QualType
10153TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010154 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010155 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010156 unsigned IndexTypeQuals,
10157 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010158 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010159 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010160 IndexTypeQuals, BracketsRange);
10161}
10162
10163template<typename Derived>
10164QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010165 unsigned NumElements,
10166 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010167 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010168 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010169}
Mike Stump11289f42009-09-09 15:08:12 +000010170
Douglas Gregord6ff3322009-08-04 16:50:30 +000010171template<typename Derived>
10172QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10173 unsigned NumElements,
10174 SourceLocation AttributeLoc) {
10175 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10176 NumElements, true);
10177 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010178 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10179 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010180 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010181}
Mike Stump11289f42009-09-09 15:08:12 +000010182
Douglas Gregord6ff3322009-08-04 16:50:30 +000010183template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010184QualType
10185TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010186 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010187 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010188 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010189}
Mike Stump11289f42009-09-09 15:08:12 +000010190
Douglas Gregord6ff3322009-08-04 16:50:30 +000010191template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010192QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10193 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010194 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010195 const FunctionProtoType::ExtProtoInfo &EPI) {
10196 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010197 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010198 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010199 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010200}
Mike Stump11289f42009-09-09 15:08:12 +000010201
Douglas Gregord6ff3322009-08-04 16:50:30 +000010202template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010203QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10204 return SemaRef.Context.getFunctionNoProtoType(T);
10205}
10206
10207template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010208QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10209 assert(D && "no decl found");
10210 if (D->isInvalidDecl()) return QualType();
10211
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010212 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010213 TypeDecl *Ty;
10214 if (isa<UsingDecl>(D)) {
10215 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010216 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010217 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10218
10219 // A valid resolved using typename decl points to exactly one type decl.
10220 assert(++Using->shadow_begin() == Using->shadow_end());
10221 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010222
John McCallb96ec562009-12-04 22:46:56 +000010223 } else {
10224 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10225 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10226 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10227 }
10228
10229 return SemaRef.Context.getTypeDeclType(Ty);
10230}
10231
10232template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010233QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10234 SourceLocation Loc) {
10235 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010236}
10237
10238template<typename Derived>
10239QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10240 return SemaRef.Context.getTypeOfType(Underlying);
10241}
10242
10243template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010244QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10245 SourceLocation Loc) {
10246 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010247}
10248
10249template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010250QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10251 UnaryTransformType::UTTKind UKind,
10252 SourceLocation Loc) {
10253 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10254}
10255
10256template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010257QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010258 TemplateName Template,
10259 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010260 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010261 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010262}
Mike Stump11289f42009-09-09 15:08:12 +000010263
Douglas Gregor1135c352009-08-06 05:28:30 +000010264template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010265QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10266 SourceLocation KWLoc) {
10267 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10268}
10269
10270template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010271TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010272TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010273 bool TemplateKW,
10274 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010275 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010276 Template);
10277}
10278
10279template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010280TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010281TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10282 const IdentifierInfo &Name,
10283 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010284 QualType ObjectType,
10285 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010286 UnqualifiedId TemplateName;
10287 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010288 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010289 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010290 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010291 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010292 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010293 /*EnteringContext=*/false,
10294 Template);
John McCall31f82722010-11-12 08:19:04 +000010295 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010296}
Mike Stump11289f42009-09-09 15:08:12 +000010297
Douglas Gregora16548e2009-08-11 05:31:07 +000010298template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010299TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010300TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010301 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010302 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010303 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010304 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010305 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010306 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010307 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010308 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010309 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010310 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010311 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010312 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010313 /*EnteringContext=*/false,
10314 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010315 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010316}
Chad Rosier1dcde962012-08-08 18:46:20 +000010317
Douglas Gregor71395fa2009-11-04 00:56:37 +000010318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010319ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010320TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10321 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010322 Expr *OrigCallee,
10323 Expr *First,
10324 Expr *Second) {
10325 Expr *Callee = OrigCallee->IgnoreParenCasts();
10326 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010327
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010328 if (First->getObjectKind() == OK_ObjCProperty) {
10329 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10330 if (BinaryOperator::isAssignmentOp(Opc))
10331 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10332 First, Second);
10333 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10334 if (Result.isInvalid())
10335 return ExprError();
10336 First = Result.get();
10337 }
10338
10339 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10340 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10341 if (Result.isInvalid())
10342 return ExprError();
10343 Second = Result.get();
10344 }
10345
Douglas Gregora16548e2009-08-11 05:31:07 +000010346 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010347 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010348 if (!First->getType()->isOverloadableType() &&
10349 !Second->getType()->isOverloadableType())
10350 return getSema().CreateBuiltinArraySubscriptExpr(First,
10351 Callee->getLocStart(),
10352 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010353 } else if (Op == OO_Arrow) {
10354 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010355 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10356 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010357 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010358 // The argument is not of overloadable type, so try to create a
10359 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010360 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010361 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010362
John McCallb268a282010-08-23 23:25:46 +000010363 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010364 }
10365 } else {
John McCallb268a282010-08-23 23:25:46 +000010366 if (!First->getType()->isOverloadableType() &&
10367 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010368 // Neither of the arguments is an overloadable type, so try to
10369 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010370 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010371 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010372 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010373 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010375
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010376 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010377 }
10378 }
Mike Stump11289f42009-09-09 15:08:12 +000010379
10380 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010381 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010382 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010383
John McCallb268a282010-08-23 23:25:46 +000010384 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010385 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010386 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010387 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010388 // If we've resolved this to a particular non-member function, just call
10389 // that function. If we resolved it to a member function,
10390 // CreateOverloaded* will find that function for us.
10391 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10392 if (!isa<CXXMethodDecl>(ND))
10393 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010394 }
Mike Stump11289f42009-09-09 15:08:12 +000010395
Douglas Gregora16548e2009-08-11 05:31:07 +000010396 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010397 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010398 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010399
Douglas Gregora16548e2009-08-11 05:31:07 +000010400 // Create the overloaded operator invocation for unary operators.
10401 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010402 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010403 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010404 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010405 }
Mike Stump11289f42009-09-09 15:08:12 +000010406
Douglas Gregore9d62932011-07-15 16:25:15 +000010407 if (Op == OO_Subscript) {
10408 SourceLocation LBrace;
10409 SourceLocation RBrace;
10410
10411 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10412 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10413 LBrace = SourceLocation::getFromRawEncoding(
10414 NameLoc.CXXOperatorName.BeginOpNameLoc);
10415 RBrace = SourceLocation::getFromRawEncoding(
10416 NameLoc.CXXOperatorName.EndOpNameLoc);
10417 } else {
10418 LBrace = Callee->getLocStart();
10419 RBrace = OpLoc;
10420 }
10421
10422 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10423 First, Second);
10424 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010425
Douglas Gregora16548e2009-08-11 05:31:07 +000010426 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010427 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010428 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010429 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10430 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010432
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010433 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010434}
Mike Stump11289f42009-09-09 15:08:12 +000010435
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010436template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010437ExprResult
John McCallb268a282010-08-23 23:25:46 +000010438TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010439 SourceLocation OperatorLoc,
10440 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010441 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010442 TypeSourceInfo *ScopeType,
10443 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010444 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010445 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010446 QualType BaseType = Base->getType();
10447 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010448 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010449 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010450 !BaseType->getAs<PointerType>()->getPointeeType()
10451 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010452 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010453 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010454 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010455 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010456 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010457 /*FIXME?*/true);
10458 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010459
Douglas Gregor678f90d2010-02-25 01:56:36 +000010460 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010461 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10462 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10463 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10464 NameInfo.setNamedTypeInfo(DestroyedType);
10465
Richard Smith8e4a3862012-05-15 06:15:11 +000010466 // The scope type is now known to be a valid nested name specifier
10467 // component. Tack it on to the end of the nested name specifier.
10468 if (ScopeType)
10469 SS.Extend(SemaRef.Context, SourceLocation(),
10470 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010471
Abramo Bagnara7945c982012-01-27 09:46:47 +000010472 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010473 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010474 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010475 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010476 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010477 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010478 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010479}
10480
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010481template<typename Derived>
10482StmtResult
10483TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010484 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010485 CapturedDecl *CD = S->getCapturedDecl();
10486 unsigned NumParams = CD->getNumParams();
10487 unsigned ContextParamPos = CD->getContextParamPosition();
10488 SmallVector<Sema::CapturedParamNameType, 4> Params;
10489 for (unsigned I = 0; I < NumParams; ++I) {
10490 if (I != ContextParamPos) {
10491 Params.push_back(
10492 std::make_pair(
10493 CD->getParam(I)->getName(),
10494 getDerived().TransformType(CD->getParam(I)->getType())));
10495 } else {
10496 Params.push_back(std::make_pair(StringRef(), QualType()));
10497 }
10498 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010499 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010500 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010501 StmtResult Body;
10502 {
10503 Sema::CompoundScopeRAII CompoundScope(getSema());
10504 Body = getDerived().TransformStmt(S->getCapturedStmt());
10505 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010506
10507 if (Body.isInvalid()) {
10508 getSema().ActOnCapturedRegionError();
10509 return StmtError();
10510 }
10511
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010512 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010513}
10514
Douglas Gregord6ff3322009-08-04 16:50:30 +000010515} // end namespace clang
10516
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010517#endif