blob: 687f16473df944ccd32394f60ce397dae5a80d23 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000347 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
Hans Wennborge113c202014-09-18 16:01:32 +0000548 unsigned ThisTypeQuals);
Douglas Gregor3024f072012-04-16 07:05:22 +0000549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Nico Weberc153d242014-07-28 00:02:09 +0000563 QualType TransformDependentTemplateSpecializationType(
564 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
565 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566
John McCall58f10c32010-03-11 09:03:00 +0000567 /// \brief Transforms the parameters of a function type into the
568 /// given vectors.
569 ///
570 /// The result vectors should be kept in sync; null entries in the
571 /// variables vector are acceptable.
572 ///
573 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000574 bool TransformFunctionTypeParams(SourceLocation Loc,
575 ParmVarDecl **Params, unsigned NumParams,
576 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000577 SmallVectorImpl<QualType> &PTypes,
578 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000579
580 /// \brief Transforms a single function-type parameter. Return null
581 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000582 ///
583 /// \param indexAdjustment - A number to add to the parameter's
584 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000585 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000586 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000587 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000588 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000589
John McCall31f82722010-11-12 08:19:04 +0000590 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000591
John McCalldadc5752010-08-24 06:29:42 +0000592 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
593 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000594
595 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000596 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000597 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
598 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000599
Faisal Vali2cba1332013-10-23 06:44:28 +0000600 TemplateParameterList *TransformTemplateParameterList(
601 TemplateParameterList *TPL) {
602 return TPL;
603 }
604
Richard Smithdb2630f2012-10-21 03:28:35 +0000605 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000608 bool IsAddressOfOperand,
609 TypeSourceInfo **RecoveryTSI);
610
611 ExprResult TransformParenDependentScopeDeclRefExpr(
612 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
613 TypeSourceInfo **RecoveryTSI);
614
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000615 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000616
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
618// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000619#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000620 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000621 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000622#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000624 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000625#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000626#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000627
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000628#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000629 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000630 OMPClause *Transform ## Class(Class *S);
631#include "clang/Basic/OpenMPKinds.def"
632
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 /// \brief Build a new pointer type given its pointee type.
634 ///
635 /// By default, performs semantic analysis when building the pointer type.
636 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
639 /// \brief Build a new block pointer type given its pointee type.
640 ///
Mike Stump11289f42009-09-09 15:08:12 +0000641 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000643 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 ///
John McCall70dd5f62009-10-30 00:06:24 +0000647 /// By default, performs semantic analysis when building the
648 /// reference type. Subclasses may override this routine to provide
649 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000650 ///
John McCall70dd5f62009-10-30 00:06:24 +0000651 /// \param LValue whether the type was written with an lvalue sigil
652 /// or an rvalue sigil.
653 QualType RebuildReferenceType(QualType ReferentType,
654 bool LValue,
655 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000656
Douglas Gregord6ff3322009-08-04 16:50:30 +0000657 /// \brief Build a new member pointer type given the pointee type and the
658 /// class type it refers into.
659 ///
660 /// By default, performs semantic analysis when building the member pointer
661 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000662 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
663 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000664
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// \brief Build a new array type given the element type, size
666 /// modifier, size of the array (if known), size expression, and index type
667 /// qualifiers.
668 ///
669 /// By default, performs semantic analysis when building the array type.
670 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000671 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672 QualType RebuildArrayType(QualType ElementType,
673 ArrayType::ArraySizeModifier SizeMod,
674 const llvm::APInt *Size,
675 Expr *SizeExpr,
676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new constant array type given the element type, size
680 /// modifier, (known) size of the array, and index type qualifiers.
681 ///
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000684 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
686 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000689
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 /// \brief Build a new incomplete array type given the element type, size
691 /// modifier, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000695 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 /// size modifier, size expression, and index type qualifiers.
702 ///
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000705 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000707 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
710
Mike Stump11289f42009-09-09 15:08:12 +0000711 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 /// size modifier, size expression, and index type qualifiers.
713 ///
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000716 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000718 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 unsigned IndexTypeQuals,
720 SourceRange BracketsRange);
721
722 /// \brief Build a new vector type given the element type and
723 /// number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000727 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000728 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000729
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 /// \brief Build a new extended vector type given the element type and
731 /// number of elements.
732 ///
733 /// By default, performs semantic analysis when building the vector type.
734 /// Subclasses may override this routine to provide different behavior.
735 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
736 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000737
738 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// given the element type and number of elements.
740 ///
741 /// By default, performs semantic analysis when building the vector type.
742 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000743 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000744 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 /// \brief Build a new function type.
748 ///
749 /// By default, performs semantic analysis when building the function type.
750 /// Subclasses may override this routine to provide different behavior.
751 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000752 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000753 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000754
John McCall550e0c22009-10-21 00:40:46 +0000755 /// \brief Build a new unprototyped function type.
756 QualType RebuildFunctionNoProtoType(QualType ResultType);
757
John McCallb96ec562009-12-04 22:46:56 +0000758 /// \brief Rebuild an unresolved typename type, given the decl that
759 /// the UnresolvedUsingTypenameDecl was transformed to.
760 QualType RebuildUnresolvedUsingType(Decl *D);
761
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000763 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 return SemaRef.Context.getTypeDeclType(Typedef);
765 }
766
767 /// \brief Build a new class/struct/union type.
768 QualType RebuildRecordType(RecordDecl *Record) {
769 return SemaRef.Context.getTypeDeclType(Record);
770 }
771
772 /// \brief Build a new Enum type.
773 QualType RebuildEnumType(EnumDecl *Enum) {
774 return SemaRef.Context.getTypeDeclType(Enum);
775 }
John McCallfcc33b02009-09-05 00:15:47 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, performs semantic analysis when building the typeof type.
780 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000781 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000782
Mike Stump11289f42009-09-09 15:08:12 +0000783 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000784 ///
785 /// By default, builds a new TypeOfType with the given underlying type.
786 QualType RebuildTypeOfType(QualType Underlying);
787
Alexis Hunte852b102011-05-24 22:41:36 +0000788 /// \brief Build a new unary transform type.
789 QualType RebuildUnaryTransformType(QualType BaseType,
790 UnaryTransformType::UTTKind UKind,
791 SourceLocation Loc);
792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 ///
795 /// By default, performs semantic analysis when building the decltype type.
796 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000797 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000798
Richard Smith74aeef52013-04-26 16:15:35 +0000799 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000800 ///
801 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000802 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000803 // Note, IsDependent is always false here: we implicitly convert an 'auto'
804 // which has been deduced to a dependent type into an undeduced 'auto', so
805 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000806 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
807 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000808 }
809
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 /// \brief Build a new template specialization type.
811 ///
812 /// By default, performs semantic analysis when building the template
813 /// specialization type. Subclasses may override this routine to provide
814 /// different behavior.
815 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000816 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000817 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000818
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000819 /// \brief Build a new parenthesized type.
820 ///
821 /// By default, builds a new ParenType type from the inner type.
822 /// Subclasses may override this routine to provide different behavior.
823 QualType RebuildParenType(QualType InnerType) {
824 return SemaRef.Context.getParenType(InnerType);
825 }
826
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 /// \brief Build a new qualified name type.
828 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000829 /// By default, builds a new ElaboratedType type from the keyword,
830 /// the nested-name-specifier and the named type.
831 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000832 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
833 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000834 NestedNameSpecifierLoc QualifierLoc,
835 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000836 return SemaRef.Context.getElaboratedType(Keyword,
837 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000838 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000839 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000840
841 /// \brief Build a new typename type that refers to a template-id.
842 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000843 /// By default, builds a new DependentNameType type from the
844 /// nested-name-specifier and the given type. Subclasses may override
845 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000846 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 ElaboratedTypeKeyword Keyword,
848 NestedNameSpecifierLoc QualifierLoc,
849 const IdentifierInfo *Name,
850 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000851 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000852 // Rebuild the template name.
853 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000854 CXXScopeSpec SS;
855 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000856 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000857 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
858 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000859
Douglas Gregora7a795b2011-03-01 20:11:18 +0000860 if (InstName.isNull())
861 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000862
Douglas Gregora7a795b2011-03-01 20:11:18 +0000863 // If it's still dependent, make a dependent specialization.
864 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000865 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
866 QualifierLoc.getNestedNameSpecifier(),
867 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000868 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 // Otherwise, make an elaborated type wrapping a non-dependent
871 // specialization.
872 QualType T =
873 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
874 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000875
Craig Topperc3ec1492014-05-26 06:22:03 +0000876 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000877 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000878
879 return SemaRef.Context.getElaboratedType(Keyword,
880 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000881 T);
882 }
883
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884 /// \brief Build a new typename type that refers to an identifier.
885 ///
886 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000888 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000889 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 NestedNameSpecifierLoc QualifierLoc,
892 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000893 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000894 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000895 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000896
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000897 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000898 // If the name is still dependent, just build a new dependent name type.
899 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 return SemaRef.Context.getDependentNameType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000902 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000903 }
904
Abramo Bagnara6150c882010-05-11 21:36:43 +0000905 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000906 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000907 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000908
909 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
910
Abramo Bagnarad7548482010-05-19 21:37:53 +0000911 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000912 // into a non-dependent elaborated-type-specifier. Find the tag we're
913 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000914 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
916 if (!DC)
917 return QualType();
918
John McCallbf8c5192010-05-27 06:40:31 +0000919 if (SemaRef.RequireCompleteDeclContext(SS, DC))
920 return QualType();
921
Craig Topperc3ec1492014-05-26 06:22:03 +0000922 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 SemaRef.LookupQualifiedName(Result, DC);
924 switch (Result.getResultKind()) {
925 case LookupResult::NotFound:
926 case LookupResult::NotFoundInCurrentInstantiation:
927 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000928
Douglas Gregore677daf2010-03-31 22:19:08 +0000929 case LookupResult::Found:
930 Tag = Result.getAsSingle<TagDecl>();
931 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000932
Douglas Gregore677daf2010-03-31 22:19:08 +0000933 case LookupResult::FoundOverloaded:
934 case LookupResult::FoundUnresolvedValue:
935 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000936
Douglas Gregore677daf2010-03-31 22:19:08 +0000937 case LookupResult::Ambiguous:
938 // Let the LookupResult structure handle ambiguities.
939 return QualType();
940 }
941
942 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000943 // Check where the name exists but isn't a tag type and use that to emit
944 // better diagnostics.
945 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::Found:
949 case LookupResult::FoundOverloaded:
950 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000951 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000952 unsigned Kind = 0;
953 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000954 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
955 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000956 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
957 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
958 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000959 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000960 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000961 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000962 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000963 break;
964 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 return QualType();
966 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000967
Richard Trieucaa33d32011-06-10 03:11:26 +0000968 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
969 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000970 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000971 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
972 return QualType();
973 }
974
975 // Build the elaborated-type-specifier type.
976 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000977 return SemaRef.Context.getElaboratedType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000979 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregor822d0302011-01-12 17:07:58 +0000982 /// \brief Build a new pack expansion type.
983 ///
984 /// By default, builds a new PackExpansionType type from the given pattern.
985 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000986 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000987 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000988 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000989 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000990 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
991 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000992 }
993
Eli Friedman0dfb8892011-10-06 23:00:33 +0000994 /// \brief Build a new atomic type given its value type.
995 ///
996 /// By default, performs semantic analysis when building the atomic type.
997 /// Subclasses may override this routine to provide different behavior.
998 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
999
Douglas Gregor71dc5092009-08-06 06:41:21 +00001000 /// \brief Build a new template name given a nested name specifier, a flag
1001 /// indicating whether the "template" keyword was provided, and the template
1002 /// that the template name refers to.
1003 ///
1004 /// By default, builds the new template name directly. Subclasses may override
1005 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001006 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001007 bool TemplateKW,
1008 TemplateDecl *Template);
1009
Douglas Gregor71dc5092009-08-06 06:41:21 +00001010 /// \brief Build a new template name given a nested name specifier and the
1011 /// name that is referred to as a template.
1012 ///
1013 /// By default, performs semantic analysis to determine whether the name can
1014 /// be resolved to a specific template, then builds the appropriate kind of
1015 /// template name. Subclasses may override this routine to provide different
1016 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001017 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1018 const IdentifierInfo &Name,
1019 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001020 QualType ObjectType,
1021 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregor71395fa2009-11-04 00:56:37 +00001023 /// \brief Build a new template name given a nested name specifier and the
1024 /// overloaded operator name that is referred to as a template.
1025 ///
1026 /// By default, performs semantic analysis to determine whether the name can
1027 /// be resolved to a specific template, then builds the appropriate kind of
1028 /// template name. Subclasses may override this routine to provide different
1029 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001030 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001031 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001032 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001033 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001034
1035 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001036 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001037 ///
1038 /// By default, performs semantic analysis to determine whether the name can
1039 /// be resolved to a specific template, then builds the appropriate kind of
1040 /// template name. Subclasses may override this routine to provide different
1041 /// behavior.
1042 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1043 const TemplateArgument &ArgPack) {
1044 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1045 }
1046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new compound statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 MultiStmtArg Statements,
1053 SourceLocation RBraceLoc,
1054 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001055 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 IsStmtExpr);
1057 }
1058
1059 /// \brief Build a new case statement.
1060 ///
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001063 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001064 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001065 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001066 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001068 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001069 ColonLoc);
1070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Attach the body to a new case statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001077 getSema().ActOnCaseStmtBody(S, Body);
1078 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
Mike Stump11289f42009-09-09 15:08:12 +00001080
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /// \brief Build a new default statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Stmt *SubStmt) {
1088 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001089 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 }
Mike Stump11289f42009-09-09 15:08:12 +00001091
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 /// \brief Build a new label statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001096 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1097 SourceLocation ColonLoc, Stmt *SubStmt) {
1098 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 }
Mike Stump11289f42009-09-09 15:08:12 +00001100
Richard Smithc202b282012-04-14 00:33:13 +00001101 /// \brief Build a new label statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001105 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1106 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001107 Stmt *SubStmt) {
1108 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1109 }
1110
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 /// \brief Build a new "if" statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001116 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001117 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001118 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Start building a new switch statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001126 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001127 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001128 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001129 }
Mike Stump11289f42009-09-09 15:08:12 +00001130
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 /// \brief Attach the body to the switch statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001135 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001136 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001137 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 }
1139
1140 /// \brief Build a new while statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001144 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1145 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001146 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 }
Mike Stump11289f42009-09-09 15:08:12 +00001148
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 /// \brief Build a new do-while statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001153 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001154 SourceLocation WhileLoc, SourceLocation LParenLoc,
1155 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001156 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1157 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001158 }
1159
1160 /// \brief Build a new for statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001164 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001166 VarDecl *CondVar, Sema::FullExprArg Inc,
1167 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001168 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001169 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new goto statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001176 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1177 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001178 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001179 }
1180
1181 /// \brief Build a new indirect goto statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001186 SourceLocation StarLoc,
1187 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 /// \brief Build a new return statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001195 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001196 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 }
Mike Stump11289f42009-09-09 15:08:12 +00001198
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 /// \brief Build a new declaration statement.
1200 ///
1201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001203 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001204 SourceLocation StartLoc, SourceLocation EndLoc) {
1205 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001206 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Anders Carlssonaaeef072010-01-24 05:50:09 +00001209 /// \brief Build a new inline asm statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001213 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1214 bool IsVolatile, unsigned NumOutputs,
1215 unsigned NumInputs, IdentifierInfo **Names,
1216 MultiExprArg Constraints, MultiExprArg Exprs,
1217 Expr *AsmString, MultiExprArg Clobbers,
1218 SourceLocation RParenLoc) {
1219 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1220 NumInputs, Names, Constraints, Exprs,
1221 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001222 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001223
Chad Rosier32503022012-06-11 20:47:18 +00001224 /// \brief Build a new MS style inline asm statement.
1225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001228 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001229 ArrayRef<Token> AsmToks,
1230 StringRef AsmString,
1231 unsigned NumOutputs, unsigned NumInputs,
1232 ArrayRef<StringRef> Constraints,
1233 ArrayRef<StringRef> Clobbers,
1234 ArrayRef<Expr*> Exprs,
1235 SourceLocation EndLoc) {
1236 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1237 NumOutputs, NumInputs,
1238 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001239 }
1240
James Dennett2a4d13c2012-06-15 07:13:21 +00001241 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001246 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001247 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001248 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001249 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001250 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001251 }
1252
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001253 /// \brief Rebuild an Objective-C exception declaration.
1254 ///
1255 /// By default, performs semantic analysis to build the new declaration.
1256 /// Subclasses may override this routine to provide different behavior.
1257 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1258 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001259 return getSema().BuildObjCExceptionDecl(TInfo, T,
1260 ExceptionDecl->getInnerLocStart(),
1261 ExceptionDecl->getLocation(),
1262 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001264
James Dennett2a4d13c2012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001269 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001270 SourceLocation RParenLoc,
1271 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001272 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001273 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001274 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001276
James Dennett2a4d13c2012-06-15 07:13:21 +00001277 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001281 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001282 Stmt *Body) {
1283 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001285
James Dennett2a4d13c2012-06-15 07:13:21 +00001286 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001291 Expr *Operand) {
1292 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001293 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001294
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001295 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001299 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001300 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001301 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001302 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001303 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001304 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1305 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001306 }
1307
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001308 /// \brief Build a new OpenMP 'if' clause.
1309 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001310 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001311 /// Subclasses may override this routine to provide different behavior.
1312 OMPClause *RebuildOMPIfClause(Expr *Condition,
1313 SourceLocation StartLoc,
1314 SourceLocation LParenLoc,
1315 SourceLocation EndLoc) {
1316 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1317 LParenLoc, EndLoc);
1318 }
1319
Alexey Bataev3778b602014-07-17 07:32:53 +00001320 /// \brief Build a new OpenMP 'final' clause.
1321 ///
1322 /// By default, performs semantic analysis to build the new OpenMP clause.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1325 SourceLocation LParenLoc,
1326 SourceLocation EndLoc) {
1327 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1328 EndLoc);
1329 }
1330
Alexey Bataev568a8332014-03-06 06:15:19 +00001331 /// \brief Build a new OpenMP 'num_threads' clause.
1332 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001333 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1340 LParenLoc, EndLoc);
1341 }
1342
Alexey Bataev62c87d22014-03-21 04:51:18 +00001343 /// \brief Build a new OpenMP 'safelen' clause.
1344 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001345 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1351 }
1352
Alexander Musman8bd31e62014-05-27 15:12:19 +00001353 /// \brief Build a new OpenMP 'collapse' clause.
1354 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001355 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001356 /// Subclasses may override this routine to provide different behavior.
1357 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1361 EndLoc);
1362 }
1363
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001364 /// \brief Build a new OpenMP 'default' clause.
1365 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001366 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001367 /// Subclasses may override this routine to provide different behavior.
1368 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1369 SourceLocation KindKwLoc,
1370 SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1374 StartLoc, LParenLoc, EndLoc);
1375 }
1376
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001377 /// \brief Build a new OpenMP 'proc_bind' clause.
1378 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001379 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1382 SourceLocation KindKwLoc,
1383 SourceLocation StartLoc,
1384 SourceLocation LParenLoc,
1385 SourceLocation EndLoc) {
1386 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1387 StartLoc, LParenLoc, EndLoc);
1388 }
1389
Alexey Bataev56dafe82014-06-20 07:16:17 +00001390 /// \brief Build a new OpenMP 'schedule' clause.
1391 ///
1392 /// By default, performs semantic analysis to build the new OpenMP clause.
1393 /// Subclasses may override this routine to provide different behavior.
1394 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1395 Expr *ChunkSize,
1396 SourceLocation StartLoc,
1397 SourceLocation LParenLoc,
1398 SourceLocation KindLoc,
1399 SourceLocation CommaLoc,
1400 SourceLocation EndLoc) {
1401 return getSema().ActOnOpenMPScheduleClause(
1402 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1403 }
1404
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001405 /// \brief Build a new OpenMP 'private' clause.
1406 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001407 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001408 /// Subclasses may override this routine to provide different behavior.
1409 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1410 SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1414 EndLoc);
1415 }
1416
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001417 /// \brief Build a new OpenMP 'firstprivate' clause.
1418 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001419 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001420 /// Subclasses may override this routine to provide different behavior.
1421 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1422 SourceLocation StartLoc,
1423 SourceLocation LParenLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1426 EndLoc);
1427 }
1428
Alexander Musman1bb328c2014-06-04 13:06:39 +00001429 /// \brief Build a new OpenMP 'lastprivate' clause.
1430 ///
1431 /// By default, performs semantic analysis to build the new OpenMP clause.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1438 EndLoc);
1439 }
1440
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001441 /// \brief Build a new OpenMP 'shared' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001444 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001445 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1450 EndLoc);
1451 }
1452
Alexey Bataevc5e02582014-06-16 07:08:35 +00001453 /// \brief Build a new OpenMP 'reduction' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new statement.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1458 SourceLocation StartLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation ColonLoc,
1461 SourceLocation EndLoc,
1462 CXXScopeSpec &ReductionIdScopeSpec,
1463 const DeclarationNameInfo &ReductionId) {
1464 return getSema().ActOnOpenMPReductionClause(
1465 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1466 ReductionId);
1467 }
1468
Alexander Musman8dba6642014-04-22 13:09:42 +00001469 /// \brief Build a new OpenMP 'linear' clause.
1470 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001471 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001472 /// Subclasses may override this routine to provide different behavior.
1473 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation ColonLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1479 ColonLoc, EndLoc);
1480 }
1481
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001482 /// \brief Build a new OpenMP 'aligned' clause.
1483 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001484 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001485 /// Subclasses may override this routine to provide different behavior.
1486 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1487 SourceLocation StartLoc,
1488 SourceLocation LParenLoc,
1489 SourceLocation ColonLoc,
1490 SourceLocation EndLoc) {
1491 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1492 LParenLoc, ColonLoc, EndLoc);
1493 }
1494
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001495 /// \brief Build a new OpenMP 'copyin' clause.
1496 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001497 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001498 /// Subclasses may override this routine to provide different behavior.
1499 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1500 SourceLocation StartLoc,
1501 SourceLocation LParenLoc,
1502 SourceLocation EndLoc) {
1503 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1504 EndLoc);
1505 }
1506
Alexey Bataevbae9a792014-06-27 10:37:06 +00001507 /// \brief Build a new OpenMP 'copyprivate' clause.
1508 ///
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1512 SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1516 EndLoc);
1517 }
1518
Alexey Bataev6125da92014-07-21 11:26:11 +00001519 /// \brief Build a new OpenMP 'flush' pseudo clause.
1520 ///
1521 /// By default, performs semantic analysis to build the new OpenMP clause.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1528 EndLoc);
1529 }
1530
James Dennett2a4d13c2012-06-15 07:13:21 +00001531 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001532 ///
1533 /// By default, performs semantic analysis to build the new statement.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1536 Expr *object) {
1537 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1538 }
1539
James Dennett2a4d13c2012-06-15 07:13:21 +00001540 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001541 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001542 /// By default, performs semantic analysis to build the new statement.
1543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001544 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001545 Expr *Object, Stmt *Body) {
1546 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001547 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001548
James Dennett2a4d13c2012-06-15 07:13:21 +00001549 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1553 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1554 Stmt *Body) {
1555 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1556 }
John McCall53848232011-07-27 01:07:15 +00001557
Douglas Gregorf68a5082010-04-22 23:10:45 +00001558 /// \brief Build a new Objective-C fast enumeration statement.
1559 ///
1560 /// By default, performs semantic analysis to build the new statement.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001563 Stmt *Element,
1564 Expr *Collection,
1565 SourceLocation RParenLoc,
1566 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001567 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001568 Element,
John McCallb268a282010-08-23 23:25:46 +00001569 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001570 RParenLoc);
1571 if (ForEachStmt.isInvalid())
1572 return StmtError();
1573
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001574 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001576
Douglas Gregorebe10102009-08-20 07:17:43 +00001577 /// \brief Build a new C++ exception declaration.
1578 ///
1579 /// By default, performs semantic analysis to build the new decaration.
1580 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001581 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001582 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001583 SourceLocation StartLoc,
1584 SourceLocation IdLoc,
1585 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001586 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001587 StartLoc, IdLoc, Id);
1588 if (Var)
1589 getSema().CurContext->addDecl(Var);
1590 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001591 }
1592
1593 /// \brief Build a new C++ catch statement.
1594 ///
1595 /// By default, performs semantic analysis to build the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001598 VarDecl *ExceptionDecl,
1599 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001600 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1601 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001602 }
Mike Stump11289f42009-09-09 15:08:12 +00001603
Douglas Gregorebe10102009-08-20 07:17:43 +00001604 /// \brief Build a new C++ try statement.
1605 ///
1606 /// By default, performs semantic analysis to build the new statement.
1607 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001608 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1609 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001610 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001611 }
Mike Stump11289f42009-09-09 15:08:12 +00001612
Richard Smith02e85f32011-04-14 22:09:26 +00001613 /// \brief Build a new C++0x range-based for statement.
1614 ///
1615 /// By default, performs semantic analysis to build the new statement.
1616 /// Subclasses may override this routine to provide different behavior.
1617 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1618 SourceLocation ColonLoc,
1619 Stmt *Range, Stmt *BeginEnd,
1620 Expr *Cond, Expr *Inc,
1621 Stmt *LoopVar,
1622 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001623 // If we've just learned that the range is actually an Objective-C
1624 // collection, treat this as an Objective-C fast enumeration loop.
1625 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1626 if (RangeStmt->isSingleDecl()) {
1627 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001628 if (RangeVar->isInvalidDecl())
1629 return StmtError();
1630
Douglas Gregorf7106af2013-04-08 18:40:13 +00001631 Expr *RangeExpr = RangeVar->getInit();
1632 if (!RangeExpr->isTypeDependent() &&
1633 RangeExpr->getType()->isObjCObjectPointerType())
1634 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1635 RParenLoc);
1636 }
1637 }
1638 }
1639
Richard Smith02e85f32011-04-14 22:09:26 +00001640 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001641 Cond, Inc, LoopVar, RParenLoc,
1642 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001643 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001644
1645 /// \brief Build a new C++0x range-based for statement.
1646 ///
1647 /// By default, performs semantic analysis to build the new statement.
1648 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001649 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001650 bool IsIfExists,
1651 NestedNameSpecifierLoc QualifierLoc,
1652 DeclarationNameInfo NameInfo,
1653 Stmt *Nested) {
1654 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1655 QualifierLoc, NameInfo, Nested);
1656 }
1657
Richard Smith02e85f32011-04-14 22:09:26 +00001658 /// \brief Attach body to a C++0x range-based for statement.
1659 ///
1660 /// By default, performs semantic analysis to finish the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
1662 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1663 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001665
David Majnemerfad8f482013-10-15 09:33:02 +00001666 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001667 Stmt *TryBlock, Stmt *Handler) {
1668 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001669 }
1670
David Majnemerfad8f482013-10-15 09:33:02 +00001671 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001672 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001673 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001674 }
1675
David Majnemerfad8f482013-10-15 09:33:02 +00001676 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1677 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001678 }
1679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 /// \brief Build a new expression that references a declaration.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001685 LookupResult &R,
1686 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001687 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1688 }
1689
1690
1691 /// \brief Build a new expression that references a declaration.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001695 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001696 ValueDecl *VD,
1697 const DeclarationNameInfo &NameInfo,
1698 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001699 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001700 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001701
1702 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001703
1704 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 }
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001708 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001713 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
1715
Douglas Gregorad8a3362009-09-04 17:36:40 +00001716 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001720 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001721 SourceLocation OperatorLoc,
1722 bool isArrow,
1723 CXXScopeSpec &SS,
1724 TypeSourceInfo *ScopeType,
1725 SourceLocation CCLoc,
1726 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001727 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001728
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001730 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001733 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001734 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001735 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001736 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
Mike Stump11289f42009-09-09 15:08:12 +00001738
Douglas Gregor882211c2010-04-28 22:16:22 +00001739 /// \brief Build a new builtin offsetof expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001744 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001745 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001746 unsigned NumComponents,
1747 SourceLocation RParenLoc) {
1748 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1749 NumComponents, RParenLoc);
1750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001751
1752 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001753 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001757 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1758 SourceLocation OpLoc,
1759 UnaryExprOrTypeTrait ExprKind,
1760 SourceRange R) {
1761 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 }
1763
Peter Collingbournee190dee2011-03-11 19:24:49 +00001764 /// \brief Build a new sizeof, alignof or vec step expression with an
1765 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001766 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001769 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1770 UnaryExprOrTypeTrait ExprKind,
1771 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001773 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001776
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001777 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 }
Mike Stump11289f42009-09-09 15:08:12 +00001779
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001781 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001784 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001786 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001788 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001789 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 RBracketLoc);
1791 }
1792
1793 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001794 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001797 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001799 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001800 Expr *ExecConfig = nullptr) {
1801 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001802 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 }
1804
1805 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001806 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001810 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001811 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001812 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001813 const DeclarationNameInfo &MemberNameInfo,
1814 ValueDecl *Member,
1815 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001816 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001817 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001818 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1819 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001820 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001821 // We have a reference to an unnamed field. This is always the
1822 // base of an anonymous struct/union member access, i.e. the
1823 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001824 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001825 assert(Member->getType()->isRecordType() &&
1826 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001827
Richard Smithcab9a7d2011-10-26 19:06:56 +00001828 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001829 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001830 QualifierLoc.getNestedNameSpecifier(),
1831 FoundDecl, Member);
1832 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001833 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001834 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001835 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001836 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001837 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001838 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001839 cast<FieldDecl>(Member)->getType(),
1840 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001841 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001844 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001845 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001846
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001847 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001848 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001849
John McCall16df1e52010-03-30 21:47:33 +00001850 // FIXME: this involves duplicating earlier analysis in a lot of
1851 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001852 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001853 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001854 R.resolveKind();
1855
John McCallb268a282010-08-23 23:25:46 +00001856 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001857 SS, TemplateKWLoc,
1858 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001859 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001863 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001866 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001867 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001868 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001869 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 }
1871
1872 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001873 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001877 SourceLocation QuestionLoc,
1878 Expr *LHS,
1879 SourceLocation ColonLoc,
1880 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001881 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1882 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 }
1884
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001886 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001890 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001892 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001893 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001894 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 }
Mike Stump11289f42009-09-09 15:08:12 +00001896
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001898 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001901 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001902 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001904 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001905 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001906 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 }
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001910 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 SourceLocation OpLoc,
1915 SourceLocation AccessorLoc,
1916 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001917
John McCall10eae182009-11-30 22:42:35 +00001918 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001919 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001920 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001921 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001922 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001923 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001924 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001925 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 }
Mike Stump11289f42009-09-09 15:08:12 +00001927
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001929 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001932 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001933 MultiExprArg Inits,
1934 SourceLocation RBraceLoc,
1935 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001936 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001937 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001938 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001939 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001940
Douglas Gregord3d93062009-11-09 17:16:50 +00001941 // Patch in the result type we were given, which may have been computed
1942 // when the initial InitListExpr was built.
1943 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1944 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001945 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001949 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 MultiExprArg ArrayExprs,
1954 SourceLocation EqualOrColonLoc,
1955 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001956 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001959 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001962
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001963 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 }
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001967 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// By default, builds the implicit value initialization without performing
1969 /// any semantic analysis. Subclasses may override this routine to provide
1970 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001972 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 }
Mike Stump11289f42009-09-09 15:08:12 +00001974
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001976 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001980 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001981 SourceLocation RParenLoc) {
1982 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001983 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001984 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 }
1986
1987 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001988 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001991 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001992 MultiExprArg SubExprs,
1993 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001994 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 }
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001998 ///
1999 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// rather than attempting to map the label statement itself.
2001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002003 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002004 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 }
Mike Stump11289f42009-09-09 15:08:12 +00002006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002008 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002011 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002012 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002014 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// \brief Build a new __builtin_choose_expr expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002022 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 SourceLocation RParenLoc) {
2024 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002025 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 RParenLoc);
2027 }
Mike Stump11289f42009-09-09 15:08:12 +00002028
Peter Collingbourne91147592011-04-15 00:35:48 +00002029 /// \brief Build a new generic selection expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
2033 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2034 SourceLocation DefaultLoc,
2035 SourceLocation RParenLoc,
2036 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002037 ArrayRef<TypeSourceInfo *> Types,
2038 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002039 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002040 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002041 }
2042
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 /// \brief Build a new overloaded operator call expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// The semantic analysis provides the behavior of template instantiation,
2047 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002048 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 /// argument-dependent lookup, etc. Subclasses may override this routine to
2050 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002053 Expr *Callee,
2054 Expr *First,
2055 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002056
2057 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 /// reinterpret_cast.
2059 ///
2060 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002061 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 Stmt::StmtClass Class,
2065 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002066 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 SourceLocation RAngleLoc,
2068 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 SourceLocation RParenLoc) {
2071 switch (Class) {
2072 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002073 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002074 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002075 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076
2077 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002078 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002079 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002080 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002083 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002084 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002085 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002089 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002090 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002091 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002094 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 }
Mike Stump11289f42009-09-09 15:08:12 +00002097
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 /// \brief Build a new C++ static_cast expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002102 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002104 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 SourceLocation RAngleLoc,
2106 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002107 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002109 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002110 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002111 SourceRange(LAngleLoc, RAngleLoc),
2112 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 }
2114
2115 /// \brief Build a new C++ dynamic_cast expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002119 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002121 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 SourceLocation RAngleLoc,
2123 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002124 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002126 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002127 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002128 SourceRange(LAngleLoc, RAngleLoc),
2129 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 }
2131
2132 /// \brief Build a new C++ reinterpret_cast expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002138 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 SourceLocation RAngleLoc,
2140 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002141 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002143 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002144 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002145 SourceRange(LAngleLoc, RAngleLoc),
2146 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 }
2148
2149 /// \brief Build a new C++ const_cast expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002155 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 SourceLocation RAngleLoc,
2157 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002158 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002160 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002161 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002162 SourceRange(LAngleLoc, RAngleLoc),
2163 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 }
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 /// \brief Build a new C++ functional-style cast expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002170 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2171 SourceLocation LParenLoc,
2172 Expr *Sub,
2173 SourceLocation RParenLoc) {
2174 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002175 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 RParenLoc);
2177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 /// \brief Build a new C++ typeid(type) expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002184 SourceLocation TypeidLoc,
2185 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002187 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002188 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 }
Mike Stump11289f42009-09-09 15:08:12 +00002190
Francois Pichet9f4f2072010-09-08 12:20:18 +00002191
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 /// \brief Build a new C++ typeid(expr) expression.
2193 ///
2194 /// By default, performs semantic analysis to build the new expression.
2195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002197 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002198 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002200 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002201 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002202 }
2203
Francois Pichet9f4f2072010-09-08 12:20:18 +00002204 /// \brief Build a new C++ __uuidof(type) expression.
2205 ///
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
2208 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2209 SourceLocation TypeidLoc,
2210 TypeSourceInfo *Operand,
2211 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002212 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002213 RParenLoc);
2214 }
2215
2216 /// \brief Build a new C++ __uuidof(expr) expression.
2217 ///
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
2220 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2221 SourceLocation TypeidLoc,
2222 Expr *Operand,
2223 SourceLocation RParenLoc) {
2224 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2225 RParenLoc);
2226 }
2227
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 /// \brief Build a new C++ "this" expression.
2229 ///
2230 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002231 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002233 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002234 QualType ThisType,
2235 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002236 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002237 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 }
2239
2240 /// \brief Build a new C++ throw expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002244 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2245 bool IsThrownVariableInScope) {
2246 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
2248
2249 /// \brief Build a new C++ default-argument expression.
2250 ///
2251 /// By default, builds a new default-argument expression, which does not
2252 /// require any semantic analysis. Subclasses may override this routine to
2253 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002254 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002255 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002256 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 }
2258
Richard Smith852c9db2013-04-20 22:23:05 +00002259 /// \brief Build a new C++11 default-initialization expression.
2260 ///
2261 /// By default, builds a new default field initialization expression, which
2262 /// does not require any semantic analysis. Subclasses may override this
2263 /// routine to provide different behavior.
2264 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2265 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002266 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002267 }
2268
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// \brief Build a new C++ zero-initialization expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002273 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2274 SourceLocation LParenLoc,
2275 SourceLocation RParenLoc) {
2276 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002277 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 }
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 /// \brief Build a new C++ "new" expression.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002284 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002285 bool UseGlobal,
2286 SourceLocation PlacementLParen,
2287 MultiExprArg PlacementArgs,
2288 SourceLocation PlacementRParen,
2289 SourceRange TypeIdParens,
2290 QualType AllocatedType,
2291 TypeSourceInfo *AllocatedTypeInfo,
2292 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002293 SourceRange DirectInitRange,
2294 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002295 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002297 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002299 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002300 AllocatedType,
2301 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002302 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002303 DirectInitRange,
2304 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 }
Mike Stump11289f42009-09-09 15:08:12 +00002306
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 /// \brief Build a new C++ "delete" expression.
2308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002311 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 bool IsGlobalDelete,
2313 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002314 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002316 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 }
Mike Stump11289f42009-09-09 15:08:12 +00002318
Douglas Gregor29c42f22012-02-24 07:38:34 +00002319 /// \brief Build a new type trait expression.
2320 ///
2321 /// By default, performs semantic analysis to build the new expression.
2322 /// Subclasses may override this routine to provide different behavior.
2323 ExprResult RebuildTypeTrait(TypeTrait Trait,
2324 SourceLocation StartLoc,
2325 ArrayRef<TypeSourceInfo *> Args,
2326 SourceLocation RParenLoc) {
2327 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002329
John Wiegley6242b6a2011-04-28 00:16:57 +00002330 /// \brief Build a new array type trait expression.
2331 ///
2332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
2334 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2335 SourceLocation StartLoc,
2336 TypeSourceInfo *TSInfo,
2337 Expr *DimExpr,
2338 SourceLocation RParenLoc) {
2339 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2340 }
2341
John Wiegleyf9f65842011-04-25 06:54:41 +00002342 /// \brief Build a new expression trait expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
2346 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2347 SourceLocation StartLoc,
2348 Expr *Queried,
2349 SourceLocation RParenLoc) {
2350 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2351 }
2352
Mike Stump11289f42009-09-09 15:08:12 +00002353 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 /// expression.
2355 ///
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002358 ExprResult RebuildDependentScopeDeclRefExpr(
2359 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002360 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002361 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002362 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002363 bool IsAddressOfOperand,
2364 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002366 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002367
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002368 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002369 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2370 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002371
Reid Kleckner32506ed2014-06-12 23:03:48 +00002372 return getSema().BuildQualifiedDeclarationNameExpr(
2373 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 }
2375
2376 /// \brief Build a new template-id expression.
2377 ///
2378 /// By default, performs semantic analysis to build the new expression.
2379 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002380 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002381 SourceLocation TemplateKWLoc,
2382 LookupResult &R,
2383 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002384 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002385 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2386 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 }
2388
2389 /// \brief Build a new object-construction expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002394 SourceLocation Loc,
2395 CXXConstructorDecl *Constructor,
2396 bool IsElidable,
2397 MultiExprArg Args,
2398 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002399 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002400 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002401 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002402 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002403 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002404 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002405 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002406 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002407 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002408
Douglas Gregordb121ba2009-12-14 16:27:04 +00002409 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002410 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002411 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002412 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002413 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002414 RequiresZeroInit, ConstructKind,
2415 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 }
2417
2418 /// \brief Build a new object-construction expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002422 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2423 SourceLocation LParenLoc,
2424 MultiExprArg Args,
2425 SourceLocation RParenLoc) {
2426 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002428 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 RParenLoc);
2430 }
2431
2432 /// \brief Build a new object-construction expression.
2433 ///
2434 /// By default, performs semantic analysis to build the new expression.
2435 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002436 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2437 SourceLocation LParenLoc,
2438 MultiExprArg Args,
2439 SourceLocation RParenLoc) {
2440 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002442 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 RParenLoc);
2444 }
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 /// \brief Build a new member reference expression.
2447 ///
2448 /// By default, performs semantic analysis to build the new expression.
2449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002450 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002451 QualType BaseType,
2452 bool IsArrow,
2453 SourceLocation OperatorLoc,
2454 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002455 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002456 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002457 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002458 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002460 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002461
John McCallb268a282010-08-23 23:25:46 +00002462 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002463 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002464 SS, TemplateKWLoc,
2465 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002466 MemberNameInfo,
2467 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002468 }
2469
John McCall10eae182009-11-30 22:42:35 +00002470 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002471 ///
2472 /// By default, performs semantic analysis to build the new expression.
2473 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002474 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2475 SourceLocation OperatorLoc,
2476 bool IsArrow,
2477 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002478 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002479 NamedDecl *FirstQualifierInScope,
2480 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002481 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002482 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002483 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002484
John McCallb268a282010-08-23 23:25:46 +00002485 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002486 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002487 SS, TemplateKWLoc,
2488 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002489 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002490 }
Mike Stump11289f42009-09-09 15:08:12 +00002491
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002492 /// \brief Build a new noexcept expression.
2493 ///
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
2496 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2497 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2498 }
2499
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002500 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002501 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2502 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002503 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002504 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002505 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002506 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2507 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002508 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002509
2510 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2511 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002512 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002513 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002514
Patrick Beard0caa3942012-04-19 00:25:12 +00002515 /// \brief Build a new Objective-C boxed expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
2519 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2520 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002522
Ted Kremeneke65b0862012-03-06 20:05:56 +00002523 /// \brief Build a new Objective-C array literal.
2524 ///
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
2527 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2528 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002529 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002530 MultiExprArg(Elements, NumElements));
2531 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002532
2533 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002534 Expr *Base, Expr *Key,
2535 ObjCMethodDecl *getterMethod,
2536 ObjCMethodDecl *setterMethod) {
2537 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2538 getterMethod, setterMethod);
2539 }
2540
2541 /// \brief Build a new Objective-C dictionary literal.
2542 ///
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
2545 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2546 ObjCDictionaryElement *Elements,
2547 unsigned NumElements) {
2548 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2549 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002550
James Dennett2a4d13c2012-06-15 07:13:21 +00002551 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 ///
2553 /// By default, performs semantic analysis to build the new expression.
2554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002555 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002556 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002558 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002559 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002560
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002561 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002562 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002563 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002564 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002565 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002566 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002567 MultiExprArg Args,
2568 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002569 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2570 ReceiverTypeInfo->getType(),
2571 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002572 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002573 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002574 }
2575
2576 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002577 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002578 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002579 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002580 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002581 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002582 MultiExprArg Args,
2583 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002584 return SemaRef.BuildInstanceMessage(Receiver,
2585 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002586 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002587 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002588 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002589 }
2590
Douglas Gregord51d90d2010-04-26 20:11:03 +00002591 /// \brief Build a new Objective-C ivar reference expression.
2592 ///
2593 /// By default, performs semantic analysis to build the new expression.
2594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002595 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002596 SourceLocation IvarLoc,
2597 bool IsArrow, bool IsFreeIvar) {
2598 // FIXME: We lose track of the IsFreeIvar bit.
2599 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002600 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2601 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002602 /*FIXME:*/IvarLoc, IsArrow,
2603 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002604 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002605 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002606 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002607 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002608
2609 /// \brief Build a new Objective-C property reference expression.
2610 ///
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002613 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002614 ObjCPropertyDecl *Property,
2615 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002616 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002617 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2618 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2619 /*FIXME:*/PropertyLoc,
2620 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002621 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002622 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002623 NameInfo,
2624 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002625 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002626
John McCallb7bd14f2010-12-02 01:19:52 +00002627 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002628 ///
2629 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2632 ObjCMethodDecl *Getter,
2633 ObjCMethodDecl *Setter,
2634 SourceLocation PropertyLoc) {
2635 // Since these expressions can only be value-dependent, we do not
2636 // need to perform semantic analysis again.
2637 return Owned(
2638 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2639 VK_LValue, OK_ObjCProperty,
2640 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002641 }
2642
Douglas Gregord51d90d2010-04-26 20:11:03 +00002643 /// \brief Build a new Objective-C "isa" expression.
2644 ///
2645 /// By default, performs semantic analysis to build the new expression.
2646 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002647 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002648 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002649 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002650 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2651 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002652 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002653 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002654 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002655 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002656 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002658
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 /// \brief Build a new shuffle vector expression.
2660 ///
2661 /// By default, performs semantic analysis to build the new expression.
2662 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002663 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002664 MultiExprArg SubExprs,
2665 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002666 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002667 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2669 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2670 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002671 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002672
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002674 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002675 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2676 SemaRef.Context.BuiltinFnTy,
2677 VK_RValue, BuiltinLoc);
2678 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2679 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002680 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002681
2682 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002683 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002684 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002685 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002686
Douglas Gregora16548e2009-08-11 05:31:07 +00002687 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002688 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 }
John McCall31f82722010-11-12 08:19:04 +00002690
Hal Finkelc4d7c822013-09-18 03:29:45 +00002691 /// \brief Build a new convert vector expression.
2692 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2693 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2694 SourceLocation RParenLoc) {
2695 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2696 BuiltinLoc, RParenLoc);
2697 }
2698
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002699 /// \brief Build a new template argument pack expansion.
2700 ///
2701 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002702 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002703 /// different behavior.
2704 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002705 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002706 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002707 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002708 case TemplateArgument::Expression: {
2709 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002710 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2711 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002712 if (Result.isInvalid())
2713 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002714
Douglas Gregor98318c22011-01-03 21:37:45 +00002715 return TemplateArgumentLoc(Result.get(), Result.get());
2716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002717
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002718 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002719 return TemplateArgumentLoc(TemplateArgument(
2720 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002721 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002722 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002723 Pattern.getTemplateNameLoc(),
2724 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002725
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002726 case TemplateArgument::Null:
2727 case TemplateArgument::Integral:
2728 case TemplateArgument::Declaration:
2729 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002730 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002731 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002732 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002733
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002734 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002735 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002736 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002737 EllipsisLoc,
2738 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002739 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2740 Expansion);
2741 break;
2742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002743
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002744 return TemplateArgumentLoc();
2745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002746
Douglas Gregor968f23a2011-01-03 19:31:53 +00002747 /// \brief Build a new expression pack expansion.
2748 ///
2749 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002750 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002751 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002752 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002753 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002754 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002755 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002756
2757 /// \brief Build a new atomic operation expression.
2758 ///
2759 /// By default, performs semantic analysis to build the new expression.
2760 /// Subclasses may override this routine to provide different behavior.
2761 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2762 MultiExprArg SubExprs,
2763 QualType RetTy,
2764 AtomicExpr::AtomicOp Op,
2765 SourceLocation RParenLoc) {
2766 // Just create the expression; there is not any interesting semantic
2767 // analysis here because we can't actually build an AtomicExpr until
2768 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002769 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002770 RParenLoc);
2771 }
2772
John McCall31f82722010-11-12 08:19:04 +00002773private:
Douglas Gregor14454802011-02-25 02:25:35 +00002774 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2775 QualType ObjectType,
2776 NamedDecl *FirstQualifierInScope,
2777 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002778
2779 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2780 QualType ObjectType,
2781 NamedDecl *FirstQualifierInScope,
2782 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002783
2784 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2785 NamedDecl *FirstQualifierInScope,
2786 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002787};
Douglas Gregora16548e2009-08-11 05:31:07 +00002788
Douglas Gregorebe10102009-08-20 07:17:43 +00002789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002790StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002791 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002792 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002793
Douglas Gregorebe10102009-08-20 07:17:43 +00002794 switch (S->getStmtClass()) {
2795 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002796
Douglas Gregorebe10102009-08-20 07:17:43 +00002797 // Transform individual statement nodes
2798#define STMT(Node, Parent) \
2799 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002800#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002801#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002802#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002803
Douglas Gregorebe10102009-08-20 07:17:43 +00002804 // Transform expressions by calling TransformExpr.
2805#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002806#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002807#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002808#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002809 {
John McCalldadc5752010-08-24 06:29:42 +00002810 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002811 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002812 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002813
Richard Smith945f8d32013-01-14 22:39:08 +00002814 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002815 }
Mike Stump11289f42009-09-09 15:08:12 +00002816 }
2817
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002818 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002819}
Mike Stump11289f42009-09-09 15:08:12 +00002820
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002821template<typename Derived>
2822OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2823 if (!S)
2824 return S;
2825
2826 switch (S->getClauseKind()) {
2827 default: break;
2828 // Transform individual clause nodes
2829#define OPENMP_CLAUSE(Name, Class) \
2830 case OMPC_ ## Name : \
2831 return getDerived().Transform ## Class(cast<Class>(S));
2832#include "clang/Basic/OpenMPKinds.def"
2833 }
2834
2835 return S;
2836}
2837
Mike Stump11289f42009-09-09 15:08:12 +00002838
Douglas Gregore922c772009-08-04 22:27:00 +00002839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002840ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002841 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002842 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002843
2844 switch (E->getStmtClass()) {
2845 case Stmt::NoStmtClass: break;
2846#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002847#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002848#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002849 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002850#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002851 }
2852
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002853 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002854}
2855
2856template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002857ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002858 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002859 // Initializers are instantiated like expressions, except that various outer
2860 // layers are stripped.
2861 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002862 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002863
2864 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2865 Init = ExprTemp->getSubExpr();
2866
Richard Smithe6ca4752013-05-30 22:40:16 +00002867 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2868 Init = MTE->GetTemporaryExpr();
2869
Richard Smithd59b8322012-12-19 01:39:02 +00002870 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2871 Init = Binder->getSubExpr();
2872
2873 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2874 Init = ICE->getSubExprAsWritten();
2875
Richard Smithcc1b96d2013-06-12 22:31:48 +00002876 if (CXXStdInitializerListExpr *ILE =
2877 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002878 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002879
Richard Smithc6abd962014-07-25 01:12:44 +00002880 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002881 // InitListExprs. Other forms of copy-initialization will be a no-op if
2882 // the initializer is already the right type.
2883 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002884 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002885 return getDerived().TransformExpr(Init);
2886
2887 // Revert value-initialization back to empty parens.
2888 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2889 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002890 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002891 Parens.getEnd());
2892 }
2893
2894 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2895 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002896 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002897 SourceLocation());
2898
2899 // Revert initialization by constructor back to a parenthesized or braced list
2900 // of expressions. Any other form of initializer can just be reused directly.
2901 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002902 return getDerived().TransformExpr(Init);
2903
Richard Smithf8adcdc2014-07-17 05:12:35 +00002904 // If the initialization implicitly converted an initializer list to a
2905 // std::initializer_list object, unwrap the std::initializer_list too.
2906 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002907 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002908
Richard Smithd59b8322012-12-19 01:39:02 +00002909 SmallVector<Expr*, 8> NewArgs;
2910 bool ArgChanged = false;
2911 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002912 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002913 return ExprError();
2914
2915 // If this was list initialization, revert to list form.
2916 if (Construct->isListInitialization())
2917 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2918 Construct->getLocEnd(),
2919 Construct->getType());
2920
Richard Smithd59b8322012-12-19 01:39:02 +00002921 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002922 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002923 if (Parens.isInvalid()) {
2924 // This was a variable declaration's initialization for which no initializer
2925 // was specified.
2926 assert(NewArgs.empty() &&
2927 "no parens or braces but have direct init with arguments?");
2928 return ExprEmpty();
2929 }
Richard Smithd59b8322012-12-19 01:39:02 +00002930 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2931 Parens.getEnd());
2932}
2933
2934template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002935bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2936 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002937 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002938 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002939 bool *ArgChanged) {
2940 for (unsigned I = 0; I != NumInputs; ++I) {
2941 // If requested, drop call arguments that need to be dropped.
2942 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2943 if (ArgChanged)
2944 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002945
Douglas Gregora3efea12011-01-03 19:04:46 +00002946 break;
2947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Douglas Gregor968f23a2011-01-03 19:31:53 +00002949 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2950 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002951
Chris Lattner01cf8db2011-07-20 06:58:45 +00002952 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002953 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2954 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002955
Douglas Gregor968f23a2011-01-03 19:31:53 +00002956 // Determine whether the set of unexpanded parameter packs can and should
2957 // be expanded.
2958 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002959 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002960 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2961 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002962 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2963 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002964 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002965 Expand, RetainExpansion,
2966 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002967 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002968
Douglas Gregor968f23a2011-01-03 19:31:53 +00002969 if (!Expand) {
2970 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002971 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002972 // expansion.
2973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2974 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2975 if (OutPattern.isInvalid())
2976 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002977
2978 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002979 Expansion->getEllipsisLoc(),
2980 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002981 if (Out.isInvalid())
2982 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002983
Douglas Gregor968f23a2011-01-03 19:31:53 +00002984 if (ArgChanged)
2985 *ArgChanged = true;
2986 Outputs.push_back(Out.get());
2987 continue;
2988 }
John McCall542e7c62011-07-06 07:30:07 +00002989
2990 // Record right away that the argument was changed. This needs
2991 // to happen even if the array expands to nothing.
2992 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
Douglas Gregor968f23a2011-01-03 19:31:53 +00002994 // The transform has determined that we should perform an elementwise
2995 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002996 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002997 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2998 ExprResult Out = getDerived().TransformExpr(Pattern);
2999 if (Out.isInvalid())
3000 return true;
3001
Richard Smith9467be42014-06-06 17:33:35 +00003002 // FIXME: Can this happen? We should not try to expand the pack
3003 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003004 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003005 Out = getDerived().RebuildPackExpansion(
3006 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003007 if (Out.isInvalid())
3008 return true;
3009 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003010
Douglas Gregor968f23a2011-01-03 19:31:53 +00003011 Outputs.push_back(Out.get());
3012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Richard Smith9467be42014-06-06 17:33:35 +00003014 // If we're supposed to retain a pack expansion, do so by temporarily
3015 // forgetting the partially-substituted parameter pack.
3016 if (RetainExpansion) {
3017 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3018
3019 ExprResult Out = getDerived().TransformExpr(Pattern);
3020 if (Out.isInvalid())
3021 return true;
3022
3023 Out = getDerived().RebuildPackExpansion(
3024 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3025 if (Out.isInvalid())
3026 return true;
3027
3028 Outputs.push_back(Out.get());
3029 }
3030
Douglas Gregor968f23a2011-01-03 19:31:53 +00003031 continue;
3032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003033
Richard Smithd59b8322012-12-19 01:39:02 +00003034 ExprResult Result =
3035 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3036 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003037 if (Result.isInvalid())
3038 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003039
Douglas Gregora3efea12011-01-03 19:04:46 +00003040 if (Result.get() != Inputs[I] && ArgChanged)
3041 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
3043 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003044 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
Douglas Gregora3efea12011-01-03 19:04:46 +00003046 return false;
3047}
3048
3049template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003050NestedNameSpecifierLoc
3051TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3052 NestedNameSpecifierLoc NNS,
3053 QualType ObjectType,
3054 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003055 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003056 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003057 Qualifier = Qualifier.getPrefix())
3058 Qualifiers.push_back(Qualifier);
3059
3060 CXXScopeSpec SS;
3061 while (!Qualifiers.empty()) {
3062 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3063 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
Douglas Gregor14454802011-02-25 02:25:35 +00003065 switch (QNNS->getKind()) {
3066 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003067 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003068 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003069 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003070 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003071 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003072 FirstQualifierInScope, false))
3073 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003074
Douglas Gregor14454802011-02-25 02:25:35 +00003075 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003076
Douglas Gregor14454802011-02-25 02:25:35 +00003077 case NestedNameSpecifier::Namespace: {
3078 NamespaceDecl *NS
3079 = cast_or_null<NamespaceDecl>(
3080 getDerived().TransformDecl(
3081 Q.getLocalBeginLoc(),
3082 QNNS->getAsNamespace()));
3083 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3084 break;
3085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor14454802011-02-25 02:25:35 +00003087 case NestedNameSpecifier::NamespaceAlias: {
3088 NamespaceAliasDecl *Alias
3089 = cast_or_null<NamespaceAliasDecl>(
3090 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3091 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003092 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003093 Q.getLocalEndLoc());
3094 break;
3095 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003096
Douglas Gregor14454802011-02-25 02:25:35 +00003097 case NestedNameSpecifier::Global:
3098 // There is no meaningful transformation that one could perform on the
3099 // global scope.
3100 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3101 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003102
Nikola Smiljanic67860242014-09-26 00:28:20 +00003103 case NestedNameSpecifier::Super: {
3104 CXXRecordDecl *RD =
3105 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3106 SourceLocation(), QNNS->getAsRecordDecl()));
3107 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3108 break;
3109 }
3110
Douglas Gregor14454802011-02-25 02:25:35 +00003111 case NestedNameSpecifier::TypeSpecWithTemplate:
3112 case NestedNameSpecifier::TypeSpec: {
3113 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3114 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor14454802011-02-25 02:25:35 +00003116 if (!TL)
3117 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
Douglas Gregor14454802011-02-25 02:25:35 +00003119 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003120 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003121 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003122 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003123 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003124 if (TL.getType()->isEnumeralType())
3125 SemaRef.Diag(TL.getBeginLoc(),
3126 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003127 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3128 Q.getLocalEndLoc());
3129 break;
3130 }
Richard Trieude756fb2011-05-07 01:36:37 +00003131 // If the nested-name-specifier is an invalid type def, don't emit an
3132 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003133 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3134 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003135 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003136 << TL.getType() << SS.getRange();
3137 }
Douglas Gregor14454802011-02-25 02:25:35 +00003138 return NestedNameSpecifierLoc();
3139 }
Douglas Gregore16af532011-02-28 18:50:33 +00003140 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003141
Douglas Gregore16af532011-02-28 18:50:33 +00003142 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003143 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003144 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003145 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
Douglas Gregor14454802011-02-25 02:25:35 +00003147 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003148 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003149 !getDerived().AlwaysRebuild())
3150 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003151
3152 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003153 // nested-name-specifier, do so.
3154 if (SS.location_size() == NNS.getDataLength() &&
3155 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3156 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3157
3158 // Allocate new nested-name-specifier location information.
3159 return SS.getWithLocInContext(SemaRef.Context);
3160}
3161
3162template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003163DeclarationNameInfo
3164TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003165::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003166 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003167 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003168 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003169
3170 switch (Name.getNameKind()) {
3171 case DeclarationName::Identifier:
3172 case DeclarationName::ObjCZeroArgSelector:
3173 case DeclarationName::ObjCOneArgSelector:
3174 case DeclarationName::ObjCMultiArgSelector:
3175 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003176 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003177 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003178 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003179
Douglas Gregorf816bd72009-09-03 22:13:48 +00003180 case DeclarationName::CXXConstructorName:
3181 case DeclarationName::CXXDestructorName:
3182 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003183 TypeSourceInfo *NewTInfo;
3184 CanQualType NewCanTy;
3185 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003186 NewTInfo = getDerived().TransformType(OldTInfo);
3187 if (!NewTInfo)
3188 return DeclarationNameInfo();
3189 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003190 }
3191 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003192 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003193 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003194 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003195 if (NewT.isNull())
3196 return DeclarationNameInfo();
3197 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3198 }
Mike Stump11289f42009-09-09 15:08:12 +00003199
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003200 DeclarationName NewName
3201 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3202 NewCanTy);
3203 DeclarationNameInfo NewNameInfo(NameInfo);
3204 NewNameInfo.setName(NewName);
3205 NewNameInfo.setNamedTypeInfo(NewTInfo);
3206 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003207 }
Mike Stump11289f42009-09-09 15:08:12 +00003208 }
3209
David Blaikie83d382b2011-09-23 05:06:16 +00003210 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003211}
3212
3213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003214TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003215TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3216 TemplateName Name,
3217 SourceLocation NameLoc,
3218 QualType ObjectType,
3219 NamedDecl *FirstQualifierInScope) {
3220 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3221 TemplateDecl *Template = QTN->getTemplateDecl();
3222 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003223
Douglas Gregor9db53502011-03-02 18:07:45 +00003224 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003225 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003226 Template));
3227 if (!TransTemplate)
3228 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor9db53502011-03-02 18:07:45 +00003230 if (!getDerived().AlwaysRebuild() &&
3231 SS.getScopeRep() == QTN->getQualifier() &&
3232 TransTemplate == Template)
3233 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003234
Douglas Gregor9db53502011-03-02 18:07:45 +00003235 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3236 TransTemplate);
3237 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003238
Douglas Gregor9db53502011-03-02 18:07:45 +00003239 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3240 if (SS.getScopeRep()) {
3241 // These apply to the scope specifier, not the template.
3242 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003243 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003244 }
3245
Douglas Gregor9db53502011-03-02 18:07:45 +00003246 if (!getDerived().AlwaysRebuild() &&
3247 SS.getScopeRep() == DTN->getQualifier() &&
3248 ObjectType.isNull())
3249 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregor9db53502011-03-02 18:07:45 +00003251 if (DTN->isIdentifier()) {
3252 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003253 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003254 NameLoc,
3255 ObjectType,
3256 FirstQualifierInScope);
3257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003258
Douglas Gregor9db53502011-03-02 18:07:45 +00003259 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3260 ObjectType);
3261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregor9db53502011-03-02 18:07:45 +00003263 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3264 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003265 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003266 Template));
3267 if (!TransTemplate)
3268 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003269
Douglas Gregor9db53502011-03-02 18:07:45 +00003270 if (!getDerived().AlwaysRebuild() &&
3271 TransTemplate == Template)
3272 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
Douglas Gregor9db53502011-03-02 18:07:45 +00003274 return TemplateName(TransTemplate);
3275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor9db53502011-03-02 18:07:45 +00003277 if (SubstTemplateTemplateParmPackStorage *SubstPack
3278 = Name.getAsSubstTemplateTemplateParmPack()) {
3279 TemplateTemplateParmDecl *TransParam
3280 = cast_or_null<TemplateTemplateParmDecl>(
3281 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3282 if (!TransParam)
3283 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
Douglas Gregor9db53502011-03-02 18:07:45 +00003285 if (!getDerived().AlwaysRebuild() &&
3286 TransParam == SubstPack->getParameterPack())
3287 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
3289 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003290 SubstPack->getArgumentPack());
3291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregor9db53502011-03-02 18:07:45 +00003293 // These should be getting filtered out before they reach the AST.
3294 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003295}
3296
3297template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003298void TreeTransform<Derived>::InventTemplateArgumentLoc(
3299 const TemplateArgument &Arg,
3300 TemplateArgumentLoc &Output) {
3301 SourceLocation Loc = getDerived().getBaseLocation();
3302 switch (Arg.getKind()) {
3303 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003304 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003305 break;
3306
3307 case TemplateArgument::Type:
3308 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003309 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
John McCall0ad16662009-10-29 08:12:44 +00003311 break;
3312
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003313 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003314 case TemplateArgument::TemplateExpansion: {
3315 NestedNameSpecifierLocBuilder Builder;
3316 TemplateName Template = Arg.getAsTemplate();
3317 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3318 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3319 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3320 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregor9d802122011-03-02 17:09:35 +00003322 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003323 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003324 Builder.getWithLocInContext(SemaRef.Context),
3325 Loc);
3326 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003327 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003328 Builder.getWithLocInContext(SemaRef.Context),
3329 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003330
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003331 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003332 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003333
John McCall0ad16662009-10-29 08:12:44 +00003334 case TemplateArgument::Expression:
3335 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3336 break;
3337
3338 case TemplateArgument::Declaration:
3339 case TemplateArgument::Integral:
3340 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003341 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003342 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003343 break;
3344 }
3345}
3346
3347template<typename Derived>
3348bool TreeTransform<Derived>::TransformTemplateArgument(
3349 const TemplateArgumentLoc &Input,
3350 TemplateArgumentLoc &Output) {
3351 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003352 switch (Arg.getKind()) {
3353 case TemplateArgument::Null:
3354 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003355 case TemplateArgument::Pack:
3356 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003357 case TemplateArgument::NullPtr:
3358 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003359
Douglas Gregore922c772009-08-04 22:27:00 +00003360 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003361 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003362 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003363 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003364
3365 DI = getDerived().TransformType(DI);
3366 if (!DI) return true;
3367
3368 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3369 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003370 }
Mike Stump11289f42009-09-09 15:08:12 +00003371
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003372 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003373 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3374 if (QualifierLoc) {
3375 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3376 if (!QualifierLoc)
3377 return true;
3378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregordf846d12011-03-02 18:46:51 +00003380 CXXScopeSpec SS;
3381 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003382 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003383 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3384 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003385 if (Template.isNull())
3386 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor9d802122011-03-02 17:09:35 +00003388 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003389 Input.getTemplateNameLoc());
3390 return false;
3391 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003392
3393 case TemplateArgument::TemplateExpansion:
3394 llvm_unreachable("Caller should expand pack expansions");
3395
Douglas Gregore922c772009-08-04 22:27:00 +00003396 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003397 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003398 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003399 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003400
John McCall0ad16662009-10-29 08:12:44 +00003401 Expr *InputExpr = Input.getSourceExpression();
3402 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3403
Chris Lattnercdb591a2011-04-25 20:37:58 +00003404 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003405 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003406 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003407 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003408 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003409 }
Douglas Gregore922c772009-08-04 22:27:00 +00003410 }
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregore922c772009-08-04 22:27:00 +00003412 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003413 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003414}
3415
Douglas Gregorfe921a72010-12-20 23:36:19 +00003416/// \brief Iterator adaptor that invents template argument location information
3417/// for each of the template arguments in its underlying iterator.
3418template<typename Derived, typename InputIterator>
3419class TemplateArgumentLocInventIterator {
3420 TreeTransform<Derived> &Self;
3421 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregorfe921a72010-12-20 23:36:19 +00003423public:
3424 typedef TemplateArgumentLoc value_type;
3425 typedef TemplateArgumentLoc reference;
3426 typedef typename std::iterator_traits<InputIterator>::difference_type
3427 difference_type;
3428 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregorfe921a72010-12-20 23:36:19 +00003430 class pointer {
3431 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregorfe921a72010-12-20 23:36:19 +00003433 public:
3434 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003435
Douglas Gregorfe921a72010-12-20 23:36:19 +00003436 const TemplateArgumentLoc *operator->() const { return &Arg; }
3437 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregorfe921a72010-12-20 23:36:19 +00003439 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
Douglas Gregorfe921a72010-12-20 23:36:19 +00003441 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3442 InputIterator Iter)
3443 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregorfe921a72010-12-20 23:36:19 +00003445 TemplateArgumentLocInventIterator &operator++() {
3446 ++Iter;
3447 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregorfe921a72010-12-20 23:36:19 +00003450 TemplateArgumentLocInventIterator operator++(int) {
3451 TemplateArgumentLocInventIterator Old(*this);
3452 ++(*this);
3453 return Old;
3454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregorfe921a72010-12-20 23:36:19 +00003456 reference operator*() const {
3457 TemplateArgumentLoc Result;
3458 Self.InventTemplateArgumentLoc(*Iter, Result);
3459 return Result;
3460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003461
Douglas Gregorfe921a72010-12-20 23:36:19 +00003462 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregorfe921a72010-12-20 23:36:19 +00003464 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3465 const TemplateArgumentLocInventIterator &Y) {
3466 return X.Iter == Y.Iter;
3467 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003468
Douglas Gregorfe921a72010-12-20 23:36:19 +00003469 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3470 const TemplateArgumentLocInventIterator &Y) {
3471 return X.Iter != Y.Iter;
3472 }
3473};
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
Douglas Gregor42cafa82010-12-20 17:42:22 +00003475template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003476template<typename InputIterator>
3477bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3478 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003479 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003480 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003481 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003482 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003484 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3485 // Unpack argument packs, which we translate them into separate
3486 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003487 // FIXME: We could do much better if we could guarantee that the
3488 // TemplateArgumentLocInfo for the pack expansion would be usable for
3489 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003490 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003491 TemplateArgument::pack_iterator>
3492 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003493 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003494 In.getArgument().pack_begin()),
3495 PackLocIterator(*this,
3496 In.getArgument().pack_end()),
3497 Outputs))
3498 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003499
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003500 continue;
3501 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003502
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003503 if (In.getArgument().isPackExpansion()) {
3504 // We have a pack expansion, for which we will be substituting into
3505 // the pattern.
3506 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003507 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003508 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003509 = getSema().getTemplateArgumentPackExpansionPattern(
3510 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Chris Lattner01cf8db2011-07-20 06:58:45 +00003512 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003513 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3514 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003515
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003516 // Determine whether the set of unexpanded parameter packs can and should
3517 // be expanded.
3518 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003519 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003520 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003521 if (getDerived().TryExpandParameterPacks(Ellipsis,
3522 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003523 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003524 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003525 RetainExpansion,
3526 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003527 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003528
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003529 if (!Expand) {
3530 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003531 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003532 // expansion.
3533 TemplateArgumentLoc OutPattern;
3534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3535 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3536 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003538 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3539 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003540 if (Out.getArgument().isNull())
3541 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003543 Outputs.addArgument(Out);
3544 continue;
3545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003546
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003547 // The transform has determined that we should perform an elementwise
3548 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003549 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003550 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3551
3552 if (getDerived().TransformTemplateArgument(Pattern, Out))
3553 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003554
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003555 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003556 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3557 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003558 if (Out.getArgument().isNull())
3559 return true;
3560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003562 Outputs.addArgument(Out);
3563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor48d24112011-01-10 20:53:55 +00003565 // If we're supposed to retain a pack expansion, do so by temporarily
3566 // forgetting the partially-substituted parameter pack.
3567 if (RetainExpansion) {
3568 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003569
Douglas Gregor48d24112011-01-10 20:53:55 +00003570 if (getDerived().TransformTemplateArgument(Pattern, Out))
3571 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003573 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3574 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003575 if (Out.getArgument().isNull())
3576 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Douglas Gregor48d24112011-01-10 20:53:55 +00003578 Outputs.addArgument(Out);
3579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003580
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003581 continue;
3582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003583
3584 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003585 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003586 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregor42cafa82010-12-20 17:42:22 +00003588 Outputs.addArgument(Out);
3589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003590
Douglas Gregor42cafa82010-12-20 17:42:22 +00003591 return false;
3592
3593}
3594
Douglas Gregord6ff3322009-08-04 16:50:30 +00003595//===----------------------------------------------------------------------===//
3596// Type transformation
3597//===----------------------------------------------------------------------===//
3598
3599template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003600QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003601 if (getDerived().AlreadyTransformed(T))
3602 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003603
John McCall550e0c22009-10-21 00:40:46 +00003604 // Temporary workaround. All of these transformations should
3605 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003606 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3607 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
John McCall31f82722010-11-12 08:19:04 +00003609 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003610
John McCall550e0c22009-10-21 00:40:46 +00003611 if (!NewDI)
3612 return QualType();
3613
3614 return NewDI->getType();
3615}
3616
3617template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003618TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003619 // Refine the base location to the type's location.
3620 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3621 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003622 if (getDerived().AlreadyTransformed(DI->getType()))
3623 return DI;
3624
3625 TypeLocBuilder TLB;
3626
3627 TypeLoc TL = DI->getTypeLoc();
3628 TLB.reserve(TL.getFullDataSize());
3629
John McCall31f82722010-11-12 08:19:04 +00003630 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003631 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003632 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003633
John McCallbcd03502009-12-07 02:54:59 +00003634 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003635}
3636
3637template<typename Derived>
3638QualType
John McCall31f82722010-11-12 08:19:04 +00003639TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003640 switch (T.getTypeLocClass()) {
3641#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003642#define TYPELOC(CLASS, PARENT) \
3643 case TypeLoc::CLASS: \
3644 return getDerived().Transform##CLASS##Type(TLB, \
3645 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003646#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003647 }
Mike Stump11289f42009-09-09 15:08:12 +00003648
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003649 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003650}
3651
3652/// FIXME: By default, this routine adds type qualifiers only to types
3653/// that can have qualifiers, and silently suppresses those qualifiers
3654/// that are not permitted (e.g., qualifiers on reference or function
3655/// types). This is the right thing for template instantiation, but
3656/// probably not for other clients.
3657template<typename Derived>
3658QualType
3659TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003660 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003661 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003662
John McCall31f82722010-11-12 08:19:04 +00003663 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003664 if (Result.isNull())
3665 return QualType();
3666
3667 // Silently suppress qualifiers if the result type can't be qualified.
3668 // FIXME: this is the right thing for template instantiation, but
3669 // probably not for other clients.
3670 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003671 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003672
John McCall31168b02011-06-15 23:02:42 +00003673 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003674 // resulting type.
3675 if (Quals.hasObjCLifetime()) {
3676 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3677 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003678 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003679 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003680 // A lifetime qualifier applied to a substituted template parameter
3681 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003682 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003683 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003684 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3685 QualType Replacement = SubstTypeParam->getReplacementType();
3686 Qualifiers Qs = Replacement.getQualifiers();
3687 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003688 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003689 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3690 Qs);
3691 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003692 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003693 Replacement);
3694 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003695 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3696 // 'auto' types behave the same way as template parameters.
3697 QualType Deduced = AutoTy->getDeducedType();
3698 Qualifiers Qs = Deduced.getQualifiers();
3699 Qs.removeObjCLifetime();
3700 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3701 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003702 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3703 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003704 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003705 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003706 // Otherwise, complain about the addition of a qualifier to an
3707 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003708 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003709 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003710 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
Douglas Gregore46db902011-06-17 22:11:49 +00003712 Quals.removeObjCLifetime();
3713 }
3714 }
3715 }
John McCallcb0f89a2010-06-05 06:41:15 +00003716 if (!Quals.empty()) {
3717 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003718 // BuildQualifiedType might not add qualifiers if they are invalid.
3719 if (Result.hasLocalQualifiers())
3720 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003721 // No location information to preserve.
3722 }
John McCall550e0c22009-10-21 00:40:46 +00003723
3724 return Result;
3725}
3726
Douglas Gregor14454802011-02-25 02:25:35 +00003727template<typename Derived>
3728TypeLoc
3729TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3730 QualType ObjectType,
3731 NamedDecl *UnqualLookup,
3732 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003733 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003734 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003735
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003736 TypeSourceInfo *TSI =
3737 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3738 if (TSI)
3739 return TSI->getTypeLoc();
3740 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003741}
3742
Douglas Gregor579c15f2011-03-02 18:32:08 +00003743template<typename Derived>
3744TypeSourceInfo *
3745TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3746 QualType ObjectType,
3747 NamedDecl *UnqualLookup,
3748 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003749 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003750 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003751
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003752 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3753 UnqualLookup, SS);
3754}
3755
3756template <typename Derived>
3757TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3758 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3759 CXXScopeSpec &SS) {
3760 QualType T = TL.getType();
3761 assert(!getDerived().AlreadyTransformed(T));
3762
Douglas Gregor579c15f2011-03-02 18:32:08 +00003763 TypeLocBuilder TLB;
3764 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003765
Douglas Gregor579c15f2011-03-02 18:32:08 +00003766 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003767 TemplateSpecializationTypeLoc SpecTL =
3768 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
Douglas Gregor579c15f2011-03-02 18:32:08 +00003770 TemplateName Template
3771 = getDerived().TransformTemplateName(SS,
3772 SpecTL.getTypePtr()->getTemplateName(),
3773 SpecTL.getTemplateNameLoc(),
3774 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003775 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003776 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003777
3778 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003779 Template);
3780 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003781 DependentTemplateSpecializationTypeLoc SpecTL =
3782 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003783
Douglas Gregor579c15f2011-03-02 18:32:08 +00003784 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003785 = getDerived().RebuildTemplateName(SS,
3786 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003787 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003788 ObjectType, UnqualLookup);
3789 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003790 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003791
3792 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003793 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003794 Template,
3795 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003796 } else {
3797 // Nothing special needs to be done for these.
3798 Result = getDerived().TransformType(TLB, TL);
3799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003800
3801 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003802 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003803
Douglas Gregor579c15f2011-03-02 18:32:08 +00003804 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3805}
3806
John McCall550e0c22009-10-21 00:40:46 +00003807template <class TyLoc> static inline
3808QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3809 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3810 NewT.setNameLoc(T.getNameLoc());
3811 return T.getType();
3812}
3813
John McCall550e0c22009-10-21 00:40:46 +00003814template<typename Derived>
3815QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003816 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003817 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3818 NewT.setBuiltinLoc(T.getBuiltinLoc());
3819 if (T.needsExtraLocalData())
3820 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3821 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003822}
Mike Stump11289f42009-09-09 15:08:12 +00003823
Douglas Gregord6ff3322009-08-04 16:50:30 +00003824template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003825QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003826 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003827 // FIXME: recurse?
3828 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003829}
Mike Stump11289f42009-09-09 15:08:12 +00003830
Reid Kleckner0503a872013-12-05 01:23:43 +00003831template <typename Derived>
3832QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3833 AdjustedTypeLoc TL) {
3834 // Adjustments applied during transformation are handled elsewhere.
3835 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3836}
3837
Douglas Gregord6ff3322009-08-04 16:50:30 +00003838template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003839QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3840 DecayedTypeLoc TL) {
3841 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3842 if (OriginalType.isNull())
3843 return QualType();
3844
3845 QualType Result = TL.getType();
3846 if (getDerived().AlwaysRebuild() ||
3847 OriginalType != TL.getOriginalLoc().getType())
3848 Result = SemaRef.Context.getDecayedType(OriginalType);
3849 TLB.push<DecayedTypeLoc>(Result);
3850 // Nothing to set for DecayedTypeLoc.
3851 return Result;
3852}
3853
3854template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003855QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003856 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003857 QualType PointeeType
3858 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003859 if (PointeeType.isNull())
3860 return QualType();
3861
3862 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003863 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003864 // A dependent pointer type 'T *' has is being transformed such
3865 // that an Objective-C class type is being replaced for 'T'. The
3866 // resulting pointer type is an ObjCObjectPointerType, not a
3867 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003868 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003869
John McCall8b07ec22010-05-15 11:32:37 +00003870 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3871 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003872 return Result;
3873 }
John McCall31f82722010-11-12 08:19:04 +00003874
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003875 if (getDerived().AlwaysRebuild() ||
3876 PointeeType != TL.getPointeeLoc().getType()) {
3877 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3878 if (Result.isNull())
3879 return QualType();
3880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
John McCall31168b02011-06-15 23:02:42 +00003882 // Objective-C ARC can add lifetime qualifiers to the type that we're
3883 // pointing to.
3884 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003885
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003886 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3887 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003888 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889}
Mike Stump11289f42009-09-09 15:08:12 +00003890
3891template<typename Derived>
3892QualType
John McCall550e0c22009-10-21 00:40:46 +00003893TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003894 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003895 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003896 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3897 if (PointeeType.isNull())
3898 return QualType();
3899
3900 QualType Result = TL.getType();
3901 if (getDerived().AlwaysRebuild() ||
3902 PointeeType != TL.getPointeeLoc().getType()) {
3903 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003904 TL.getSigilLoc());
3905 if (Result.isNull())
3906 return QualType();
3907 }
3908
Douglas Gregor049211a2010-04-22 16:50:51 +00003909 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003910 NewT.setSigilLoc(TL.getSigilLoc());
3911 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912}
3913
John McCall70dd5f62009-10-30 00:06:24 +00003914/// Transforms a reference type. Note that somewhat paradoxically we
3915/// don't care whether the type itself is an l-value type or an r-value
3916/// type; we only care if the type was *written* as an l-value type
3917/// or an r-value type.
3918template<typename Derived>
3919QualType
3920TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003921 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003922 const ReferenceType *T = TL.getTypePtr();
3923
3924 // Note that this works with the pointee-as-written.
3925 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3926 if (PointeeType.isNull())
3927 return QualType();
3928
3929 QualType Result = TL.getType();
3930 if (getDerived().AlwaysRebuild() ||
3931 PointeeType != T->getPointeeTypeAsWritten()) {
3932 Result = getDerived().RebuildReferenceType(PointeeType,
3933 T->isSpelledAsLValue(),
3934 TL.getSigilLoc());
3935 if (Result.isNull())
3936 return QualType();
3937 }
3938
John McCall31168b02011-06-15 23:02:42 +00003939 // Objective-C ARC can add lifetime qualifiers to the type that we're
3940 // referring to.
3941 TLB.TypeWasModifiedSafely(
3942 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3943
John McCall70dd5f62009-10-30 00:06:24 +00003944 // r-value references can be rebuilt as l-value references.
3945 ReferenceTypeLoc NewTL;
3946 if (isa<LValueReferenceType>(Result))
3947 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3948 else
3949 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3950 NewTL.setSigilLoc(TL.getSigilLoc());
3951
3952 return Result;
3953}
3954
Mike Stump11289f42009-09-09 15:08:12 +00003955template<typename Derived>
3956QualType
John McCall550e0c22009-10-21 00:40:46 +00003957TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003958 LValueReferenceTypeLoc TL) {
3959 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003960}
3961
Mike Stump11289f42009-09-09 15:08:12 +00003962template<typename Derived>
3963QualType
John McCall550e0c22009-10-21 00:40:46 +00003964TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003965 RValueReferenceTypeLoc TL) {
3966 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003967}
Mike Stump11289f42009-09-09 15:08:12 +00003968
Douglas Gregord6ff3322009-08-04 16:50:30 +00003969template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003970QualType
John McCall550e0c22009-10-21 00:40:46 +00003971TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003972 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003973 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003974 if (PointeeType.isNull())
3975 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003976
Abramo Bagnara509357842011-03-05 14:42:21 +00003977 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003978 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003979 if (OldClsTInfo) {
3980 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3981 if (!NewClsTInfo)
3982 return QualType();
3983 }
3984
3985 const MemberPointerType *T = TL.getTypePtr();
3986 QualType OldClsType = QualType(T->getClass(), 0);
3987 QualType NewClsType;
3988 if (NewClsTInfo)
3989 NewClsType = NewClsTInfo->getType();
3990 else {
3991 NewClsType = getDerived().TransformType(OldClsType);
3992 if (NewClsType.isNull())
3993 return QualType();
3994 }
Mike Stump11289f42009-09-09 15:08:12 +00003995
John McCall550e0c22009-10-21 00:40:46 +00003996 QualType Result = TL.getType();
3997 if (getDerived().AlwaysRebuild() ||
3998 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003999 NewClsType != OldClsType) {
4000 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004001 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004002 if (Result.isNull())
4003 return QualType();
4004 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004005
Reid Kleckner0503a872013-12-05 01:23:43 +00004006 // If we had to adjust the pointee type when building a member pointer, make
4007 // sure to push TypeLoc info for it.
4008 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4009 if (MPT && PointeeType != MPT->getPointeeType()) {
4010 assert(isa<AdjustedType>(MPT->getPointeeType()));
4011 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4012 }
4013
John McCall550e0c22009-10-21 00:40:46 +00004014 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4015 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004016 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004017
4018 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019}
4020
Mike Stump11289f42009-09-09 15:08:12 +00004021template<typename Derived>
4022QualType
John McCall550e0c22009-10-21 00:40:46 +00004023TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004024 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004025 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004026 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027 if (ElementType.isNull())
4028 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004029
John McCall550e0c22009-10-21 00:40:46 +00004030 QualType Result = TL.getType();
4031 if (getDerived().AlwaysRebuild() ||
4032 ElementType != T->getElementType()) {
4033 Result = getDerived().RebuildConstantArrayType(ElementType,
4034 T->getSizeModifier(),
4035 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004036 T->getIndexTypeCVRQualifiers(),
4037 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004038 if (Result.isNull())
4039 return QualType();
4040 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004041
4042 // We might have either a ConstantArrayType or a VariableArrayType now:
4043 // a ConstantArrayType is allowed to have an element type which is a
4044 // VariableArrayType if the type is dependent. Fortunately, all array
4045 // types have the same location layout.
4046 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004047 NewTL.setLBracketLoc(TL.getLBracketLoc());
4048 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004049
John McCall550e0c22009-10-21 00:40:46 +00004050 Expr *Size = TL.getSizeExpr();
4051 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004052 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4053 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004054 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4055 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004056 }
4057 NewTL.setSizeExpr(Size);
4058
4059 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004060}
Mike Stump11289f42009-09-09 15:08:12 +00004061
Douglas Gregord6ff3322009-08-04 16:50:30 +00004062template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004063QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004064 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004065 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004066 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004067 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068 if (ElementType.isNull())
4069 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004070
John McCall550e0c22009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 ElementType != T->getElementType()) {
4074 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004075 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004076 T->getIndexTypeCVRQualifiers(),
4077 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
4080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004081
John McCall550e0c22009-10-21 00:40:46 +00004082 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4083 NewTL.setLBracketLoc(TL.getLBracketLoc());
4084 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004085 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004086
4087 return Result;
4088}
4089
4090template<typename Derived>
4091QualType
4092TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004094 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004095 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4096 if (ElementType.isNull())
4097 return QualType();
4098
John McCalldadc5752010-08-24 06:29:42 +00004099 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004100 = getDerived().TransformExpr(T->getSizeExpr());
4101 if (SizeResult.isInvalid())
4102 return QualType();
4103
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004104 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004105
4106 QualType Result = TL.getType();
4107 if (getDerived().AlwaysRebuild() ||
4108 ElementType != T->getElementType() ||
4109 Size != T->getSizeExpr()) {
4110 Result = getDerived().RebuildVariableArrayType(ElementType,
4111 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004112 Size,
John McCall550e0c22009-10-21 00:40:46 +00004113 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004114 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004115 if (Result.isNull())
4116 return QualType();
4117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004118
Serge Pavlov774c6d02014-02-06 03:49:11 +00004119 // We might have constant size array now, but fortunately it has the same
4120 // location layout.
4121 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004122 NewTL.setLBracketLoc(TL.getLBracketLoc());
4123 NewTL.setRBracketLoc(TL.getRBracketLoc());
4124 NewTL.setSizeExpr(Size);
4125
4126 return Result;
4127}
4128
4129template<typename Derived>
4130QualType
4131TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004132 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004133 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004134 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4135 if (ElementType.isNull())
4136 return QualType();
4137
Richard Smith764d2fe2011-12-20 02:08:33 +00004138 // Array bounds are constant expressions.
4139 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4140 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004141
John McCall33ddac02011-01-19 10:06:00 +00004142 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4143 Expr *origSize = TL.getSizeExpr();
4144 if (!origSize) origSize = T->getSizeExpr();
4145
4146 ExprResult sizeResult
4147 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004148 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004149 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004150 return QualType();
4151
John McCall33ddac02011-01-19 10:06:00 +00004152 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004153
4154 QualType Result = TL.getType();
4155 if (getDerived().AlwaysRebuild() ||
4156 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004157 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004158 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4159 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004160 size,
John McCall550e0c22009-10-21 00:40:46 +00004161 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004162 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004163 if (Result.isNull())
4164 return QualType();
4165 }
John McCall550e0c22009-10-21 00:40:46 +00004166
4167 // We might have any sort of array type now, but fortunately they
4168 // all have the same location layout.
4169 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4170 NewTL.setLBracketLoc(TL.getLBracketLoc());
4171 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004172 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004173
4174 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175}
Mike Stump11289f42009-09-09 15:08:12 +00004176
4177template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004178QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004179 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004180 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004181 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004182
4183 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184 QualType ElementType = getDerived().TransformType(T->getElementType());
4185 if (ElementType.isNull())
4186 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004187
Richard Smith764d2fe2011-12-20 02:08:33 +00004188 // Vector sizes are constant expressions.
4189 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4190 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004191
John McCalldadc5752010-08-24 06:29:42 +00004192 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004193 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004194 if (Size.isInvalid())
4195 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004196
John McCall550e0c22009-10-21 00:40:46 +00004197 QualType Result = TL.getType();
4198 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004199 ElementType != T->getElementType() ||
4200 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004201 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004202 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004203 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004204 if (Result.isNull())
4205 return QualType();
4206 }
John McCall550e0c22009-10-21 00:40:46 +00004207
4208 // Result might be dependent or not.
4209 if (isa<DependentSizedExtVectorType>(Result)) {
4210 DependentSizedExtVectorTypeLoc NewTL
4211 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4212 NewTL.setNameLoc(TL.getNameLoc());
4213 } else {
4214 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4215 NewTL.setNameLoc(TL.getNameLoc());
4216 }
4217
4218 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219}
Mike Stump11289f42009-09-09 15:08:12 +00004220
4221template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004222QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004223 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004224 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004225 QualType ElementType = getDerived().TransformType(T->getElementType());
4226 if (ElementType.isNull())
4227 return QualType();
4228
John McCall550e0c22009-10-21 00:40:46 +00004229 QualType Result = TL.getType();
4230 if (getDerived().AlwaysRebuild() ||
4231 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004232 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004233 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004234 if (Result.isNull())
4235 return QualType();
4236 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004237
John McCall550e0c22009-10-21 00:40:46 +00004238 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4239 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004240
John McCall550e0c22009-10-21 00:40:46 +00004241 return Result;
4242}
4243
4244template<typename Derived>
4245QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004246 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004247 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004248 QualType ElementType = getDerived().TransformType(T->getElementType());
4249 if (ElementType.isNull())
4250 return QualType();
4251
4252 QualType Result = TL.getType();
4253 if (getDerived().AlwaysRebuild() ||
4254 ElementType != T->getElementType()) {
4255 Result = getDerived().RebuildExtVectorType(ElementType,
4256 T->getNumElements(),
4257 /*FIXME*/ SourceLocation());
4258 if (Result.isNull())
4259 return QualType();
4260 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004261
John McCall550e0c22009-10-21 00:40:46 +00004262 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4263 NewTL.setNameLoc(TL.getNameLoc());
4264
4265 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004266}
Mike Stump11289f42009-09-09 15:08:12 +00004267
David Blaikie05785d12013-02-20 22:23:23 +00004268template <typename Derived>
4269ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4270 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4271 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004272 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004273 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004274
Douglas Gregor715e4612011-01-14 22:40:04 +00004275 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004276 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004277 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004278 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004279 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004280
Douglas Gregor715e4612011-01-14 22:40:04 +00004281 TypeLocBuilder TLB;
4282 TypeLoc NewTL = OldDI->getTypeLoc();
4283 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004284
4285 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004286 OldExpansionTL.getPatternLoc());
4287 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004288 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004289
4290 Result = RebuildPackExpansionType(Result,
4291 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004292 OldExpansionTL.getEllipsisLoc(),
4293 NumExpansions);
4294 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004295 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004296
Douglas Gregor715e4612011-01-14 22:40:04 +00004297 PackExpansionTypeLoc NewExpansionTL
4298 = TLB.push<PackExpansionTypeLoc>(Result);
4299 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4300 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4301 } else
4302 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004303 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004304 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004305
John McCall8fb0d9d2011-05-01 22:35:37 +00004306 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004307 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004308
4309 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4310 OldParm->getDeclContext(),
4311 OldParm->getInnerLocStart(),
4312 OldParm->getLocation(),
4313 OldParm->getIdentifier(),
4314 NewDI->getType(),
4315 NewDI,
4316 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004317 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004318 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4319 OldParm->getFunctionScopeIndex() + indexAdjustment);
4320 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004321}
4322
4323template<typename Derived>
4324bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004325 TransformFunctionTypeParams(SourceLocation Loc,
4326 ParmVarDecl **Params, unsigned NumParams,
4327 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004328 SmallVectorImpl<QualType> &OutParamTypes,
4329 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004330 int indexAdjustment = 0;
4331
Douglas Gregordd472162011-01-07 00:20:55 +00004332 for (unsigned i = 0; i != NumParams; ++i) {
4333 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004334 assert(OldParm->getFunctionScopeIndex() == i);
4335
David Blaikie05785d12013-02-20 22:23:23 +00004336 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004337 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004338 if (OldParm->isParameterPack()) {
4339 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004340 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004341
Douglas Gregor5499af42011-01-05 23:12:31 +00004342 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004343 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004344 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004345 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4346 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004347 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4348
Douglas Gregor5499af42011-01-05 23:12:31 +00004349 // Determine whether we should expand the parameter packs.
4350 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004351 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004352 Optional<unsigned> OrigNumExpansions =
4353 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004354 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004355 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4356 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004357 Unexpanded,
4358 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004359 RetainExpansion,
4360 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004361 return true;
4362 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004363
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 if (ShouldExpand) {
4365 // Expand the function parameter pack into multiple, separate
4366 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004367 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004368 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004369 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004370 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004371 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004372 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004373 OrigNumExpansions,
4374 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004375 if (!NewParm)
4376 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Douglas Gregordd472162011-01-07 00:20:55 +00004378 OutParamTypes.push_back(NewParm->getType());
4379 if (PVars)
4380 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004381 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004382
4383 // If we're supposed to retain a pack expansion, do so by temporarily
4384 // forgetting the partially-substituted parameter pack.
4385 if (RetainExpansion) {
4386 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004387 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004388 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004389 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004390 OrigNumExpansions,
4391 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004392 if (!NewParm)
4393 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004394
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004395 OutParamTypes.push_back(NewParm->getType());
4396 if (PVars)
4397 PVars->push_back(NewParm);
4398 }
4399
John McCall8fb0d9d2011-05-01 22:35:37 +00004400 // The next parameter should have the same adjustment as the
4401 // last thing we pushed, but we post-incremented indexAdjustment
4402 // on every push. Also, if we push nothing, the adjustment should
4403 // go down by one.
4404 indexAdjustment--;
4405
Douglas Gregor5499af42011-01-05 23:12:31 +00004406 // We're done with the pack expansion.
4407 continue;
4408 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004409
4410 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004411 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004412 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4413 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004414 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004415 NumExpansions,
4416 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004417 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004418 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004419 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004420 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004421
John McCall58f10c32010-03-11 09:03:00 +00004422 if (!NewParm)
4423 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Douglas Gregordd472162011-01-07 00:20:55 +00004425 OutParamTypes.push_back(NewParm->getType());
4426 if (PVars)
4427 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004428 continue;
4429 }
John McCall58f10c32010-03-11 09:03:00 +00004430
4431 // Deal with the possibility that we don't have a parameter
4432 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004433 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004434 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004435 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004436 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004437 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004438 = dyn_cast<PackExpansionType>(OldType)) {
4439 // We have a function parameter pack that may need to be expanded.
4440 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004441 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004442 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004443
Douglas Gregor5499af42011-01-05 23:12:31 +00004444 // Determine whether we should expand the parameter packs.
4445 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004446 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004447 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004448 Unexpanded,
4449 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004450 RetainExpansion,
4451 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004452 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004454
Douglas Gregor5499af42011-01-05 23:12:31 +00004455 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004456 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004458 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004459 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4460 QualType NewType = getDerived().TransformType(Pattern);
4461 if (NewType.isNull())
4462 return true;
John McCall58f10c32010-03-11 09:03:00 +00004463
Douglas Gregordd472162011-01-07 00:20:55 +00004464 OutParamTypes.push_back(NewType);
4465 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004466 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004467 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004468
Douglas Gregor5499af42011-01-05 23:12:31 +00004469 // We're done with the pack expansion.
4470 continue;
4471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004472
Douglas Gregor48d24112011-01-10 20:53:55 +00004473 // If we're supposed to retain a pack expansion, do so by temporarily
4474 // forgetting the partially-substituted parameter pack.
4475 if (RetainExpansion) {
4476 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4477 QualType NewType = getDerived().TransformType(Pattern);
4478 if (NewType.isNull())
4479 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004480
Douglas Gregor48d24112011-01-10 20:53:55 +00004481 OutParamTypes.push_back(NewType);
4482 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004483 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004484 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004485
Chad Rosier1dcde962012-08-08 18:46:20 +00004486 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004487 // expansion.
4488 OldType = Expansion->getPattern();
4489 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004490 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4491 NewType = getDerived().TransformType(OldType);
4492 } else {
4493 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004495
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 if (NewType.isNull())
4497 return true;
4498
4499 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004500 NewType = getSema().Context.getPackExpansionType(NewType,
4501 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004502
Douglas Gregordd472162011-01-07 00:20:55 +00004503 OutParamTypes.push_back(NewType);
4504 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004505 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004506 }
4507
John McCall8fb0d9d2011-05-01 22:35:37 +00004508#ifndef NDEBUG
4509 if (PVars) {
4510 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4511 if (ParmVarDecl *parm = (*PVars)[i])
4512 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004513 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004514#endif
4515
4516 return false;
4517}
John McCall58f10c32010-03-11 09:03:00 +00004518
4519template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004520QualType
John McCall550e0c22009-10-21 00:40:46 +00004521TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004522 FunctionProtoTypeLoc TL) {
Hans Wennborge113c202014-09-18 16:01:32 +00004523 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004524}
4525
Hans Wennborge113c202014-09-18 16:01:32 +00004526template<typename Derived>
4527QualType
4528TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4529 FunctionProtoTypeLoc TL,
4530 CXXRecordDecl *ThisContext,
4531 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004532 // Transform the parameters and return type.
4533 //
Richard Smithf623c962012-04-17 00:58:00 +00004534 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004535 // When the function has a trailing return type, we instantiate the
4536 // parameters before the return type, since the return type can then refer
4537 // to the parameters themselves (via decltype, sizeof, etc.).
4538 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004539 SmallVector<QualType, 4> ParamTypes;
4540 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004541 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004542
Douglas Gregor7fb25412010-10-01 18:44:50 +00004543 QualType ResultType;
4544
Richard Smith1226c602012-08-14 22:51:13 +00004545 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004546 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004547 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004548 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004549 return QualType();
4550
Douglas Gregor3024f072012-04-16 07:05:22 +00004551 {
4552 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004553 // If a declaration declares a member function or member function
4554 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004555 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004556 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004557 // declarator.
4558 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004559
Alp Toker42a16a62014-01-25 23:51:36 +00004560 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004561 if (ResultType.isNull())
4562 return QualType();
4563 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004564 }
4565 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004566 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004567 if (ResultType.isNull())
4568 return QualType();
4569
Alp Toker9cacbab2014-01-20 20:26:09 +00004570 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004571 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004572 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004573 return QualType();
4574 }
4575
Hans Wennborge113c202014-09-18 16:01:32 +00004576 // FIXME: Need to transform the exception-specification too.
Richard Smithf623c962012-04-17 00:58:00 +00004577
John McCall550e0c22009-10-21 00:40:46 +00004578 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004579 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004580 T->getNumParams() != ParamTypes.size() ||
4581 !std::equal(T->param_type_begin(), T->param_type_end(),
Hans Wennborge113c202014-09-18 16:01:32 +00004582 ParamTypes.begin())) {
4583 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4584 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004585 if (Result.isNull())
4586 return QualType();
4587 }
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCall550e0c22009-10-21 00:40:46 +00004589 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004590 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004591 NewTL.setLParenLoc(TL.getLParenLoc());
4592 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004593 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004594 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4595 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004596
4597 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004598}
Mike Stump11289f42009-09-09 15:08:12 +00004599
Douglas Gregord6ff3322009-08-04 16:50:30 +00004600template<typename Derived>
4601QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004602 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004603 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004604 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004605 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004606 if (ResultType.isNull())
4607 return QualType();
4608
4609 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004610 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004611 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4612
4613 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004614 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004615 NewTL.setLParenLoc(TL.getLParenLoc());
4616 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004617 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004618
4619 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004620}
Mike Stump11289f42009-09-09 15:08:12 +00004621
John McCallb96ec562009-12-04 22:46:56 +00004622template<typename Derived> QualType
4623TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004624 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004625 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004626 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004627 if (!D)
4628 return QualType();
4629
4630 QualType Result = TL.getType();
4631 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4632 Result = getDerived().RebuildUnresolvedUsingType(D);
4633 if (Result.isNull())
4634 return QualType();
4635 }
4636
4637 // We might get an arbitrary type spec type back. We should at
4638 // least always get a type spec type, though.
4639 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4640 NewTL.setNameLoc(TL.getNameLoc());
4641
4642 return Result;
4643}
4644
Douglas Gregord6ff3322009-08-04 16:50:30 +00004645template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004646QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004647 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004648 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004649 TypedefNameDecl *Typedef
4650 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4651 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652 if (!Typedef)
4653 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004654
John McCall550e0c22009-10-21 00:40:46 +00004655 QualType Result = TL.getType();
4656 if (getDerived().AlwaysRebuild() ||
4657 Typedef != T->getDecl()) {
4658 Result = getDerived().RebuildTypedefType(Typedef);
4659 if (Result.isNull())
4660 return QualType();
4661 }
Mike Stump11289f42009-09-09 15:08:12 +00004662
John McCall550e0c22009-10-21 00:40:46 +00004663 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4664 NewTL.setNameLoc(TL.getNameLoc());
4665
4666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregord6ff3322009-08-04 16:50:30 +00004669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004670QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004671 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004672 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004673 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4674 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCalldadc5752010-08-24 06:29:42 +00004676 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004677 if (E.isInvalid())
4678 return QualType();
4679
Eli Friedmane4f22df2012-02-29 04:03:55 +00004680 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4681 if (E.isInvalid())
4682 return QualType();
4683
John McCall550e0c22009-10-21 00:40:46 +00004684 QualType Result = TL.getType();
4685 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004686 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004687 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004688 if (Result.isNull())
4689 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004690 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004691 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004692
John McCall550e0c22009-10-21 00:40:46 +00004693 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004694 NewTL.setTypeofLoc(TL.getTypeofLoc());
4695 NewTL.setLParenLoc(TL.getLParenLoc());
4696 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004697
4698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699}
Mike Stump11289f42009-09-09 15:08:12 +00004700
4701template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004702QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004703 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004704 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4705 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4706 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004707 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004708
John McCall550e0c22009-10-21 00:40:46 +00004709 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004710 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4711 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004712 if (Result.isNull())
4713 return QualType();
4714 }
Mike Stump11289f42009-09-09 15:08:12 +00004715
John McCall550e0c22009-10-21 00:40:46 +00004716 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004717 NewTL.setTypeofLoc(TL.getTypeofLoc());
4718 NewTL.setLParenLoc(TL.getLParenLoc());
4719 NewTL.setRParenLoc(TL.getRParenLoc());
4720 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004721
4722 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004723}
Mike Stump11289f42009-09-09 15:08:12 +00004724
4725template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004726QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004727 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004728 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004729
Douglas Gregore922c772009-08-04 22:27:00 +00004730 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004731 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4732 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004733
John McCalldadc5752010-08-24 06:29:42 +00004734 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004735 if (E.isInvalid())
4736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004737
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004738 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004739 if (E.isInvalid())
4740 return QualType();
4741
John McCall550e0c22009-10-21 00:40:46 +00004742 QualType Result = TL.getType();
4743 if (getDerived().AlwaysRebuild() ||
4744 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004745 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004746 if (Result.isNull())
4747 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004748 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004749 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004750
John McCall550e0c22009-10-21 00:40:46 +00004751 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4752 NewTL.setNameLoc(TL.getNameLoc());
4753
4754 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004755}
4756
4757template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004758QualType TreeTransform<Derived>::TransformUnaryTransformType(
4759 TypeLocBuilder &TLB,
4760 UnaryTransformTypeLoc TL) {
4761 QualType Result = TL.getType();
4762 if (Result->isDependentType()) {
4763 const UnaryTransformType *T = TL.getTypePtr();
4764 QualType NewBase =
4765 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4766 Result = getDerived().RebuildUnaryTransformType(NewBase,
4767 T->getUTTKind(),
4768 TL.getKWLoc());
4769 if (Result.isNull())
4770 return QualType();
4771 }
4772
4773 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4774 NewTL.setKWLoc(TL.getKWLoc());
4775 NewTL.setParensRange(TL.getParensRange());
4776 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4777 return Result;
4778}
4779
4780template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004781QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4782 AutoTypeLoc TL) {
4783 const AutoType *T = TL.getTypePtr();
4784 QualType OldDeduced = T->getDeducedType();
4785 QualType NewDeduced;
4786 if (!OldDeduced.isNull()) {
4787 NewDeduced = getDerived().TransformType(OldDeduced);
4788 if (NewDeduced.isNull())
4789 return QualType();
4790 }
4791
4792 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004793 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4794 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004795 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004796 if (Result.isNull())
4797 return QualType();
4798 }
4799
4800 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4801 NewTL.setNameLoc(TL.getNameLoc());
4802
4803 return Result;
4804}
4805
4806template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004807QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004808 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004809 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004810 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004811 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4812 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004813 if (!Record)
4814 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004815
John McCall550e0c22009-10-21 00:40:46 +00004816 QualType Result = TL.getType();
4817 if (getDerived().AlwaysRebuild() ||
4818 Record != T->getDecl()) {
4819 Result = getDerived().RebuildRecordType(Record);
4820 if (Result.isNull())
4821 return QualType();
4822 }
Mike Stump11289f42009-09-09 15:08:12 +00004823
John McCall550e0c22009-10-21 00:40:46 +00004824 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4825 NewTL.setNameLoc(TL.getNameLoc());
4826
4827 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004828}
Mike Stump11289f42009-09-09 15:08:12 +00004829
4830template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004831QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004832 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004833 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004834 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004835 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4836 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004837 if (!Enum)
4838 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004839
John McCall550e0c22009-10-21 00:40:46 +00004840 QualType Result = TL.getType();
4841 if (getDerived().AlwaysRebuild() ||
4842 Enum != T->getDecl()) {
4843 Result = getDerived().RebuildEnumType(Enum);
4844 if (Result.isNull())
4845 return QualType();
4846 }
Mike Stump11289f42009-09-09 15:08:12 +00004847
John McCall550e0c22009-10-21 00:40:46 +00004848 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4849 NewTL.setNameLoc(TL.getNameLoc());
4850
4851 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004852}
John McCallfcc33b02009-09-05 00:15:47 +00004853
John McCalle78aac42010-03-10 03:28:59 +00004854template<typename Derived>
4855QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4856 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004857 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004858 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4859 TL.getTypePtr()->getDecl());
4860 if (!D) return QualType();
4861
4862 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4863 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4864 return T;
4865}
4866
Douglas Gregord6ff3322009-08-04 16:50:30 +00004867template<typename Derived>
4868QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004869 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004870 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004871 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004872}
4873
Mike Stump11289f42009-09-09 15:08:12 +00004874template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004875QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004876 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004877 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004878 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004879
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004880 // Substitute into the replacement type, which itself might involve something
4881 // that needs to be transformed. This only tends to occur with default
4882 // template arguments of template template parameters.
4883 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4884 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4885 if (Replacement.isNull())
4886 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004887
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004888 // Always canonicalize the replacement type.
4889 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4890 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004891 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004892 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004893
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004894 // Propagate type-source information.
4895 SubstTemplateTypeParmTypeLoc NewTL
4896 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4897 NewTL.setNameLoc(TL.getNameLoc());
4898 return Result;
4899
John McCallcebee162009-10-18 09:09:24 +00004900}
4901
4902template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004903QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4904 TypeLocBuilder &TLB,
4905 SubstTemplateTypeParmPackTypeLoc TL) {
4906 return TransformTypeSpecType(TLB, TL);
4907}
4908
4909template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004910QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004911 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004912 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004913 const TemplateSpecializationType *T = TL.getTypePtr();
4914
Douglas Gregordf846d12011-03-02 18:46:51 +00004915 // The nested-name-specifier never matters in a TemplateSpecializationType,
4916 // because we can't have a dependent nested-name-specifier anyway.
4917 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004918 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004919 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4920 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004921 if (Template.isNull())
4922 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004923
John McCall31f82722010-11-12 08:19:04 +00004924 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4925}
4926
Eli Friedman0dfb8892011-10-06 23:00:33 +00004927template<typename Derived>
4928QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4929 AtomicTypeLoc TL) {
4930 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4931 if (ValueType.isNull())
4932 return QualType();
4933
4934 QualType Result = TL.getType();
4935 if (getDerived().AlwaysRebuild() ||
4936 ValueType != TL.getValueLoc().getType()) {
4937 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4938 if (Result.isNull())
4939 return QualType();
4940 }
4941
4942 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4943 NewTL.setKWLoc(TL.getKWLoc());
4944 NewTL.setLParenLoc(TL.getLParenLoc());
4945 NewTL.setRParenLoc(TL.getRParenLoc());
4946
4947 return Result;
4948}
4949
Chad Rosier1dcde962012-08-08 18:46:20 +00004950 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004951 /// container that provides a \c getArgLoc() member function.
4952 ///
4953 /// This iterator is intended to be used with the iterator form of
4954 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4955 template<typename ArgLocContainer>
4956 class TemplateArgumentLocContainerIterator {
4957 ArgLocContainer *Container;
4958 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004959
Douglas Gregorfe921a72010-12-20 23:36:19 +00004960 public:
4961 typedef TemplateArgumentLoc value_type;
4962 typedef TemplateArgumentLoc reference;
4963 typedef int difference_type;
4964 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
Douglas Gregorfe921a72010-12-20 23:36:19 +00004966 class pointer {
4967 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004968
Douglas Gregorfe921a72010-12-20 23:36:19 +00004969 public:
4970 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
Douglas Gregorfe921a72010-12-20 23:36:19 +00004972 const TemplateArgumentLoc *operator->() const {
4973 return &Arg;
4974 }
4975 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004976
4977
Douglas Gregorfe921a72010-12-20 23:36:19 +00004978 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004979
Douglas Gregorfe921a72010-12-20 23:36:19 +00004980 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4981 unsigned Index)
4982 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004983
Douglas Gregorfe921a72010-12-20 23:36:19 +00004984 TemplateArgumentLocContainerIterator &operator++() {
4985 ++Index;
4986 return *this;
4987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004988
Douglas Gregorfe921a72010-12-20 23:36:19 +00004989 TemplateArgumentLocContainerIterator operator++(int) {
4990 TemplateArgumentLocContainerIterator Old(*this);
4991 ++(*this);
4992 return Old;
4993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004994
Douglas Gregorfe921a72010-12-20 23:36:19 +00004995 TemplateArgumentLoc operator*() const {
4996 return Container->getArgLoc(Index);
4997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004998
Douglas Gregorfe921a72010-12-20 23:36:19 +00004999 pointer operator->() const {
5000 return pointer(Container->getArgLoc(Index));
5001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005002
Douglas Gregorfe921a72010-12-20 23:36:19 +00005003 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005004 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005005 return X.Container == Y.Container && X.Index == Y.Index;
5006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005007
Douglas Gregorfe921a72010-12-20 23:36:19 +00005008 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005009 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005010 return !(X == Y);
5011 }
5012 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005013
5014
John McCall31f82722010-11-12 08:19:04 +00005015template <typename Derived>
5016QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5017 TypeLocBuilder &TLB,
5018 TemplateSpecializationTypeLoc TL,
5019 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005020 TemplateArgumentListInfo NewTemplateArgs;
5021 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5022 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005023 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5024 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005025 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005026 ArgIterator(TL, TL.getNumArgs()),
5027 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005028 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005029
John McCall0ad16662009-10-29 08:12:44 +00005030 // FIXME: maybe don't rebuild if all the template arguments are the same.
5031
5032 QualType Result =
5033 getDerived().RebuildTemplateSpecializationType(Template,
5034 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005035 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005036
5037 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005038 // Specializations of template template parameters are represented as
5039 // TemplateSpecializationTypes, and substitution of type alias templates
5040 // within a dependent context can transform them into
5041 // DependentTemplateSpecializationTypes.
5042 if (isa<DependentTemplateSpecializationType>(Result)) {
5043 DependentTemplateSpecializationTypeLoc NewTL
5044 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005045 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005046 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005047 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005048 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005049 NewTL.setLAngleLoc(TL.getLAngleLoc());
5050 NewTL.setRAngleLoc(TL.getRAngleLoc());
5051 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5052 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5053 return Result;
5054 }
5055
John McCall0ad16662009-10-29 08:12:44 +00005056 TemplateSpecializationTypeLoc NewTL
5057 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005058 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005059 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5060 NewTL.setLAngleLoc(TL.getLAngleLoc());
5061 NewTL.setRAngleLoc(TL.getRAngleLoc());
5062 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5063 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005064 }
Mike Stump11289f42009-09-09 15:08:12 +00005065
John McCall0ad16662009-10-29 08:12:44 +00005066 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005067}
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregor5a064722011-02-28 17:23:35 +00005069template <typename Derived>
5070QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5071 TypeLocBuilder &TLB,
5072 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005073 TemplateName Template,
5074 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005075 TemplateArgumentListInfo NewTemplateArgs;
5076 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5077 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5078 typedef TemplateArgumentLocContainerIterator<
5079 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005080 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005081 ArgIterator(TL, TL.getNumArgs()),
5082 NewTemplateArgs))
5083 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005084
Douglas Gregor5a064722011-02-28 17:23:35 +00005085 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005086
Douglas Gregor5a064722011-02-28 17:23:35 +00005087 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5088 QualType Result
5089 = getSema().Context.getDependentTemplateSpecializationType(
5090 TL.getTypePtr()->getKeyword(),
5091 DTN->getQualifier(),
5092 DTN->getIdentifier(),
5093 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005094
Douglas Gregor5a064722011-02-28 17:23:35 +00005095 DependentTemplateSpecializationTypeLoc NewTL
5096 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005097 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005098 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005099 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005100 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005101 NewTL.setLAngleLoc(TL.getLAngleLoc());
5102 NewTL.setRAngleLoc(TL.getRAngleLoc());
5103 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5104 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5105 return Result;
5106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005107
5108 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005109 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005110 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005111 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005112
Douglas Gregor5a064722011-02-28 17:23:35 +00005113 if (!Result.isNull()) {
5114 /// FIXME: Wrap this in an elaborated-type-specifier?
5115 TemplateSpecializationTypeLoc NewTL
5116 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005117 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005118 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005119 NewTL.setLAngleLoc(TL.getLAngleLoc());
5120 NewTL.setRAngleLoc(TL.getRAngleLoc());
5121 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5122 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005124
Douglas Gregor5a064722011-02-28 17:23:35 +00005125 return Result;
5126}
5127
Mike Stump11289f42009-09-09 15:08:12 +00005128template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005129QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005130TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005131 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005132 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005133
Douglas Gregor844cb502011-03-01 18:12:44 +00005134 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005135 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005136 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005137 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005138 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5139 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005140 return QualType();
5141 }
Mike Stump11289f42009-09-09 15:08:12 +00005142
John McCall31f82722010-11-12 08:19:04 +00005143 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5144 if (NamedT.isNull())
5145 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005146
Richard Smith3f1b5d02011-05-05 21:57:07 +00005147 // C++0x [dcl.type.elab]p2:
5148 // If the identifier resolves to a typedef-name or the simple-template-id
5149 // resolves to an alias template specialization, the
5150 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005151 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5152 if (const TemplateSpecializationType *TST =
5153 NamedT->getAs<TemplateSpecializationType>()) {
5154 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005155 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5156 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005157 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5158 diag::err_tag_reference_non_tag) << 4;
5159 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5160 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005161 }
5162 }
5163
John McCall550e0c22009-10-21 00:40:46 +00005164 QualType Result = TL.getType();
5165 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005166 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005167 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005168 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005169 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005170 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005171 if (Result.isNull())
5172 return QualType();
5173 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005174
Abramo Bagnara6150c882010-05-11 21:36:43 +00005175 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005176 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005177 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005178 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005179}
Mike Stump11289f42009-09-09 15:08:12 +00005180
5181template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005182QualType TreeTransform<Derived>::TransformAttributedType(
5183 TypeLocBuilder &TLB,
5184 AttributedTypeLoc TL) {
5185 const AttributedType *oldType = TL.getTypePtr();
5186 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5187 if (modifiedType.isNull())
5188 return QualType();
5189
5190 QualType result = TL.getType();
5191
5192 // FIXME: dependent operand expressions?
5193 if (getDerived().AlwaysRebuild() ||
5194 modifiedType != oldType->getModifiedType()) {
5195 // TODO: this is really lame; we should really be rebuilding the
5196 // equivalent type from first principles.
5197 QualType equivalentType
5198 = getDerived().TransformType(oldType->getEquivalentType());
5199 if (equivalentType.isNull())
5200 return QualType();
5201 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5202 modifiedType,
5203 equivalentType);
5204 }
5205
5206 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5207 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5208 if (TL.hasAttrOperand())
5209 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5210 if (TL.hasAttrExprOperand())
5211 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5212 else if (TL.hasAttrEnumOperand())
5213 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5214
5215 return result;
5216}
5217
5218template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005219QualType
5220TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5221 ParenTypeLoc TL) {
5222 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5223 if (Inner.isNull())
5224 return QualType();
5225
5226 QualType Result = TL.getType();
5227 if (getDerived().AlwaysRebuild() ||
5228 Inner != TL.getInnerLoc().getType()) {
5229 Result = getDerived().RebuildParenType(Inner);
5230 if (Result.isNull())
5231 return QualType();
5232 }
5233
5234 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5235 NewTL.setLParenLoc(TL.getLParenLoc());
5236 NewTL.setRParenLoc(TL.getRParenLoc());
5237 return Result;
5238}
5239
5240template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005241QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005242 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005243 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005244
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005245 NestedNameSpecifierLoc QualifierLoc
5246 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5247 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005248 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005249
John McCallc392f372010-06-11 00:33:02 +00005250 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005251 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005252 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005253 QualifierLoc,
5254 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005255 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005256 if (Result.isNull())
5257 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005258
Abramo Bagnarad7548482010-05-19 21:37:53 +00005259 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5260 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005261 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5262
Abramo Bagnarad7548482010-05-19 21:37:53 +00005263 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005264 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005265 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005266 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005267 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005268 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005269 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005270 NewTL.setNameLoc(TL.getNameLoc());
5271 }
John McCall550e0c22009-10-21 00:40:46 +00005272 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005273}
Mike Stump11289f42009-09-09 15:08:12 +00005274
Douglas Gregord6ff3322009-08-04 16:50:30 +00005275template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005276QualType TreeTransform<Derived>::
5277 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005278 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005279 NestedNameSpecifierLoc QualifierLoc;
5280 if (TL.getQualifierLoc()) {
5281 QualifierLoc
5282 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5283 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005284 return QualType();
5285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005286
John McCall31f82722010-11-12 08:19:04 +00005287 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005288 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005289}
5290
5291template<typename Derived>
5292QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005293TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5294 DependentTemplateSpecializationTypeLoc TL,
5295 NestedNameSpecifierLoc QualifierLoc) {
5296 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005297
Douglas Gregora7a795b2011-03-01 20:11:18 +00005298 TemplateArgumentListInfo NewTemplateArgs;
5299 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5300 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005301
Douglas Gregora7a795b2011-03-01 20:11:18 +00005302 typedef TemplateArgumentLocContainerIterator<
5303 DependentTemplateSpecializationTypeLoc> ArgIterator;
5304 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5305 ArgIterator(TL, TL.getNumArgs()),
5306 NewTemplateArgs))
5307 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005308
Douglas Gregora7a795b2011-03-01 20:11:18 +00005309 QualType Result
5310 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5311 QualifierLoc,
5312 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005313 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005314 NewTemplateArgs);
5315 if (Result.isNull())
5316 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005317
Douglas Gregora7a795b2011-03-01 20:11:18 +00005318 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5319 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005320
Douglas Gregora7a795b2011-03-01 20:11:18 +00005321 // Copy information relevant to the template specialization.
5322 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005323 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005324 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005325 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005326 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5327 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005328 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005329 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005330
Douglas Gregora7a795b2011-03-01 20:11:18 +00005331 // Copy information relevant to the elaborated type.
5332 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005333 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005334 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005335 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5336 DependentTemplateSpecializationTypeLoc SpecTL
5337 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005338 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005339 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005340 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005341 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005342 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5343 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005344 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005345 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005346 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005347 TemplateSpecializationTypeLoc SpecTL
5348 = TLB.push<TemplateSpecializationTypeLoc>(Result);
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 }
5356 return Result;
5357}
5358
5359template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005360QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5361 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005362 QualType Pattern
5363 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005364 if (Pattern.isNull())
5365 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005366
5367 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005368 if (getDerived().AlwaysRebuild() ||
5369 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005370 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005371 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005372 TL.getEllipsisLoc(),
5373 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005374 if (Result.isNull())
5375 return QualType();
5376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005377
Douglas Gregor822d0302011-01-12 17:07:58 +00005378 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5379 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5380 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005381}
5382
5383template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005384QualType
5385TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005386 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005387 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005388 TLB.pushFullCopy(TL);
5389 return TL.getType();
5390}
5391
5392template<typename Derived>
5393QualType
5394TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005395 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005396 // ObjCObjectType is never dependent.
5397 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005398 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005399}
Mike Stump11289f42009-09-09 15:08:12 +00005400
5401template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005402QualType
5403TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005404 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005405 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005406 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005407 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005408}
5409
Douglas Gregord6ff3322009-08-04 16:50:30 +00005410//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005411// Statement transformation
5412//===----------------------------------------------------------------------===//
5413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005414StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005415TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005416 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005417}
5418
5419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005420StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005421TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5422 return getDerived().TransformCompoundStmt(S, false);
5423}
5424
5425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005426StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005427TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005428 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005429 Sema::CompoundScopeRAII CompoundScope(getSema());
5430
John McCall1ababa62010-08-27 19:56:05 +00005431 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005432 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005433 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005434 for (auto *B : S->body()) {
5435 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005436 if (Result.isInvalid()) {
5437 // Immediately fail if this was a DeclStmt, since it's very
5438 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005439 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005440 return StmtError();
5441
5442 // Otherwise, just keep processing substatements and fail later.
5443 SubStmtInvalid = true;
5444 continue;
5445 }
Mike Stump11289f42009-09-09 15:08:12 +00005446
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005447 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005448 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005449 }
Mike Stump11289f42009-09-09 15:08:12 +00005450
John McCall1ababa62010-08-27 19:56:05 +00005451 if (SubStmtInvalid)
5452 return StmtError();
5453
Douglas Gregorebe10102009-08-20 07:17:43 +00005454 if (!getDerived().AlwaysRebuild() &&
5455 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005456 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005457
5458 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005459 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005460 S->getRBracLoc(),
5461 IsStmtExpr);
5462}
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregorebe10102009-08-20 07:17:43 +00005464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005465StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005466TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005467 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005468 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005469 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5470 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005471
Eli Friedman06577382009-11-19 03:14:00 +00005472 // Transform the left-hand case value.
5473 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005474 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005475 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005477
Eli Friedman06577382009-11-19 03:14:00 +00005478 // Transform the right-hand case value (for the GNU case-range extension).
5479 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005480 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005481 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005483 }
Mike Stump11289f42009-09-09 15:08:12 +00005484
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 // Build the case statement.
5486 // Case statements are always rebuilt so that they will attached to their
5487 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005488 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005489 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005491 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005492 S->getColonLoc());
5493 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregorebe10102009-08-20 07:17:43 +00005496 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005497 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005498 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005500
Douglas Gregorebe10102009-08-20 07:17:43 +00005501 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005502 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503}
5504
5505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005507TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005508 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005509 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005510 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005511 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005512
Douglas Gregorebe10102009-08-20 07:17:43 +00005513 // Default statements are always rebuilt
5514 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005515 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005516}
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregorebe10102009-08-20 07:17:43 +00005518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005519StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005520TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005521 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005522 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005524
Chris Lattnercab02a62011-02-17 20:34:02 +00005525 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5526 S->getDecl());
5527 if (!LD)
5528 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005529
5530
Douglas Gregorebe10102009-08-20 07:17:43 +00005531 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005532 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005533 cast<LabelDecl>(LD), SourceLocation(),
5534 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005535}
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregorebe10102009-08-20 07:17:43 +00005537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005538StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005539TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5540 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5541 if (SubStmt.isInvalid())
5542 return StmtError();
5543
5544 // TODO: transform attributes
5545 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5546 return S;
5547
5548 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5549 S->getAttrs(),
5550 SubStmt.get());
5551}
5552
5553template<typename Derived>
5554StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005555TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005556 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005557 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005558 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005559 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005560 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005561 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005562 getDerived().TransformDefinition(
5563 S->getConditionVariable()->getLocation(),
5564 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005565 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005567 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005568 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005569
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005570 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005571 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005572
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005573 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005574 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005575 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005576 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005577 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005579
John McCallb268a282010-08-23 23:25:46 +00005580 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005581 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005583
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005584 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005585 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005587
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005589 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005590 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005594 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005595 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005596 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005599 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005600 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 Then.get() == S->getThen() &&
5602 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005603 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005604
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005605 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005606 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005607 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005608}
5609
5610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005611StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005612TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005614 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005615 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005616 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005617 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005618 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005619 getDerived().TransformDefinition(
5620 S->getConditionVariable()->getLocation(),
5621 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005622 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005624 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005625 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005626
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005627 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005628 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005629 }
Mike Stump11289f42009-09-09 15:08:12 +00005630
Douglas Gregorebe10102009-08-20 07:17:43 +00005631 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005632 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005633 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005634 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005635 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005636 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005637
Douglas Gregorebe10102009-08-20 07:17:43 +00005638 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005639 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregorebe10102009-08-20 07:17:43 +00005643 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005644 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5645 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005646}
Mike Stump11289f42009-09-09 15:08:12 +00005647
Douglas Gregorebe10102009-08-20 07:17:43 +00005648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005649StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005650TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005651 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005652 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005653 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005654 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005655 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005656 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005657 getDerived().TransformDefinition(
5658 S->getConditionVariable()->getLocation(),
5659 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005660 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005662 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005663 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005664
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005665 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005666 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005667
5668 if (S->getCond()) {
5669 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005670 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5671 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005672 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005673 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005675 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005676 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005677 }
Mike Stump11289f42009-09-09 15:08:12 +00005678
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005679 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005680 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005681 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005684 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005685 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005686 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005689 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005690 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005692 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005694 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005695 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005696}
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorebe10102009-08-20 07:17:43 +00005698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005699StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005700TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005702 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005703 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005706 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005707 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005708 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005709 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005710
Douglas Gregorebe10102009-08-20 07:17:43 +00005711 if (!getDerived().AlwaysRebuild() &&
5712 Cond.get() == S->getCond() &&
5713 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005714 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005715
John McCallb268a282010-08-23 23:25:46 +00005716 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5717 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005718 S->getRParenLoc());
5719}
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregorebe10102009-08-20 07:17:43 +00005721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005722StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005723TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005724 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005725 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005726 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregorebe10102009-08-20 07:17:43 +00005729 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005730 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005731 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005732 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005733 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005734 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005735 getDerived().TransformDefinition(
5736 S->getConditionVariable()->getLocation(),
5737 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005738 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005739 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005740 } else {
5741 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005742
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005743 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005744 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005745
5746 if (S->getCond()) {
5747 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005748 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5749 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005750 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005751 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005752 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005753
John McCallb268a282010-08-23 23:25:46 +00005754 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005755 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005756 }
Mike Stump11289f42009-09-09 15:08:12 +00005757
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005758 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005759 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005760 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005761
Douglas Gregorebe10102009-08-20 07:17:43 +00005762 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005763 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005764 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005766
Richard Smith945f8d32013-01-14 22:39:08 +00005767 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005768 if (S->getInc() && !FullInc.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 body
John McCalldadc5752010-08-24 06:29:42 +00005772 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005773 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregorebe10102009-08-20 07:17:43 +00005776 if (!getDerived().AlwaysRebuild() &&
5777 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005778 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005779 Inc.get() == S->getInc() &&
5780 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005781 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregorebe10102009-08-20 07:17:43 +00005783 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005784 Init.get(), FullCond, ConditionVar,
5785 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005786}
5787
5788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005789StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005790TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005791 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5792 S->getLabel());
5793 if (!LD)
5794 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Douglas Gregorebe10102009-08-20 07:17:43 +00005796 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005797 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005798 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005799}
5800
5801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005803TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005804 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005805 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005807 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005808
Douglas Gregorebe10102009-08-20 07:17:43 +00005809 if (!getDerived().AlwaysRebuild() &&
5810 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005811 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005812
5813 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005814 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005815}
5816
5817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005818StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005819TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005820 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005821}
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregorebe10102009-08-20 07:17:43 +00005823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005824StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005825TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005826 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005827}
Mike Stump11289f42009-09-09 15:08:12 +00005828
Douglas Gregorebe10102009-08-20 07:17:43 +00005829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005830StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005831TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00005832 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
5833 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00005834 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005836
Mike Stump11289f42009-09-09 15:08:12 +00005837 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005838 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005839 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005840}
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregorebe10102009-08-20 07:17:43 +00005842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005843StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005844TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005845 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005846 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005847 for (auto *D : S->decls()) {
5848 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005849 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005850 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005851
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005852 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005853 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005854
Douglas Gregorebe10102009-08-20 07:17:43 +00005855 Decls.push_back(Transformed);
5856 }
Mike Stump11289f42009-09-09 15:08:12 +00005857
Douglas Gregorebe10102009-08-20 07:17:43 +00005858 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005859 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005860
Rafael Espindolaab417692013-07-09 12:05:01 +00005861 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005862}
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregorebe10102009-08-20 07:17:43 +00005864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005865StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005866TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005867
Benjamin Kramerf0623432012-08-23 22:51:59 +00005868 SmallVector<Expr*, 8> Constraints;
5869 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005870 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005871
John McCalldadc5752010-08-24 06:29:42 +00005872 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005873 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005874
5875 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Anders Carlssonaaeef072010-01-24 05:50:09 +00005877 // Go through the outputs.
5878 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005879 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
Anders Carlssonaaeef072010-01-24 05:50:09 +00005881 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005882 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005883
Anders Carlssonaaeef072010-01-24 05:50:09 +00005884 // Transform the output expr.
5885 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005886 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005887 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005889
Anders Carlssonaaeef072010-01-24 05:50:09 +00005890 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005891
John McCallb268a282010-08-23 23:25:46 +00005892 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005893 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005894
Anders Carlssonaaeef072010-01-24 05:50:09 +00005895 // Go through the inputs.
5896 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005897 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005898
Anders Carlssonaaeef072010-01-24 05:50:09 +00005899 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005900 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
Anders Carlssonaaeef072010-01-24 05:50:09 +00005902 // Transform the input expr.
5903 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005904 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005905 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005906 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005907
Anders Carlssonaaeef072010-01-24 05:50:09 +00005908 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005909
John McCallb268a282010-08-23 23:25:46 +00005910 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005912
Anders Carlssonaaeef072010-01-24 05:50:09 +00005913 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005914 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005915
5916 // Go through the clobbers.
5917 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005918 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005919
5920 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005921 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005922 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5923 S->isVolatile(), S->getNumOutputs(),
5924 S->getNumInputs(), Names.data(),
5925 Constraints, Exprs, AsmString.get(),
5926 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005927}
5928
Chad Rosier32503022012-06-11 20:47:18 +00005929template<typename Derived>
5930StmtResult
5931TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005932 ArrayRef<Token> AsmToks =
5933 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005934
John McCallf413f5e2013-05-03 00:10:13 +00005935 bool HadError = false, HadChange = false;
5936
5937 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5938 SmallVector<Expr*, 8> TransformedExprs;
5939 TransformedExprs.reserve(SrcExprs.size());
5940 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5941 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5942 if (!Result.isUsable()) {
5943 HadError = true;
5944 } else {
5945 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005946 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005947 }
5948 }
5949
5950 if (HadError) return StmtError();
5951 if (!HadChange && !getDerived().AlwaysRebuild())
5952 return Owned(S);
5953
Chad Rosierb6f46c12012-08-15 16:53:30 +00005954 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005955 AsmToks, S->getAsmString(),
5956 S->getNumOutputs(), S->getNumInputs(),
5957 S->getAllConstraints(), S->getClobbers(),
5958 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005959}
Douglas Gregorebe10102009-08-20 07:17:43 +00005960
5961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005962StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005963TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005964 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005965 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005966 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005968
Douglas Gregor96c79492010-04-23 22:50:49 +00005969 // Transform the @catch statements (if present).
5970 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005971 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005972 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005973 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005974 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005976 if (Catch.get() != S->getCatchStmt(I))
5977 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005978 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005980
Douglas Gregor306de2f2010-04-22 23:59:56 +00005981 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005982 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005983 if (S->getFinallyStmt()) {
5984 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5985 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005987 }
5988
5989 // If nothing changed, just retain this statement.
5990 if (!getDerived().AlwaysRebuild() &&
5991 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005992 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005993 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005994 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
Douglas Gregor306de2f2010-04-22 23:59:56 +00005996 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005997 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005998 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005999}
Mike Stump11289f42009-09-09 15:08:12 +00006000
Douglas Gregorebe10102009-08-20 07:17:43 +00006001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006002StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006003TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006004 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006005 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006006 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006007 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006008 if (FromVar->getTypeSourceInfo()) {
6009 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6010 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006014 QualType T;
6015 if (TSInfo)
6016 T = TSInfo->getType();
6017 else {
6018 T = getDerived().TransformType(FromVar->getType());
6019 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +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 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6024 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006025 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006026 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006027
John McCalldadc5752010-08-24 06:29:42 +00006028 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006029 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006030 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006031
6032 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006033 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006034 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006035}
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregorebe10102009-08-20 07:17:43 +00006037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006039TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006040 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006041 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006042 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006044
Douglas Gregor306de2f2010-04-22 23:59:56 +00006045 // If nothing changed, just retain this statement.
6046 if (!getDerived().AlwaysRebuild() &&
6047 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006048 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006049
6050 // Build a new statement.
6051 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006052 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006053}
Mike Stump11289f42009-09-09 15:08:12 +00006054
Douglas Gregorebe10102009-08-20 07:17:43 +00006055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006056StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006057TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006058 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006059 if (S->getThrowExpr()) {
6060 Operand = getDerived().TransformExpr(S->getThrowExpr());
6061 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006064
Douglas Gregor2900c162010-04-22 21:44:01 +00006065 if (!getDerived().AlwaysRebuild() &&
6066 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006067 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006068
John McCallb268a282010-08-23 23:25:46 +00006069 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006070}
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregorebe10102009-08-20 07:17:43 +00006072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006073StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006074TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006075 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006076 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006077 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006078 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006080 Object =
6081 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6082 Object.get());
6083 if (Object.isInvalid())
6084 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006085
Douglas Gregor6148de72010-04-22 22:01:21 +00006086 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006087 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006088 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006089 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006090
Douglas Gregor6148de72010-04-22 22:01:21 +00006091 // If nothing change, just retain the current statement.
6092 if (!getDerived().AlwaysRebuild() &&
6093 Object.get() == S->getSynchExpr() &&
6094 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006095 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006096
6097 // Build a new statement.
6098 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006099 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006100}
6101
6102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006103StmtResult
John McCall31168b02011-06-15 23:02:42 +00006104TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6105 ObjCAutoreleasePoolStmt *S) {
6106 // Transform the body.
6107 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6108 if (Body.isInvalid())
6109 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006110
John McCall31168b02011-06-15 23:02:42 +00006111 // If nothing changed, just retain this statement.
6112 if (!getDerived().AlwaysRebuild() &&
6113 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006114 return S;
John McCall31168b02011-06-15 23:02:42 +00006115
6116 // Build a new statement.
6117 return getDerived().RebuildObjCAutoreleasePoolStmt(
6118 S->getAtLoc(), Body.get());
6119}
6120
6121template<typename Derived>
6122StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006123TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006124 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006125 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006126 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006127 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006129
Douglas Gregorf68a5082010-04-22 23:10:45 +00006130 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006131 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006132 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006134
Douglas Gregorf68a5082010-04-22 23:10:45 +00006135 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006136 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006137 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006138 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006139
Douglas Gregorf68a5082010-04-22 23:10:45 +00006140 // If nothing changed, just retain this statement.
6141 if (!getDerived().AlwaysRebuild() &&
6142 Element.get() == S->getElement() &&
6143 Collection.get() == S->getCollection() &&
6144 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006145 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006146
Douglas Gregorf68a5082010-04-22 23:10:45 +00006147 // Build a new statement.
6148 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006149 Element.get(),
6150 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006151 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006152 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006153}
6154
David Majnemer5f7efef2013-10-15 09:50:08 +00006155template <typename Derived>
6156StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006158 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006159 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6160 TypeSourceInfo *T =
6161 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006162 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006163 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006164
David Majnemer5f7efef2013-10-15 09:50:08 +00006165 Var = getDerived().RebuildExceptionDecl(
6166 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6167 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006168 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 }
Mike Stump11289f42009-09-09 15:08:12 +00006171
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006173 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006174 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006176
David Majnemer5f7efef2013-10-15 09:50:08 +00006177 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006178 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006179 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006180
David Majnemer5f7efef2013-10-15 09:50:08 +00006181 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006182}
Mike Stump11289f42009-09-09 15:08:12 +00006183
David Majnemer5f7efef2013-10-15 09:50:08 +00006184template <typename Derived>
6185StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006186 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006187 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006188 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006189 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregorebe10102009-08-20 07:17:43 +00006191 // Transform the handlers.
6192 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006193 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006194 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006195 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006197 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006198
Douglas Gregorebe10102009-08-20 07:17:43 +00006199 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006200 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006201 }
Mike Stump11289f42009-09-09 15:08:12 +00006202
David Majnemer5f7efef2013-10-15 09:50:08 +00006203 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006204 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006205 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006206
John McCallb268a282010-08-23 23:25:46 +00006207 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006208 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006209}
Mike Stump11289f42009-09-09 15:08:12 +00006210
Richard Smith02e85f32011-04-14 22:09:26 +00006211template<typename Derived>
6212StmtResult
6213TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6214 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6215 if (Range.isInvalid())
6216 return StmtError();
6217
6218 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6219 if (BeginEnd.isInvalid())
6220 return StmtError();
6221
6222 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6223 if (Cond.isInvalid())
6224 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006225 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006226 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006227 if (Cond.isInvalid())
6228 return StmtError();
6229 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006230 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006231
6232 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6233 if (Inc.isInvalid())
6234 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006235 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006236 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006237
6238 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6239 if (LoopVar.isInvalid())
6240 return StmtError();
6241
6242 StmtResult NewStmt = S;
6243 if (getDerived().AlwaysRebuild() ||
6244 Range.get() != S->getRangeStmt() ||
6245 BeginEnd.get() != S->getBeginEndStmt() ||
6246 Cond.get() != S->getCond() ||
6247 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006248 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006249 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6250 S->getColonLoc(), Range.get(),
6251 BeginEnd.get(), Cond.get(),
6252 Inc.get(), LoopVar.get(),
6253 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006254 if (NewStmt.isInvalid())
6255 return StmtError();
6256 }
Richard Smith02e85f32011-04-14 22:09:26 +00006257
6258 StmtResult Body = getDerived().TransformStmt(S->getBody());
6259 if (Body.isInvalid())
6260 return StmtError();
6261
6262 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6263 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006264 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006265 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6266 S->getColonLoc(), Range.get(),
6267 BeginEnd.get(), Cond.get(),
6268 Inc.get(), LoopVar.get(),
6269 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006270 if (NewStmt.isInvalid())
6271 return StmtError();
6272 }
Richard Smith02e85f32011-04-14 22:09:26 +00006273
6274 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006275 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006276
6277 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6278}
6279
John Wiegley1c0675e2011-04-28 01:08:34 +00006280template<typename Derived>
6281StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006282TreeTransform<Derived>::TransformMSDependentExistsStmt(
6283 MSDependentExistsStmt *S) {
6284 // Transform the nested-name-specifier, if any.
6285 NestedNameSpecifierLoc QualifierLoc;
6286 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006287 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006288 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6289 if (!QualifierLoc)
6290 return StmtError();
6291 }
6292
6293 // Transform the declaration name.
6294 DeclarationNameInfo NameInfo = S->getNameInfo();
6295 if (NameInfo.getName()) {
6296 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6297 if (!NameInfo.getName())
6298 return StmtError();
6299 }
6300
6301 // Check whether anything changed.
6302 if (!getDerived().AlwaysRebuild() &&
6303 QualifierLoc == S->getQualifierLoc() &&
6304 NameInfo.getName() == S->getNameInfo().getName())
6305 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006306
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006307 // Determine whether this name exists, if we can.
6308 CXXScopeSpec SS;
6309 SS.Adopt(QualifierLoc);
6310 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006311 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006312 case Sema::IER_Exists:
6313 if (S->isIfExists())
6314 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006315
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006316 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6317
6318 case Sema::IER_DoesNotExist:
6319 if (S->isIfNotExists())
6320 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006322 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006323
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006324 case Sema::IER_Dependent:
6325 Dependent = true;
6326 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006328 case Sema::IER_Error:
6329 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006330 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006331
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006332 // We need to continue with the instantiation, so do so now.
6333 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6334 if (SubStmt.isInvalid())
6335 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006336
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006337 // If we have resolved the name, just transform to the substatement.
6338 if (!Dependent)
6339 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006340
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006341 // The name is still dependent, so build a dependent expression again.
6342 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6343 S->isIfExists(),
6344 QualifierLoc,
6345 NameInfo,
6346 SubStmt.get());
6347}
6348
6349template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006350ExprResult
6351TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6352 NestedNameSpecifierLoc QualifierLoc;
6353 if (E->getQualifierLoc()) {
6354 QualifierLoc
6355 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6356 if (!QualifierLoc)
6357 return ExprError();
6358 }
6359
6360 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6361 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6362 if (!PD)
6363 return ExprError();
6364
6365 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6366 if (Base.isInvalid())
6367 return ExprError();
6368
6369 return new (SemaRef.getASTContext())
6370 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6371 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6372 QualifierLoc, E->getMemberLoc());
6373}
6374
David Majnemerfad8f482013-10-15 09:33:02 +00006375template <typename Derived>
6376StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006377 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006378 if (TryBlock.isInvalid())
6379 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006380
6381 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006382 if (Handler.isInvalid())
6383 return StmtError();
6384
David Majnemerfad8f482013-10-15 09:33:02 +00006385 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6386 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006387 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006388
Warren Huntf6be4cb2014-07-25 20:52:51 +00006389 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6390 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006391}
6392
David Majnemerfad8f482013-10-15 09:33:02 +00006393template <typename Derived>
6394StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006395 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006396 if (Block.isInvalid())
6397 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006398
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006399 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006400}
6401
David Majnemerfad8f482013-10-15 09:33:02 +00006402template <typename Derived>
6403StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006404 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006405 if (FilterExpr.isInvalid())
6406 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006407
David Majnemer7e755502013-10-15 09:30:14 +00006408 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006409 if (Block.isInvalid())
6410 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006411
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006412 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6413 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006414}
6415
David Majnemerfad8f482013-10-15 09:33:02 +00006416template <typename Derived>
6417StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6418 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006419 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6420 else
6421 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6422}
6423
Nico Weber9b982072014-07-07 00:12:30 +00006424template<typename Derived>
6425StmtResult
6426TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6427 return S;
6428}
6429
Alexander Musman64d33f12014-06-04 07:53:32 +00006430//===----------------------------------------------------------------------===//
6431// OpenMP directive transformation
6432//===----------------------------------------------------------------------===//
6433template <typename Derived>
6434StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6435 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006436
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006437 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006438 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006439 ArrayRef<OMPClause *> Clauses = D->clauses();
6440 TClauses.reserve(Clauses.size());
6441 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6442 I != E; ++I) {
6443 if (*I) {
6444 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006445 if (Clause)
6446 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006447 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006448 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006449 }
6450 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006451 StmtResult AssociatedStmt;
6452 if (D->hasAssociatedStmt()) {
6453 if (!D->getAssociatedStmt()) {
6454 return StmtError();
6455 }
6456 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6457 if (AssociatedStmt.isInvalid()) {
6458 return StmtError();
6459 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006460 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006461 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006462 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006463 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006464
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006465 // Transform directive name for 'omp critical' directive.
6466 DeclarationNameInfo DirName;
6467 if (D->getDirectiveKind() == OMPD_critical) {
6468 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6469 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6470 }
6471
Alexander Musman64d33f12014-06-04 07:53:32 +00006472 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006473 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6474 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006475}
6476
Alexander Musman64d33f12014-06-04 07:53:32 +00006477template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006478StmtResult
6479TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6480 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006481 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6482 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006483 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6484 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6485 return Res;
6486}
6487
Alexander Musman64d33f12014-06-04 07:53:32 +00006488template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006489StmtResult
6490TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6491 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006492 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6493 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006494 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6495 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006496 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006497}
6498
Alexey Bataevf29276e2014-06-18 04:14:57 +00006499template <typename Derived>
6500StmtResult
6501TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6502 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006503 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6504 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006505 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6506 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6507 return Res;
6508}
6509
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006510template <typename Derived>
6511StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006512TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6513 DeclarationNameInfo DirName;
6514 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6515 D->getLocStart());
6516 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6517 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6518 return Res;
6519}
6520
6521template <typename Derived>
6522StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006523TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6524 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006525 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6526 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006527 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6528 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6529 return Res;
6530}
6531
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006532template <typename Derived>
6533StmtResult
6534TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6535 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006536 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6537 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006538 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6539 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6540 return Res;
6541}
6542
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006543template <typename Derived>
6544StmtResult
6545TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6546 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006547 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6548 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006549 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6550 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6551 return Res;
6552}
6553
Alexey Bataev4acb8592014-07-07 13:01:15 +00006554template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006555StmtResult
6556TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6557 DeclarationNameInfo DirName;
6558 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6559 D->getLocStart());
6560 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6561 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6562 return Res;
6563}
6564
6565template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006566StmtResult
6567TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6568 getDerived().getSema().StartOpenMPDSABlock(
6569 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6570 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6571 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6572 return Res;
6573}
6574
6575template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006576StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6577 OMPParallelForDirective *D) {
6578 DeclarationNameInfo DirName;
6579 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6580 nullptr, D->getLocStart());
6581 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6582 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6583 return Res;
6584}
6585
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006586template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006587StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6588 OMPParallelForSimdDirective *D) {
6589 DeclarationNameInfo DirName;
6590 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6591 nullptr, D->getLocStart());
6592 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6593 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6594 return Res;
6595}
6596
6597template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006598StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6599 OMPParallelSectionsDirective *D) {
6600 DeclarationNameInfo DirName;
6601 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6602 nullptr, D->getLocStart());
6603 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6604 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6605 return Res;
6606}
6607
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006608template <typename Derived>
6609StmtResult
6610TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6611 DeclarationNameInfo DirName;
6612 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6613 D->getLocStart());
6614 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6615 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6616 return Res;
6617}
6618
Alexey Bataev68446b72014-07-18 07:47:19 +00006619template <typename Derived>
6620StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6621 OMPTaskyieldDirective *D) {
6622 DeclarationNameInfo DirName;
6623 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6624 D->getLocStart());
6625 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6626 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6627 return Res;
6628}
6629
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006630template <typename Derived>
6631StmtResult
6632TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6633 DeclarationNameInfo DirName;
6634 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6635 D->getLocStart());
6636 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6637 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6638 return Res;
6639}
6640
Alexey Bataev2df347a2014-07-18 10:17:07 +00006641template <typename Derived>
6642StmtResult
6643TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6644 DeclarationNameInfo DirName;
6645 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6646 D->getLocStart());
6647 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6648 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6649 return Res;
6650}
6651
Alexey Bataev6125da92014-07-21 11:26:11 +00006652template <typename Derived>
6653StmtResult
6654TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6655 DeclarationNameInfo DirName;
6656 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6657 D->getLocStart());
6658 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6659 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6660 return Res;
6661}
6662
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006663template <typename Derived>
6664StmtResult
6665TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6666 DeclarationNameInfo DirName;
6667 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6668 D->getLocStart());
6669 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6670 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6671 return Res;
6672}
6673
Alexey Bataev0162e452014-07-22 10:10:35 +00006674template <typename Derived>
6675StmtResult
6676TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6677 DeclarationNameInfo DirName;
6678 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6679 D->getLocStart());
6680 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6681 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6682 return Res;
6683}
6684
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006685template <typename Derived>
6686StmtResult
6687TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6688 DeclarationNameInfo DirName;
6689 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6690 D->getLocStart());
6691 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6692 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6693 return Res;
6694}
6695
Alexander Musman64d33f12014-06-04 07:53:32 +00006696//===----------------------------------------------------------------------===//
6697// OpenMP clause transformation
6698//===----------------------------------------------------------------------===//
6699template <typename Derived>
6700OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006701 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6702 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006703 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006704 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006705 C->getLParenLoc(), C->getLocEnd());
6706}
6707
Alexander Musman64d33f12014-06-04 07:53:32 +00006708template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006709OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6710 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6711 if (Cond.isInvalid())
6712 return nullptr;
6713 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6714 C->getLParenLoc(), C->getLocEnd());
6715}
6716
6717template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006718OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006719TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6720 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6721 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006722 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006723 return getDerived().RebuildOMPNumThreadsClause(
6724 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006725}
6726
Alexey Bataev62c87d22014-03-21 04:51:18 +00006727template <typename Derived>
6728OMPClause *
6729TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6730 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6731 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006732 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006733 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006734 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006735}
6736
Alexander Musman8bd31e62014-05-27 15:12:19 +00006737template <typename Derived>
6738OMPClause *
6739TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6740 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6741 if (E.isInvalid())
6742 return 0;
6743 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006744 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006745}
6746
Alexander Musman64d33f12014-06-04 07:53:32 +00006747template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006748OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006749TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006750 return getDerived().RebuildOMPDefaultClause(
6751 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6752 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006753}
6754
Alexander Musman64d33f12014-06-04 07:53:32 +00006755template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006756OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006757TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006758 return getDerived().RebuildOMPProcBindClause(
6759 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6760 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006761}
6762
Alexander Musman64d33f12014-06-04 07:53:32 +00006763template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006764OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006765TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6766 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6767 if (E.isInvalid())
6768 return nullptr;
6769 return getDerived().RebuildOMPScheduleClause(
6770 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6771 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6772}
6773
6774template <typename Derived>
6775OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006776TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6777 // No need to rebuild this clause, no template-dependent parameters.
6778 return C;
6779}
6780
6781template <typename Derived>
6782OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006783TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6784 // No need to rebuild this clause, no template-dependent parameters.
6785 return C;
6786}
6787
6788template <typename Derived>
6789OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006790TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6791 // No need to rebuild this clause, no template-dependent parameters.
6792 return C;
6793}
6794
6795template <typename Derived>
6796OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006797TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6798 // No need to rebuild this clause, no template-dependent parameters.
6799 return C;
6800}
6801
6802template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006803OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6804 // No need to rebuild this clause, no template-dependent parameters.
6805 return C;
6806}
6807
6808template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006809OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6810 // No need to rebuild this clause, no template-dependent parameters.
6811 return C;
6812}
6813
6814template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006815OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006816TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6817 // No need to rebuild this clause, no template-dependent parameters.
6818 return C;
6819}
6820
6821template <typename Derived>
6822OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006823TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6824 // No need to rebuild this clause, no template-dependent parameters.
6825 return C;
6826}
6827
6828template <typename Derived>
6829OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006830TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6831 // No need to rebuild this clause, no template-dependent parameters.
6832 return C;
6833}
6834
6835template <typename Derived>
6836OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006837TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006838 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006839 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006840 for (auto *VE : C->varlists()) {
6841 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006842 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006843 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006844 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006845 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006846 return getDerived().RebuildOMPPrivateClause(
6847 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006848}
6849
Alexander Musman64d33f12014-06-04 07:53:32 +00006850template <typename Derived>
6851OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6852 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006853 llvm::SmallVector<Expr *, 16> Vars;
6854 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006855 for (auto *VE : C->varlists()) {
6856 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006857 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006858 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006859 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006860 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006861 return getDerived().RebuildOMPFirstprivateClause(
6862 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006863}
6864
Alexander Musman64d33f12014-06-04 07:53:32 +00006865template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006866OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006867TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6868 llvm::SmallVector<Expr *, 16> Vars;
6869 Vars.reserve(C->varlist_size());
6870 for (auto *VE : C->varlists()) {
6871 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6872 if (EVar.isInvalid())
6873 return nullptr;
6874 Vars.push_back(EVar.get());
6875 }
6876 return getDerived().RebuildOMPLastprivateClause(
6877 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6878}
6879
6880template <typename Derived>
6881OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006882TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6883 llvm::SmallVector<Expr *, 16> Vars;
6884 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006885 for (auto *VE : C->varlists()) {
6886 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006887 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006888 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006889 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006890 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006891 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6892 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006893}
6894
Alexander Musman64d33f12014-06-04 07:53:32 +00006895template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006896OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006897TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6898 llvm::SmallVector<Expr *, 16> Vars;
6899 Vars.reserve(C->varlist_size());
6900 for (auto *VE : C->varlists()) {
6901 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6902 if (EVar.isInvalid())
6903 return nullptr;
6904 Vars.push_back(EVar.get());
6905 }
6906 CXXScopeSpec ReductionIdScopeSpec;
6907 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6908
6909 DeclarationNameInfo NameInfo = C->getNameInfo();
6910 if (NameInfo.getName()) {
6911 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6912 if (!NameInfo.getName())
6913 return nullptr;
6914 }
6915 return getDerived().RebuildOMPReductionClause(
6916 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6917 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6918}
6919
6920template <typename Derived>
6921OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006922TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6923 llvm::SmallVector<Expr *, 16> Vars;
6924 Vars.reserve(C->varlist_size());
6925 for (auto *VE : C->varlists()) {
6926 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6927 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006928 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006929 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006930 }
6931 ExprResult Step = getDerived().TransformExpr(C->getStep());
6932 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006933 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006934 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6935 C->getLParenLoc(),
6936 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006937}
6938
Alexander Musman64d33f12014-06-04 07:53:32 +00006939template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006940OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006941TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6942 llvm::SmallVector<Expr *, 16> Vars;
6943 Vars.reserve(C->varlist_size());
6944 for (auto *VE : C->varlists()) {
6945 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6946 if (EVar.isInvalid())
6947 return nullptr;
6948 Vars.push_back(EVar.get());
6949 }
6950 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6951 if (Alignment.isInvalid())
6952 return nullptr;
6953 return getDerived().RebuildOMPAlignedClause(
6954 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6955 C->getColonLoc(), C->getLocEnd());
6956}
6957
Alexander Musman64d33f12014-06-04 07:53:32 +00006958template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006959OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006960TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6961 llvm::SmallVector<Expr *, 16> Vars;
6962 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006963 for (auto *VE : C->varlists()) {
6964 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006965 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006966 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006967 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006968 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006969 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6970 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006971}
6972
Alexey Bataevbae9a792014-06-27 10:37:06 +00006973template <typename Derived>
6974OMPClause *
6975TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6976 llvm::SmallVector<Expr *, 16> Vars;
6977 Vars.reserve(C->varlist_size());
6978 for (auto *VE : C->varlists()) {
6979 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6980 if (EVar.isInvalid())
6981 return nullptr;
6982 Vars.push_back(EVar.get());
6983 }
6984 return getDerived().RebuildOMPCopyprivateClause(
6985 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6986}
6987
Alexey Bataev6125da92014-07-21 11:26:11 +00006988template <typename Derived>
6989OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6990 llvm::SmallVector<Expr *, 16> Vars;
6991 Vars.reserve(C->varlist_size());
6992 for (auto *VE : C->varlists()) {
6993 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6994 if (EVar.isInvalid())
6995 return nullptr;
6996 Vars.push_back(EVar.get());
6997 }
6998 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6999 C->getLParenLoc(), C->getLocEnd());
7000}
7001
Douglas Gregorebe10102009-08-20 07:17:43 +00007002//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007003// Expression transformation
7004//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007007TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007008 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007009}
Mike Stump11289f42009-09-09 15:08:12 +00007010
7011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007013TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007014 NestedNameSpecifierLoc QualifierLoc;
7015 if (E->getQualifierLoc()) {
7016 QualifierLoc
7017 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7018 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007019 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007020 }
John McCallce546572009-12-08 09:08:17 +00007021
7022 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007023 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7024 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007025 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007027
John McCall815039a2010-08-17 21:27:17 +00007028 DeclarationNameInfo NameInfo = E->getNameInfo();
7029 if (NameInfo.getName()) {
7030 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7031 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007032 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007033 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007034
7035 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007036 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007037 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007038 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007039 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007040
7041 // Mark it referenced in the new context regardless.
7042 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007043 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007044
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007045 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007046 }
John McCallce546572009-12-08 09:08:17 +00007047
Craig Topperc3ec1492014-05-26 06:22:03 +00007048 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007049 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007050 TemplateArgs = &TransArgs;
7051 TransArgs.setLAngleLoc(E->getLAngleLoc());
7052 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007053 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7054 E->getNumTemplateArgs(),
7055 TransArgs))
7056 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007057 }
7058
Chad Rosier1dcde962012-08-08 18:46:20 +00007059 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007060 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007061}
Mike Stump11289f42009-09-09 15:08:12 +00007062
Douglas Gregora16548e2009-08-11 05:31:07 +00007063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007065TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007066 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007067}
Mike Stump11289f42009-09-09 15:08:12 +00007068
Douglas Gregora16548e2009-08-11 05:31:07 +00007069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007071TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007072 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007073}
Mike Stump11289f42009-09-09 15:08:12 +00007074
Douglas Gregora16548e2009-08-11 05:31:07 +00007075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007077TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007078 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007079}
Mike Stump11289f42009-09-09 15:08:12 +00007080
Douglas Gregora16548e2009-08-11 05:31:07 +00007081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007082ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007083TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007084 return E;
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>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007090 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007091}
7092
7093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007094ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007095TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007096 if (FunctionDecl *FD = E->getDirectCallee())
7097 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007098 return SemaRef.MaybeBindToTemporary(E);
7099}
7100
7101template<typename Derived>
7102ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007103TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7104 ExprResult ControllingExpr =
7105 getDerived().TransformExpr(E->getControllingExpr());
7106 if (ControllingExpr.isInvalid())
7107 return ExprError();
7108
Chris Lattner01cf8db2011-07-20 06:58:45 +00007109 SmallVector<Expr *, 4> AssocExprs;
7110 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007111 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7112 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7113 if (TS) {
7114 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7115 if (!AssocType)
7116 return ExprError();
7117 AssocTypes.push_back(AssocType);
7118 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007119 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007120 }
7121
7122 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7123 if (AssocExpr.isInvalid())
7124 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007125 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007126 }
7127
7128 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7129 E->getDefaultLoc(),
7130 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007131 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007132 AssocTypes,
7133 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007134}
7135
7136template<typename Derived>
7137ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007138TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007139 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007140 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007141 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007142
Douglas Gregora16548e2009-08-11 05:31:07 +00007143 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007144 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007145
John McCallb268a282010-08-23 23:25:46 +00007146 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 E->getRParen());
7148}
7149
Richard Smithdb2630f2012-10-21 03:28:35 +00007150/// \brief The operand of a unary address-of operator has special rules: it's
7151/// allowed to refer to a non-static member of a class even if there's no 'this'
7152/// object available.
7153template<typename Derived>
7154ExprResult
7155TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7156 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007157 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007158 else
7159 return getDerived().TransformExpr(E);
7160}
7161
Mike Stump11289f42009-09-09 15:08:12 +00007162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007164TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007165 ExprResult SubExpr;
7166 if (E->getOpcode() == UO_AddrOf)
7167 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7168 else
7169 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007170 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007172
Douglas Gregora16548e2009-08-11 05:31:07 +00007173 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007174 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007175
Douglas Gregora16548e2009-08-11 05:31:07 +00007176 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7177 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007178 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007179}
Mike Stump11289f42009-09-09 15:08:12 +00007180
Douglas Gregora16548e2009-08-11 05:31:07 +00007181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007182ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007183TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7184 // Transform the type.
7185 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7186 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007187 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007188
Douglas Gregor882211c2010-04-28 22:16:22 +00007189 // Transform all of the components into components similar to what the
7190 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007191 // FIXME: It would be slightly more efficient in the non-dependent case to
7192 // just map FieldDecls, rather than requiring the rebuilder to look for
7193 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007194 // template code that we don't care.
7195 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007196 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007197 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007198 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007199 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7200 const Node &ON = E->getComponent(I);
7201 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007202 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007203 Comp.LocStart = ON.getSourceRange().getBegin();
7204 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007205 switch (ON.getKind()) {
7206 case Node::Array: {
7207 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007208 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007209 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007210 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007211
Douglas Gregor882211c2010-04-28 22:16:22 +00007212 ExprChanged = ExprChanged || Index.get() != FromIndex;
7213 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007214 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007215 break;
7216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007217
Douglas Gregor882211c2010-04-28 22:16:22 +00007218 case Node::Field:
7219 case Node::Identifier:
7220 Comp.isBrackets = false;
7221 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007222 if (!Comp.U.IdentInfo)
7223 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007224
Douglas Gregor882211c2010-04-28 22:16:22 +00007225 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007226
Douglas Gregord1702062010-04-29 00:18:15 +00007227 case Node::Base:
7228 // Will be recomputed during the rebuild.
7229 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007231
Douglas Gregor882211c2010-04-28 22:16:22 +00007232 Components.push_back(Comp);
7233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007234
Douglas Gregor882211c2010-04-28 22:16:22 +00007235 // If nothing changed, retain the existing expression.
7236 if (!getDerived().AlwaysRebuild() &&
7237 Type == E->getTypeSourceInfo() &&
7238 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007239 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007240
Douglas Gregor882211c2010-04-28 22:16:22 +00007241 // Build a new offsetof expression.
7242 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7243 Components.data(), Components.size(),
7244 E->getRParenLoc());
7245}
7246
7247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007248ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007249TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7250 assert(getDerived().AlreadyTransformed(E->getType()) &&
7251 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007252 return E;
John McCall8d69a212010-11-15 23:31:06 +00007253}
7254
7255template<typename Derived>
7256ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007257TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007258 // Rebuild the syntactic form. The original syntactic form has
7259 // opaque-value expressions in it, so strip those away and rebuild
7260 // the result. This is a really awful way of doing this, but the
7261 // better solution (rebuilding the semantic expressions and
7262 // rebinding OVEs as necessary) doesn't work; we'd need
7263 // TreeTransform to not strip away implicit conversions.
7264 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7265 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007266 if (result.isInvalid()) return ExprError();
7267
7268 // If that gives us a pseudo-object result back, the pseudo-object
7269 // expression must have been an lvalue-to-rvalue conversion which we
7270 // should reapply.
7271 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007272 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007273
7274 return result;
7275}
7276
7277template<typename Derived>
7278ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007279TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7280 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007281 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007282 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007283
John McCallbcd03502009-12-07 02:54:59 +00007284 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007285 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007287
John McCall4c98fd82009-11-04 07:28:41 +00007288 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007289 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007290
Peter Collingbournee190dee2011-03-11 19:24:49 +00007291 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7292 E->getKind(),
7293 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 }
Mike Stump11289f42009-09-09 15:08:12 +00007295
Eli Friedmane4f22df2012-02-29 04:03:55 +00007296 // C++0x [expr.sizeof]p1:
7297 // The operand is either an expression, which is an unevaluated operand
7298 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7300 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007301
Reid Kleckner32506ed2014-06-12 23:03:48 +00007302 // Try to recover if we have something like sizeof(T::X) where X is a type.
7303 // Notably, there must be *exactly* one set of parens if X is a type.
7304 TypeSourceInfo *RecoveryTSI = nullptr;
7305 ExprResult SubExpr;
7306 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7307 if (auto *DRE =
7308 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7309 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7310 PE, DRE, false, &RecoveryTSI);
7311 else
7312 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7313
7314 if (RecoveryTSI) {
7315 return getDerived().RebuildUnaryExprOrTypeTrait(
7316 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7317 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007318 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007319
Eli Friedmane4f22df2012-02-29 04:03:55 +00007320 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007321 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007322
Peter Collingbournee190dee2011-03-11 19:24:49 +00007323 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7324 E->getOperatorLoc(),
7325 E->getKind(),
7326 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007327}
Mike Stump11289f42009-09-09 15:08:12 +00007328
Douglas Gregora16548e2009-08-11 05:31:07 +00007329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007331TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007332 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007333 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007334 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007335
John McCalldadc5752010-08-24 06:29:42 +00007336 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007337 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007339
7340
Douglas Gregora16548e2009-08-11 05:31:07 +00007341 if (!getDerived().AlwaysRebuild() &&
7342 LHS.get() == E->getLHS() &&
7343 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007344 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007345
John McCallb268a282010-08-23 23:25:46 +00007346 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007347 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007348 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007349 E->getRBracketLoc());
7350}
Mike Stump11289f42009-09-09 15:08:12 +00007351
7352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007354TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007356 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007358 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007359
7360 // Transform arguments.
7361 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007362 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007363 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007364 &ArgChanged))
7365 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007366
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 if (!getDerived().AlwaysRebuild() &&
7368 Callee.get() == E->getCallee() &&
7369 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007370 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007371
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007373 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007374 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007375 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007376 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007377 E->getRParenLoc());
7378}
Mike Stump11289f42009-09-09 15:08:12 +00007379
7380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007382TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007383 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007384 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregorea972d32011-02-28 21:54:11 +00007387 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007388 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007389 QualifierLoc
7390 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007391
Douglas Gregorea972d32011-02-28 21:54:11 +00007392 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007393 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007394 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007395 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007396
Eli Friedman2cfcef62009-12-04 06:40:45 +00007397 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007398 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7399 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007400 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007402
John McCall16df1e52010-03-30 21:47:33 +00007403 NamedDecl *FoundDecl = E->getFoundDecl();
7404 if (FoundDecl == E->getMemberDecl()) {
7405 FoundDecl = Member;
7406 } else {
7407 FoundDecl = cast_or_null<NamedDecl>(
7408 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7409 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007410 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007411 }
7412
Douglas Gregora16548e2009-08-11 05:31:07 +00007413 if (!getDerived().AlwaysRebuild() &&
7414 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007415 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007416 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007417 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007418 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007419
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007420 // Mark it referenced in the new context regardless.
7421 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007422 SemaRef.MarkMemberReferenced(E);
7423
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007424 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007425 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007426
John McCall6b51f282009-11-23 01:53:49 +00007427 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007428 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007429 TransArgs.setLAngleLoc(E->getLAngleLoc());
7430 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007431 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7432 E->getNumTemplateArgs(),
7433 TransArgs))
7434 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007436
Douglas Gregora16548e2009-08-11 05:31:07 +00007437 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007438 SourceLocation FakeOperatorLoc =
7439 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007440
John McCall38836f02010-01-15 08:34:02 +00007441 // FIXME: to do this check properly, we will need to preserve the
7442 // first-qualifier-in-scope here, just in case we had a dependent
7443 // base (and therefore couldn't do the check) and a
7444 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007445 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007446
John McCallb268a282010-08-23 23:25:46 +00007447 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007448 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007449 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007450 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007451 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007452 Member,
John McCall16df1e52010-03-30 21:47:33 +00007453 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007454 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007455 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007456 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007457}
Mike Stump11289f42009-09-09 15:08:12 +00007458
Douglas Gregora16548e2009-08-11 05:31:07 +00007459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007460ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007461TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007462 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007463 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007465
John McCalldadc5752010-08-24 06:29:42 +00007466 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007467 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007469
Douglas Gregora16548e2009-08-11 05:31:07 +00007470 if (!getDerived().AlwaysRebuild() &&
7471 LHS.get() == E->getLHS() &&
7472 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007473 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007474
Lang Hames5de91cc2012-10-02 04:45:10 +00007475 Sema::FPContractStateRAII FPContractState(getSema());
7476 getSema().FPFeatures.fp_contract = E->isFPContractable();
7477
Douglas Gregora16548e2009-08-11 05:31:07 +00007478 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007479 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007480}
7481
Mike Stump11289f42009-09-09 15:08:12 +00007482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007483ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007484TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007485 CompoundAssignOperator *E) {
7486 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007487}
Mike Stump11289f42009-09-09 15:08:12 +00007488
Douglas Gregora16548e2009-08-11 05:31:07 +00007489template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007490ExprResult TreeTransform<Derived>::
7491TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7492 // Just rebuild the common and RHS expressions and see whether we
7493 // get any changes.
7494
7495 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7496 if (commonExpr.isInvalid())
7497 return ExprError();
7498
7499 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7500 if (rhs.isInvalid())
7501 return ExprError();
7502
7503 if (!getDerived().AlwaysRebuild() &&
7504 commonExpr.get() == e->getCommon() &&
7505 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007506 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007507
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007508 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007509 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007510 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007511 e->getColonLoc(),
7512 rhs.get());
7513}
7514
7515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007516ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007517TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007518 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007519 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007521
John McCalldadc5752010-08-24 06:29:42 +00007522 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007523 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007525
John McCalldadc5752010-08-24 06:29:42 +00007526 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007529
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 if (!getDerived().AlwaysRebuild() &&
7531 Cond.get() == E->getCond() &&
7532 LHS.get() == E->getLHS() &&
7533 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007534 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007535
John McCallb268a282010-08-23 23:25:46 +00007536 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007537 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007538 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007539 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007540 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007541}
Mike Stump11289f42009-09-09 15:08:12 +00007542
7543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007545TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007546 // Implicit casts are eliminated during transformation, since they
7547 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007548 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007549}
Mike Stump11289f42009-09-09 15:08:12 +00007550
Douglas Gregora16548e2009-08-11 05:31:07 +00007551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007553TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007554 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7555 if (!Type)
7556 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007557
John McCalldadc5752010-08-24 06:29:42 +00007558 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007559 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007562
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007564 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007565 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007566 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007567
John McCall97513962010-01-15 18:39:57 +00007568 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007569 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007571 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007572}
Mike Stump11289f42009-09-09 15:08:12 +00007573
Douglas Gregora16548e2009-08-11 05:31:07 +00007574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007575ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007576TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007577 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7578 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7579 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007581
John McCalldadc5752010-08-24 06:29:42 +00007582 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007583 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007585
Douglas Gregora16548e2009-08-11 05:31:07 +00007586 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007587 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007589 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007590
John McCall5d7aa7f2010-01-19 22:33:45 +00007591 // Note: the expression type doesn't necessarily match the
7592 // type-as-written, but that's okay, because it should always be
7593 // derivable from the initializer.
7594
John McCalle15bbff2010-01-18 19:35:47 +00007595 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007597 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007598}
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregora16548e2009-08-11 05:31:07 +00007600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007601ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007602TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007603 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007604 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007606
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 if (!getDerived().AlwaysRebuild() &&
7608 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007609 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007610
Douglas Gregora16548e2009-08-11 05:31:07 +00007611 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007612 SourceLocation FakeOperatorLoc =
7613 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007614 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007615 E->getAccessorLoc(),
7616 E->getAccessor());
7617}
Mike Stump11289f42009-09-09 15:08:12 +00007618
Douglas Gregora16548e2009-08-11 05:31:07 +00007619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007621TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007622 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007623
Benjamin Kramerf0623432012-08-23 22:51:59 +00007624 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007625 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007626 Inits, &InitChanged))
7627 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007628
Douglas Gregora16548e2009-08-11 05:31:07 +00007629 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007630 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007631
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007632 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007633 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007634}
Mike Stump11289f42009-09-09 15:08:12 +00007635
Douglas Gregora16548e2009-08-11 05:31:07 +00007636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007638TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007639 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007640
Douglas Gregorebe10102009-08-20 07:17:43 +00007641 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007642 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007643 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007645
Douglas Gregorebe10102009-08-20 07:17:43 +00007646 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007647 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 bool ExprChanged = false;
7649 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7650 DEnd = E->designators_end();
7651 D != DEnd; ++D) {
7652 if (D->isFieldDesignator()) {
7653 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7654 D->getDotLoc(),
7655 D->getFieldLoc()));
7656 continue;
7657 }
Mike Stump11289f42009-09-09 15:08:12 +00007658
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007660 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007663
7664 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007665 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007666
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007668 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007669 continue;
7670 }
Mike Stump11289f42009-09-09 15:08:12 +00007671
Douglas Gregora16548e2009-08-11 05:31:07 +00007672 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007673 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7675 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007677
John McCalldadc5752010-08-24 06:29:42 +00007678 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007681
7682 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007683 End.get(),
7684 D->getLBracketLoc(),
7685 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007686
Douglas Gregora16548e2009-08-11 05:31:07 +00007687 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7688 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007689
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007690 ArrayExprs.push_back(Start.get());
7691 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007692 }
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 if (!getDerived().AlwaysRebuild() &&
7695 Init.get() == E->getInit() &&
7696 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007697 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007698
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007699 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007700 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007701 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007702}
Mike Stump11289f42009-09-09 15:08:12 +00007703
Douglas Gregora16548e2009-08-11 05:31:07 +00007704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007705ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007706TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007707 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007708 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007709
Douglas Gregor3da3c062009-10-28 00:29:27 +00007710 // FIXME: Will we ever have proper type location here? Will we actually
7711 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 QualType T = getDerived().TransformType(E->getType());
7713 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007715
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 if (!getDerived().AlwaysRebuild() &&
7717 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007718 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007719
Douglas Gregora16548e2009-08-11 05:31:07 +00007720 return getDerived().RebuildImplicitValueInitExpr(T);
7721}
Mike Stump11289f42009-09-09 15:08:12 +00007722
Douglas Gregora16548e2009-08-11 05:31:07 +00007723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007725TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007726 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7727 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007729
John McCalldadc5752010-08-24 06:29:42 +00007730 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007731 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007733
Douglas Gregora16548e2009-08-11 05:31:07 +00007734 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007735 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007736 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007737 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007738
John McCallb268a282010-08-23 23:25:46 +00007739 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007740 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007741}
7742
7743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007745TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007746 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007747 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007748 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7749 &ArgumentChanged))
7750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007751
Douglas Gregora16548e2009-08-11 05:31:07 +00007752 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007753 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007754 E->getRParenLoc());
7755}
Mike Stump11289f42009-09-09 15:08:12 +00007756
Douglas Gregora16548e2009-08-11 05:31:07 +00007757/// \brief Transform an address-of-label expression.
7758///
7759/// By default, the transformation of an address-of-label expression always
7760/// rebuilds the expression, so that the label identifier can be resolved to
7761/// the corresponding label statement by semantic analysis.
7762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007764TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007765 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7766 E->getLabel());
7767 if (!LD)
7768 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007769
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007771 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007772}
Mike Stump11289f42009-09-09 15:08:12 +00007773
7774template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007775ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007776TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007777 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007778 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007779 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007780 if (SubStmt.isInvalid()) {
7781 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007782 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007783 }
Mike Stump11289f42009-09-09 15:08:12 +00007784
Douglas Gregora16548e2009-08-11 05:31:07 +00007785 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007786 SubStmt.get() == E->getSubStmt()) {
7787 // Calling this an 'error' is unintuitive, but it does the right thing.
7788 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007789 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007790 }
Mike Stump11289f42009-09-09 15:08:12 +00007791
7792 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007793 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007794 E->getRParenLoc());
7795}
Mike Stump11289f42009-09-09 15:08:12 +00007796
Douglas Gregora16548e2009-08-11 05:31:07 +00007797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007799TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007800 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007801 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007803
John McCalldadc5752010-08-24 06:29:42 +00007804 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007807
John McCalldadc5752010-08-24 06:29:42 +00007808 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007809 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007811
Douglas Gregora16548e2009-08-11 05:31:07 +00007812 if (!getDerived().AlwaysRebuild() &&
7813 Cond.get() == E->getCond() &&
7814 LHS.get() == E->getLHS() &&
7815 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007816 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007817
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007819 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 E->getRParenLoc());
7821}
Mike Stump11289f42009-09-09 15:08:12 +00007822
Douglas Gregora16548e2009-08-11 05:31:07 +00007823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007825TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007826 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007827}
7828
7829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007830ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007831TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007832 switch (E->getOperator()) {
7833 case OO_New:
7834 case OO_Delete:
7835 case OO_Array_New:
7836 case OO_Array_Delete:
7837 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007838
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007839 case OO_Call: {
7840 // This is a call to an object's operator().
7841 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7842
7843 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007844 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007845 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007846 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007847
7848 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007849 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7850 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007851
7852 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007853 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007854 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007855 Args))
7856 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007857
John McCallb268a282010-08-23 23:25:46 +00007858 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007859 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007860 E->getLocEnd());
7861 }
7862
7863#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7864 case OO_##Name:
7865#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7866#include "clang/Basic/OperatorKinds.def"
7867 case OO_Subscript:
7868 // Handled below.
7869 break;
7870
7871 case OO_Conditional:
7872 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007873
7874 case OO_None:
7875 case NUM_OVERLOADED_OPERATORS:
7876 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007877 }
7878
John McCalldadc5752010-08-24 06:29:42 +00007879 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007880 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007882
Richard Smithdb2630f2012-10-21 03:28:35 +00007883 ExprResult First;
7884 if (E->getOperator() == OO_Amp)
7885 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7886 else
7887 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007888 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007889 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007890
John McCalldadc5752010-08-24 06:29:42 +00007891 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007892 if (E->getNumArgs() == 2) {
7893 Second = getDerived().TransformExpr(E->getArg(1));
7894 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007895 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007896 }
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 if (!getDerived().AlwaysRebuild() &&
7899 Callee.get() == E->getCallee() &&
7900 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007901 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007902 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007903
Lang Hames5de91cc2012-10-02 04:45:10 +00007904 Sema::FPContractStateRAII FPContractState(getSema());
7905 getSema().FPFeatures.fp_contract = E->isFPContractable();
7906
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7908 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007909 Callee.get(),
7910 First.get(),
7911 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007912}
Mike Stump11289f42009-09-09 15:08:12 +00007913
Douglas Gregora16548e2009-08-11 05:31:07 +00007914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007916TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7917 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007918}
Mike Stump11289f42009-09-09 15:08:12 +00007919
Douglas Gregora16548e2009-08-11 05:31:07 +00007920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007921ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007922TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7923 // Transform the callee.
7924 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7925 if (Callee.isInvalid())
7926 return ExprError();
7927
7928 // Transform exec config.
7929 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7930 if (EC.isInvalid())
7931 return ExprError();
7932
7933 // Transform arguments.
7934 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007935 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007936 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007937 &ArgChanged))
7938 return ExprError();
7939
7940 if (!getDerived().AlwaysRebuild() &&
7941 Callee.get() == E->getCallee() &&
7942 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007943 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007944
7945 // FIXME: Wrong source location information for the '('.
7946 SourceLocation FakeLParenLoc
7947 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7948 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007949 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007950 E->getRParenLoc(), EC.get());
7951}
7952
7953template<typename Derived>
7954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007955TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007956 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7957 if (!Type)
7958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007959
John McCalldadc5752010-08-24 06:29:42 +00007960 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007961 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007962 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007964
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007966 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007968 return E;
Nico Weberc153d242014-07-28 00:02:09 +00007969 return getDerived().RebuildCXXNamedCastExpr(
7970 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
7971 Type, E->getAngleBrackets().getEnd(),
7972 // FIXME. this should be '(' location
7973 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007974}
Mike Stump11289f42009-09-09 15:08:12 +00007975
Douglas Gregora16548e2009-08-11 05:31:07 +00007976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007978TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7979 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007980}
Mike Stump11289f42009-09-09 15:08:12 +00007981
7982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007984TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7985 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007986}
7987
Douglas Gregora16548e2009-08-11 05:31:07 +00007988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007989ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007990TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007991 CXXReinterpretCastExpr *E) {
7992 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007993}
Mike Stump11289f42009-09-09 15:08:12 +00007994
Douglas Gregora16548e2009-08-11 05:31:07 +00007995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007997TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7998 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007999}
Mike Stump11289f42009-09-09 15:08:12 +00008000
Douglas Gregora16548e2009-08-11 05:31:07 +00008001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008002ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008003TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008004 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008005 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8006 if (!Type)
8007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008008
John McCalldadc5752010-08-24 06:29:42 +00008009 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008010 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008011 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008013
Douglas Gregora16548e2009-08-11 05:31:07 +00008014 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008015 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008016 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008017 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008018
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008019 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008020 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008021 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008022 E->getRParenLoc());
8023}
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
John McCall47f29ea2009-12-08 09:21:05 +00008027TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008028 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008029 TypeSourceInfo *TInfo
8030 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8031 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008032 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008033
Douglas Gregora16548e2009-08-11 05:31:07 +00008034 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008035 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008036 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008037
Douglas Gregor9da64192010-04-26 22:37:10 +00008038 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8039 E->getLocStart(),
8040 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008041 E->getLocEnd());
8042 }
Mike Stump11289f42009-09-09 15:08:12 +00008043
Eli Friedman456f0182012-01-20 01:26:23 +00008044 // We don't know whether the subexpression is potentially evaluated until
8045 // after we perform semantic analysis. We speculatively assume it is
8046 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008047 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008048 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8049 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008050
John McCalldadc5752010-08-24 06:29:42 +00008051 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008052 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008054
Douglas Gregora16548e2009-08-11 05:31:07 +00008055 if (!getDerived().AlwaysRebuild() &&
8056 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008057 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008058
Douglas Gregor9da64192010-04-26 22:37:10 +00008059 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8060 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008061 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008062 E->getLocEnd());
8063}
8064
8065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008066ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008067TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8068 if (E->isTypeOperand()) {
8069 TypeSourceInfo *TInfo
8070 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8071 if (!TInfo)
8072 return ExprError();
8073
8074 if (!getDerived().AlwaysRebuild() &&
8075 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008076 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008077
Douglas Gregor69735112011-03-06 17:40:41 +00008078 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008079 E->getLocStart(),
8080 TInfo,
8081 E->getLocEnd());
8082 }
8083
Francois Pichet9f4f2072010-09-08 12:20:18 +00008084 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8085
8086 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8087 if (SubExpr.isInvalid())
8088 return ExprError();
8089
8090 if (!getDerived().AlwaysRebuild() &&
8091 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008092 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008093
8094 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8095 E->getLocStart(),
8096 SubExpr.get(),
8097 E->getLocEnd());
8098}
8099
8100template<typename Derived>
8101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008102TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008103 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008104}
Mike Stump11289f42009-09-09 15:08:12 +00008105
Douglas Gregora16548e2009-08-11 05:31:07 +00008106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008107ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008108TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008109 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008110 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008111}
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregora16548e2009-08-11 05:31:07 +00008113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008115TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008116 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008117
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008118 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8119 // Make sure that we capture 'this'.
8120 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008121 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008123
Douglas Gregorb15af892010-01-07 23:12:05 +00008124 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008125}
Mike Stump11289f42009-09-09 15:08:12 +00008126
Douglas Gregora16548e2009-08-11 05:31:07 +00008127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008129TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008130 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 if (!getDerived().AlwaysRebuild() &&
8135 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008136 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008137
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008138 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8139 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008140}
Mike Stump11289f42009-09-09 15:08:12 +00008141
Douglas Gregora16548e2009-08-11 05:31:07 +00008142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008144TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008145 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008146 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8147 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008148 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008150
Chandler Carruth794da4c2010-02-08 06:42:49 +00008151 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008152 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008153 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008154
Douglas Gregor033f6752009-12-23 23:03:06 +00008155 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008156}
Mike Stump11289f42009-09-09 15:08:12 +00008157
Douglas Gregora16548e2009-08-11 05:31:07 +00008158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008159ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008160TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8161 FieldDecl *Field
8162 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8163 E->getField()));
8164 if (!Field)
8165 return ExprError();
8166
8167 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008168 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008169
8170 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8171}
8172
8173template<typename Derived>
8174ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008175TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8176 CXXScalarValueInitExpr *E) {
8177 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8178 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008179 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008180
Douglas Gregora16548e2009-08-11 05:31:07 +00008181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008182 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008183 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008184
Chad Rosier1dcde962012-08-08 18:46:20 +00008185 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008186 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008187 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008188}
Mike Stump11289f42009-09-09 15:08:12 +00008189
Douglas Gregora16548e2009-08-11 05:31:07 +00008190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008192TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008193 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008194 TypeSourceInfo *AllocTypeInfo
8195 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8196 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008198
Douglas Gregora16548e2009-08-11 05:31:07 +00008199 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008200 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008201 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008203
Douglas Gregora16548e2009-08-11 05:31:07 +00008204 // Transform the placement arguments (if any).
8205 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008206 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008207 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008208 E->getNumPlacementArgs(), true,
8209 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008211
Sebastian Redl6047f072012-02-16 12:22:20 +00008212 // Transform the initializer (if any).
8213 Expr *OldInit = E->getInitializer();
8214 ExprResult NewInit;
8215 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008216 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008217 if (NewInit.isInvalid())
8218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008219
Sebastian Redl6047f072012-02-16 12:22:20 +00008220 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008221 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008222 if (E->getOperatorNew()) {
8223 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008224 getDerived().TransformDecl(E->getLocStart(),
8225 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008226 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008227 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008228 }
8229
Craig Topperc3ec1492014-05-26 06:22:03 +00008230 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008231 if (E->getOperatorDelete()) {
8232 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008233 getDerived().TransformDecl(E->getLocStart(),
8234 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008235 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008236 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008237 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008238
Douglas Gregora16548e2009-08-11 05:31:07 +00008239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008240 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008241 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008242 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008243 OperatorNew == E->getOperatorNew() &&
8244 OperatorDelete == E->getOperatorDelete() &&
8245 !ArgumentChanged) {
8246 // Mark any declarations we need as referenced.
8247 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008248 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008249 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008250 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008251 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008252
Sebastian Redl6047f072012-02-16 12:22:20 +00008253 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008254 QualType ElementType
8255 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8256 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8257 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8258 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008259 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008260 }
8261 }
8262 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008263
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008264 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008265 }
Mike Stump11289f42009-09-09 15:08:12 +00008266
Douglas Gregor0744ef62010-09-07 21:49:58 +00008267 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008268 if (!ArraySize.get()) {
8269 // If no array size was specified, but the new expression was
8270 // instantiated with an array type (e.g., "new T" where T is
8271 // instantiated with "int[4]"), extract the outer bound from the
8272 // array type as our array size. We do this with constant and
8273 // dependently-sized array types.
8274 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8275 if (!ArrayT) {
8276 // Do nothing
8277 } else if (const ConstantArrayType *ConsArrayT
8278 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008279 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8280 SemaRef.Context.getSizeType(),
8281 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008282 AllocType = ConsArrayT->getElementType();
8283 } else if (const DependentSizedArrayType *DepArrayT
8284 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8285 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008286 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008287 AllocType = DepArrayT->getElementType();
8288 }
8289 }
8290 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008291
Douglas Gregora16548e2009-08-11 05:31:07 +00008292 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8293 E->isGlobalNew(),
8294 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008295 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008297 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008298 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008299 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008300 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008301 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008302 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008303}
Mike Stump11289f42009-09-09 15:08:12 +00008304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008307TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008308 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008309 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008310 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008311
Douglas Gregord2d9da02010-02-26 00:38:10 +00008312 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008313 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008314 if (E->getOperatorDelete()) {
8315 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008316 getDerived().TransformDecl(E->getLocStart(),
8317 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008318 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008319 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008321
Douglas Gregora16548e2009-08-11 05:31:07 +00008322 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008323 Operand.get() == E->getArgument() &&
8324 OperatorDelete == E->getOperatorDelete()) {
8325 // Mark any declarations we need as referenced.
8326 // FIXME: instantiation-specific.
8327 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008328 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008329
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008330 if (!E->getArgument()->isTypeDependent()) {
8331 QualType Destroyed = SemaRef.Context.getBaseElementType(
8332 E->getDestroyedType());
8333 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8334 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008335 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008336 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008337 }
8338 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008339
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008340 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008341 }
Mike Stump11289f42009-09-09 15:08:12 +00008342
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8344 E->isGlobalDelete(),
8345 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008346 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008347}
Mike Stump11289f42009-09-09 15:08:12 +00008348
Douglas Gregora16548e2009-08-11 05:31:07 +00008349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008350ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008351TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008352 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008353 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008354 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008356
John McCallba7bf592010-08-24 05:47:05 +00008357 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008358 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008359 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008360 E->getOperatorLoc(),
8361 E->isArrow()? tok::arrow : tok::period,
8362 ObjectTypePtr,
8363 MayBePseudoDestructor);
8364 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008365 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008366
John McCallba7bf592010-08-24 05:47:05 +00008367 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008368 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8369 if (QualifierLoc) {
8370 QualifierLoc
8371 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8372 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008373 return ExprError();
8374 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008375 CXXScopeSpec SS;
8376 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008377
Douglas Gregor678f90d2010-02-25 01:56:36 +00008378 PseudoDestructorTypeStorage Destroyed;
8379 if (E->getDestroyedTypeInfo()) {
8380 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008381 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008382 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008383 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008384 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008385 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008386 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008387 // We aren't likely to be able to resolve the identifier down to a type
8388 // now anyway, so just retain the identifier.
8389 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8390 E->getDestroyedTypeLoc());
8391 } else {
8392 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008393 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008394 *E->getDestroyedTypeIdentifier(),
8395 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008396 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008397 SS, ObjectTypePtr,
8398 false);
8399 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008400 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008401
Douglas Gregor678f90d2010-02-25 01:56:36 +00008402 Destroyed
8403 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8404 E->getDestroyedTypeLoc());
8405 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008406
Craig Topperc3ec1492014-05-26 06:22:03 +00008407 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008408 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008409 CXXScopeSpec EmptySS;
8410 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008411 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008412 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008413 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008415
John McCallb268a282010-08-23 23:25:46 +00008416 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008417 E->getOperatorLoc(),
8418 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008419 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008420 ScopeTypeInfo,
8421 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008422 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008423 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008424}
Mike Stump11289f42009-09-09 15:08:12 +00008425
Douglas Gregorad8a3362009-09-04 17:36:40 +00008426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008427ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008428TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008429 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008430 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8431 Sema::LookupOrdinaryName);
8432
8433 // Transform all the decls.
8434 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8435 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008436 NamedDecl *InstD = static_cast<NamedDecl*>(
8437 getDerived().TransformDecl(Old->getNameLoc(),
8438 *I));
John McCall84d87672009-12-10 09:41:52 +00008439 if (!InstD) {
8440 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8441 // This can happen because of dependent hiding.
8442 if (isa<UsingShadowDecl>(*I))
8443 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008444 else {
8445 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008446 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008447 }
John McCall84d87672009-12-10 09:41:52 +00008448 }
John McCalle66edc12009-11-24 19:00:30 +00008449
8450 // Expand using declarations.
8451 if (isa<UsingDecl>(InstD)) {
8452 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008453 for (auto *I : UD->shadows())
8454 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008455 continue;
8456 }
8457
8458 R.addDecl(InstD);
8459 }
8460
8461 // Resolve a kind, but don't do any further analysis. If it's
8462 // ambiguous, the callee needs to deal with it.
8463 R.resolveKind();
8464
8465 // Rebuild the nested-name qualifier, if present.
8466 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008467 if (Old->getQualifierLoc()) {
8468 NestedNameSpecifierLoc QualifierLoc
8469 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8470 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008471 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008472
Douglas Gregor0da1d432011-02-28 20:01:57 +00008473 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008474 }
8475
Douglas Gregor9262f472010-04-27 18:19:34 +00008476 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008477 CXXRecordDecl *NamingClass
8478 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8479 Old->getNameLoc(),
8480 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008481 if (!NamingClass) {
8482 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008483 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008485
Douglas Gregorda7be082010-04-27 16:10:10 +00008486 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008487 }
8488
Abramo Bagnara7945c982012-01-27 09:46:47 +00008489 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8490
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008491 // If we have neither explicit template arguments, nor the template keyword,
8492 // it's a normal declaration name.
8493 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008494 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8495
8496 // If we have template arguments, rebuild them, then rebuild the
8497 // templateid expression.
8498 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008499 if (Old->hasExplicitTemplateArgs() &&
8500 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008501 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008502 TransArgs)) {
8503 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008504 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008505 }
John McCalle66edc12009-11-24 19:00:30 +00008506
Abramo Bagnara7945c982012-01-27 09:46:47 +00008507 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008508 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008509}
Mike Stump11289f42009-09-09 15:08:12 +00008510
Douglas Gregora16548e2009-08-11 05:31:07 +00008511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008512ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008513TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8514 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008515 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008516 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8517 TypeSourceInfo *From = E->getArg(I);
8518 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008519 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008520 TypeLocBuilder TLB;
8521 TLB.reserve(FromTL.getFullDataSize());
8522 QualType To = getDerived().TransformType(TLB, FromTL);
8523 if (To.isNull())
8524 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008525
Douglas Gregor29c42f22012-02-24 07:38:34 +00008526 if (To == From->getType())
8527 Args.push_back(From);
8528 else {
8529 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8530 ArgChanged = true;
8531 }
8532 continue;
8533 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008534
Douglas Gregor29c42f22012-02-24 07:38:34 +00008535 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008536
Douglas Gregor29c42f22012-02-24 07:38:34 +00008537 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008538 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008539 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8540 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8541 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008542
Douglas Gregor29c42f22012-02-24 07:38:34 +00008543 // Determine whether the set of unexpanded parameter packs can and should
8544 // be expanded.
8545 bool Expand = true;
8546 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008547 Optional<unsigned> OrigNumExpansions =
8548 ExpansionTL.getTypePtr()->getNumExpansions();
8549 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008550 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8551 PatternTL.getSourceRange(),
8552 Unexpanded,
8553 Expand, RetainExpansion,
8554 NumExpansions))
8555 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008556
Douglas Gregor29c42f22012-02-24 07:38:34 +00008557 if (!Expand) {
8558 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008559 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008560 // expansion.
8561 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008562
Douglas Gregor29c42f22012-02-24 07:38:34 +00008563 TypeLocBuilder TLB;
8564 TLB.reserve(From->getTypeLoc().getFullDataSize());
8565
8566 QualType To = getDerived().TransformType(TLB, PatternTL);
8567 if (To.isNull())
8568 return ExprError();
8569
Chad Rosier1dcde962012-08-08 18:46:20 +00008570 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008571 PatternTL.getSourceRange(),
8572 ExpansionTL.getEllipsisLoc(),
8573 NumExpansions);
8574 if (To.isNull())
8575 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008576
Douglas Gregor29c42f22012-02-24 07:38:34 +00008577 PackExpansionTypeLoc ToExpansionTL
8578 = TLB.push<PackExpansionTypeLoc>(To);
8579 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8580 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8581 continue;
8582 }
8583
8584 // Expand the pack expansion by substituting for each argument in the
8585 // pack(s).
8586 for (unsigned I = 0; I != *NumExpansions; ++I) {
8587 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8588 TypeLocBuilder TLB;
8589 TLB.reserve(PatternTL.getFullDataSize());
8590 QualType To = getDerived().TransformType(TLB, PatternTL);
8591 if (To.isNull())
8592 return ExprError();
8593
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008594 if (To->containsUnexpandedParameterPack()) {
8595 To = getDerived().RebuildPackExpansionType(To,
8596 PatternTL.getSourceRange(),
8597 ExpansionTL.getEllipsisLoc(),
8598 NumExpansions);
8599 if (To.isNull())
8600 return ExprError();
8601
8602 PackExpansionTypeLoc ToExpansionTL
8603 = TLB.push<PackExpansionTypeLoc>(To);
8604 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8605 }
8606
Douglas Gregor29c42f22012-02-24 07:38:34 +00008607 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008609
Douglas Gregor29c42f22012-02-24 07:38:34 +00008610 if (!RetainExpansion)
8611 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008612
Douglas Gregor29c42f22012-02-24 07:38:34 +00008613 // If we're supposed to retain a pack expansion, do so by temporarily
8614 // forgetting the partially-substituted parameter pack.
8615 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8616
8617 TypeLocBuilder TLB;
8618 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008619
Douglas Gregor29c42f22012-02-24 07:38:34 +00008620 QualType To = getDerived().TransformType(TLB, PatternTL);
8621 if (To.isNull())
8622 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008623
8624 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008625 PatternTL.getSourceRange(),
8626 ExpansionTL.getEllipsisLoc(),
8627 NumExpansions);
8628 if (To.isNull())
8629 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008630
Douglas Gregor29c42f22012-02-24 07:38:34 +00008631 PackExpansionTypeLoc ToExpansionTL
8632 = TLB.push<PackExpansionTypeLoc>(To);
8633 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8634 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008636
Douglas Gregor29c42f22012-02-24 07:38:34 +00008637 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008638 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008639
8640 return getDerived().RebuildTypeTrait(E->getTrait(),
8641 E->getLocStart(),
8642 Args,
8643 E->getLocEnd());
8644}
8645
8646template<typename Derived>
8647ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008648TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8649 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8650 if (!T)
8651 return ExprError();
8652
8653 if (!getDerived().AlwaysRebuild() &&
8654 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008655 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008656
8657 ExprResult SubExpr;
8658 {
8659 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8660 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8661 if (SubExpr.isInvalid())
8662 return ExprError();
8663
8664 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008665 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008666 }
8667
8668 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8669 E->getLocStart(),
8670 T,
8671 SubExpr.get(),
8672 E->getLocEnd());
8673}
8674
8675template<typename Derived>
8676ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008677TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8678 ExprResult SubExpr;
8679 {
8680 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8681 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8682 if (SubExpr.isInvalid())
8683 return ExprError();
8684
8685 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008686 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008687 }
8688
8689 return getDerived().RebuildExpressionTrait(
8690 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8691}
8692
Reid Kleckner32506ed2014-06-12 23:03:48 +00008693template <typename Derived>
8694ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8695 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8696 TypeSourceInfo **RecoveryTSI) {
8697 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8698 DRE, AddrTaken, RecoveryTSI);
8699
8700 // Propagate both errors and recovered types, which return ExprEmpty.
8701 if (!NewDRE.isUsable())
8702 return NewDRE;
8703
8704 // We got an expr, wrap it up in parens.
8705 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8706 return PE;
8707 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8708 PE->getRParen());
8709}
8710
8711template <typename Derived>
8712ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8713 DependentScopeDeclRefExpr *E) {
8714 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8715 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008716}
8717
8718template<typename Derived>
8719ExprResult
8720TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8721 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008722 bool IsAddressOfOperand,
8723 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008724 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008725 NestedNameSpecifierLoc QualifierLoc
8726 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8727 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008728 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008729 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008730
John McCall31f82722010-11-12 08:19:04 +00008731 // TODO: If this is a conversion-function-id, verify that the
8732 // destination type name (if present) resolves the same way after
8733 // instantiation as it did in the local scope.
8734
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008735 DeclarationNameInfo NameInfo
8736 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8737 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008738 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008739
John McCalle66edc12009-11-24 19:00:30 +00008740 if (!E->hasExplicitTemplateArgs()) {
8741 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008742 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008743 // Note: it is sufficient to compare the Name component of NameInfo:
8744 // if name has not changed, DNLoc has not changed either.
8745 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008746 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008747
Reid Kleckner32506ed2014-06-12 23:03:48 +00008748 return getDerived().RebuildDependentScopeDeclRefExpr(
8749 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8750 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008751 }
John McCall6b51f282009-11-23 01:53:49 +00008752
8753 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008754 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8755 E->getNumTemplateArgs(),
8756 TransArgs))
8757 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008758
Reid Kleckner32506ed2014-06-12 23:03:48 +00008759 return getDerived().RebuildDependentScopeDeclRefExpr(
8760 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8761 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008762}
8763
8764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008765ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008766TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008767 // CXXConstructExprs other than for list-initialization and
8768 // CXXTemporaryObjectExpr are always implicit, so when we have
8769 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008770 if ((E->getNumArgs() == 1 ||
8771 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008772 (!getDerived().DropCallArgument(E->getArg(0))) &&
8773 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008774 return getDerived().TransformExpr(E->getArg(0));
8775
Douglas Gregora16548e2009-08-11 05:31:07 +00008776 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8777
8778 QualType T = getDerived().TransformType(E->getType());
8779 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008780 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008781
8782 CXXConstructorDecl *Constructor
8783 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008784 getDerived().TransformDecl(E->getLocStart(),
8785 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008786 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008788
Douglas Gregora16548e2009-08-11 05:31:07 +00008789 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008790 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008791 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008792 &ArgumentChanged))
8793 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008794
Douglas Gregora16548e2009-08-11 05:31:07 +00008795 if (!getDerived().AlwaysRebuild() &&
8796 T == E->getType() &&
8797 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008798 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008799 // Mark the constructor as referenced.
8800 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008801 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008802 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008803 }
Mike Stump11289f42009-09-09 15:08:12 +00008804
Douglas Gregordb121ba2009-12-14 16:27:04 +00008805 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8806 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008807 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008808 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008809 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008810 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008811 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008812 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008813 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008814}
Mike Stump11289f42009-09-09 15:08:12 +00008815
Douglas Gregora16548e2009-08-11 05:31:07 +00008816/// \brief Transform a C++ temporary-binding expression.
8817///
Douglas Gregor363b1512009-12-24 18:51:59 +00008818/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8819/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008822TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008823 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008824}
Mike Stump11289f42009-09-09 15:08:12 +00008825
John McCall5d413782010-12-06 08:20:24 +00008826/// \brief Transform a C++ expression that contains cleanups that should
8827/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008828///
John McCall5d413782010-12-06 08:20:24 +00008829/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008830/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008832ExprResult
John McCall5d413782010-12-06 08:20:24 +00008833TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008834 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008835}
Mike Stump11289f42009-09-09 15:08:12 +00008836
Douglas Gregora16548e2009-08-11 05:31:07 +00008837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008838ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008839TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008840 CXXTemporaryObjectExpr *E) {
8841 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8842 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008844
Douglas Gregora16548e2009-08-11 05:31:07 +00008845 CXXConstructorDecl *Constructor
8846 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008847 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008848 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008849 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008851
Douglas Gregora16548e2009-08-11 05:31:07 +00008852 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008853 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008854 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008855 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008856 &ArgumentChanged))
8857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008858
Douglas Gregora16548e2009-08-11 05:31:07 +00008859 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008860 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008861 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008862 !ArgumentChanged) {
8863 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008864 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008865 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008867
Richard Smithd59b8322012-12-19 01:39:02 +00008868 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008869 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8870 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008871 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008872 E->getLocEnd());
8873}
Mike Stump11289f42009-09-09 15:08:12 +00008874
Douglas Gregora16548e2009-08-11 05:31:07 +00008875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008876ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008877TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008878
8879 // Transform any init-capture expressions before entering the scope of the
8880 // lambda body, because they are not semantically within that scope.
8881 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8882 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8883 E->explicit_capture_begin());
8884
8885 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8886 CEnd = E->capture_end();
8887 C != CEnd; ++C) {
8888 if (!C->isInitCapture())
8889 continue;
8890 EnterExpressionEvaluationContext EEEC(getSema(),
8891 Sema::PotentiallyEvaluated);
8892 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8893 C->getCapturedVar()->getInit(),
8894 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8895
8896 if (NewExprInitResult.isInvalid())
8897 return ExprError();
8898 Expr *NewExprInit = NewExprInitResult.get();
8899
8900 VarDecl *OldVD = C->getCapturedVar();
8901 QualType NewInitCaptureType =
8902 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8903 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8904 NewExprInit);
8905 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008906 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8907 std::make_pair(NewExprInitResult, NewInitCaptureType);
8908
8909 }
8910
Faisal Vali524ca282013-11-12 01:40:44 +00008911 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008912 // Transform the template parameters, and add them to the current
8913 // instantiation scope. The null case is handled correctly.
8914 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8915 E->getTemplateParameterList());
8916
8917 // Check to see if the TypeSourceInfo of the call operator needs to
8918 // be transformed, and if so do the transformation in the
8919 // CurrentInstantiationScope.
8920
8921 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8922 FunctionProtoTypeLoc OldCallOpFPTL =
8923 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008924 TypeSourceInfo *NewCallOpTSI = nullptr;
8925
Faisal Vali2cba1332013-10-23 06:44:28 +00008926 const bool CallOpWasAlreadyTransformed =
8927 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8928
8929 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8930 if (CallOpWasAlreadyTransformed)
8931 NewCallOpTSI = OldCallOpTSI;
8932 else {
8933 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8934 // The transformation MUST be done in the CurrentInstantiationScope since
8935 // it introduces a mapping of the original to the newly created
8936 // transformed parameters.
8937
8938 TypeLocBuilder NewCallOpTLBuilder;
Hans Wennborge113c202014-09-18 16:01:32 +00008939 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8940 OldCallOpFPTL,
8941 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008942 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8943 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008944 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008945 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8946 // the vector below - this will be used to synthesize the
8947 // NewCallOperator. Additionally, add the parameters of the untransformed
8948 // lambda call operator to the CurrentInstantiationScope.
8949 SmallVector<ParmVarDecl *, 4> Params;
8950 {
8951 FunctionProtoTypeLoc NewCallOpFPTL =
8952 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8953 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008954 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008955
8956 for (unsigned I = 0; I < NewNumArgs; ++I) {
8957 // If this call operator's type does not require transformation,
8958 // the parameters do not get added to the current instantiation scope,
8959 // - so ADD them! This allows the following to compile when the enclosing
8960 // template is specialized and the entire lambda expression has to be
8961 // transformed.
8962 // template<class T> void foo(T t) {
8963 // auto L = [](auto a) {
8964 // auto M = [](char b) { <-- note: non-generic lambda
8965 // auto N = [](auto c) {
8966 // int x = sizeof(a);
8967 // x = sizeof(b); <-- specifically this line
8968 // x = sizeof(c);
8969 // };
8970 // };
8971 // };
8972 // }
8973 // foo('a')
8974 if (CallOpWasAlreadyTransformed)
8975 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8976 NewParamDeclArray[I]);
8977 // Add to Params array, so these parameters can be used to create
8978 // the newly transformed call operator.
8979 Params.push_back(NewParamDeclArray[I]);
8980 }
8981 }
8982
8983 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008984 return ExprError();
8985
Eli Friedmand564afb2012-09-19 01:18:11 +00008986 // Create the local class that will describe the lambda.
8987 CXXRecordDecl *Class
8988 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008989 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008990 /*KnownDependent=*/false,
8991 E->getCaptureDefault());
8992
Eli Friedmand564afb2012-09-19 01:18:11 +00008993 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8994
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008995 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008996 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008997 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008998 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008999 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00009000 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00009001 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009002
Faisal Vali2cba1332013-10-23 06:44:28 +00009003 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9004
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009005 return getDerived().TransformLambdaScope(E, NewCallOperator,
9006 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00009007}
9008
9009template<typename Derived>
9010ExprResult
9011TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009012 CXXMethodDecl *CallOperator,
9013 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00009014 bool Invalid = false;
9015
Douglas Gregorb4328232012-02-14 00:00:48 +00009016 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009017 Sema::ContextRAII SavedContext(getSema(), CallOperator,
9018 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009019
Faisal Vali2b391ab2013-09-26 19:54:12 +00009020 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009021 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009022 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009023 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009024 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009025 E->hasExplicitParameters(),
9026 E->hasExplicitResultType(),
9027 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009028
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009029 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009030 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009031 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009032 CEnd = E->capture_end();
9033 C != CEnd; ++C) {
9034 // When we hit the first implicit capture, tell Sema that we've finished
9035 // the list of explicit captures.
9036 if (!FinishedExplicitCaptures && C->isImplicit()) {
9037 getSema().finishLambdaExplicitCaptures(LSI);
9038 FinishedExplicitCaptures = true;
9039 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009040
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009041 // Capturing 'this' is trivial.
9042 if (C->capturesThis()) {
9043 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9044 continue;
9045 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009046 // Captured expression will be recaptured during captured variables
9047 // rebuilding.
9048 if (C->capturesVLAType())
9049 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009050
Richard Smithba71c082013-05-16 06:20:58 +00009051 // Rebuild init-captures, including the implied field declaration.
9052 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009053
9054 InitCaptureInfoTy InitExprTypePair =
9055 InitCaptureExprsAndTypes[C - E->capture_begin()];
9056 ExprResult Init = InitExprTypePair.first;
9057 QualType InitQualType = InitExprTypePair.second;
9058 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009059 Invalid = true;
9060 continue;
9061 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009062 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009063 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9064 OldVD->getLocation(), InitExprTypePair.second,
9065 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009066 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009067 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009068 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009069 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009070 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009071 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009072 continue;
9073 }
9074
9075 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9076
Douglas Gregor3e308b12012-02-14 19:27:52 +00009077 // Determine the capture kind for Sema.
9078 Sema::TryCaptureKind Kind
9079 = C->isImplicit()? Sema::TryCapture_Implicit
9080 : C->getCaptureKind() == LCK_ByCopy
9081 ? Sema::TryCapture_ExplicitByVal
9082 : Sema::TryCapture_ExplicitByRef;
9083 SourceLocation EllipsisLoc;
9084 if (C->isPackExpansion()) {
9085 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9086 bool ShouldExpand = false;
9087 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009088 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009089 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9090 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009091 Unexpanded,
9092 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009093 NumExpansions)) {
9094 Invalid = true;
9095 continue;
9096 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009097
Douglas Gregor3e308b12012-02-14 19:27:52 +00009098 if (ShouldExpand) {
9099 // The transform has determined that we should perform an expansion;
9100 // transform and capture each of the arguments.
9101 // expansion of the pattern. Do so.
9102 VarDecl *Pack = C->getCapturedVar();
9103 for (unsigned I = 0; I != *NumExpansions; ++I) {
9104 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9105 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009106 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009107 Pack));
9108 if (!CapturedVar) {
9109 Invalid = true;
9110 continue;
9111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregor3e308b12012-02-14 19:27:52 +00009113 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009114 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9115 }
Richard Smith9467be42014-06-06 17:33:35 +00009116
9117 // FIXME: Retain a pack expansion if RetainExpansion is true.
9118
Douglas Gregor3e308b12012-02-14 19:27:52 +00009119 continue;
9120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
Douglas Gregor3e308b12012-02-14 19:27:52 +00009122 EllipsisLoc = C->getEllipsisLoc();
9123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009125 // Transform the captured variable.
9126 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009127 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009128 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009129 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009130 Invalid = true;
9131 continue;
9132 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009133
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009134 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009135 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009136 }
9137 if (!FinishedExplicitCaptures)
9138 getSema().finishLambdaExplicitCaptures(LSI);
9139
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009140
9141 // Enter a new evaluation context to insulate the lambda from any
9142 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009143 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009144
9145 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009146 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009147 /*IsInstantiation=*/true);
9148 return ExprError();
9149 }
9150
9151 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009152 StmtResult Body = getDerived().TransformStmt(E->getBody());
9153 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009154 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009155 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009156 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009157 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009158
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009159 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009160 /*CurScope=*/nullptr,
9161 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009162}
9163
9164template<typename Derived>
9165ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009166TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009167 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009168 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9169 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009171
Douglas Gregora16548e2009-08-11 05:31:07 +00009172 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009173 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009174 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009175 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009176 &ArgumentChanged))
9177 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009178
Douglas Gregora16548e2009-08-11 05:31:07 +00009179 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009180 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009182 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009183
Douglas Gregora16548e2009-08-11 05:31:07 +00009184 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009185 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009186 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009187 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009188 E->getRParenLoc());
9189}
Mike Stump11289f42009-09-09 15:08:12 +00009190
Douglas Gregora16548e2009-08-11 05:31:07 +00009191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009192ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009193TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009194 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009195 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009196 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009197 Expr *OldBase;
9198 QualType BaseType;
9199 QualType ObjectType;
9200 if (!E->isImplicitAccess()) {
9201 OldBase = E->getBase();
9202 Base = getDerived().TransformExpr(OldBase);
9203 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009204 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009205
John McCall2d74de92009-12-01 22:10:20 +00009206 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009207 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009208 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009209 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009210 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009211 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009212 ObjectTy,
9213 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009214 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009215 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009216
John McCallba7bf592010-08-24 05:47:05 +00009217 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009218 BaseType = ((Expr*) Base.get())->getType();
9219 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009220 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009221 BaseType = getDerived().TransformType(E->getBaseType());
9222 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9223 }
Mike Stump11289f42009-09-09 15:08:12 +00009224
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009225 // Transform the first part of the nested-name-specifier that qualifies
9226 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009227 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009228 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009229 E->getFirstQualifierFoundInScope(),
9230 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009231
Douglas Gregore16af532011-02-28 18:50:33 +00009232 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009233 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009234 QualifierLoc
9235 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9236 ObjectType,
9237 FirstQualifierInScope);
9238 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009239 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009240 }
Mike Stump11289f42009-09-09 15:08:12 +00009241
Abramo Bagnara7945c982012-01-27 09:46:47 +00009242 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9243
John McCall31f82722010-11-12 08:19:04 +00009244 // TODO: If this is a conversion-function-id, verify that the
9245 // destination type name (if present) resolves the same way after
9246 // instantiation as it did in the local scope.
9247
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009248 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009249 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009250 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009252
John McCall2d74de92009-12-01 22:10:20 +00009253 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009254 // This is a reference to a member without an explicitly-specified
9255 // template argument list. Optimize for this common case.
9256 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009257 Base.get() == OldBase &&
9258 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009259 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009260 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009261 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009262 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009263
John McCallb268a282010-08-23 23:25:46 +00009264 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009265 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009266 E->isArrow(),
9267 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009268 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009269 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009270 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009271 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009272 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009273 }
9274
John McCall6b51f282009-11-23 01:53:49 +00009275 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009276 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9277 E->getNumTemplateArgs(),
9278 TransArgs))
9279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009280
John McCallb268a282010-08-23 23:25:46 +00009281 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009282 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009283 E->isArrow(),
9284 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009285 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009286 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009287 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009288 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009289 &TransArgs);
9290}
9291
9292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009293ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009294TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009295 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009296 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009297 QualType BaseType;
9298 if (!Old->isImplicitAccess()) {
9299 Base = getDerived().TransformExpr(Old->getBase());
9300 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009301 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009302 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009303 Old->isArrow());
9304 if (Base.isInvalid())
9305 return ExprError();
9306 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009307 } else {
9308 BaseType = getDerived().TransformType(Old->getBaseType());
9309 }
John McCall10eae182009-11-30 22:42:35 +00009310
Douglas Gregor0da1d432011-02-28 20:01:57 +00009311 NestedNameSpecifierLoc QualifierLoc;
9312 if (Old->getQualifierLoc()) {
9313 QualifierLoc
9314 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9315 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009316 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009317 }
9318
Abramo Bagnara7945c982012-01-27 09:46:47 +00009319 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9320
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009321 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009322 Sema::LookupOrdinaryName);
9323
9324 // Transform all the decls.
9325 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9326 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009327 NamedDecl *InstD = static_cast<NamedDecl*>(
9328 getDerived().TransformDecl(Old->getMemberLoc(),
9329 *I));
John McCall84d87672009-12-10 09:41:52 +00009330 if (!InstD) {
9331 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9332 // This can happen because of dependent hiding.
9333 if (isa<UsingShadowDecl>(*I))
9334 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009335 else {
9336 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009337 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009338 }
John McCall84d87672009-12-10 09:41:52 +00009339 }
John McCall10eae182009-11-30 22:42:35 +00009340
9341 // Expand using declarations.
9342 if (isa<UsingDecl>(InstD)) {
9343 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009344 for (auto *I : UD->shadows())
9345 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009346 continue;
9347 }
9348
9349 R.addDecl(InstD);
9350 }
9351
9352 R.resolveKind();
9353
Douglas Gregor9262f472010-04-27 18:19:34 +00009354 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009355 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009356 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009357 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009358 Old->getMemberLoc(),
9359 Old->getNamingClass()));
9360 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009361 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009362
Douglas Gregorda7be082010-04-27 16:10:10 +00009363 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009365
John McCall10eae182009-11-30 22:42:35 +00009366 TemplateArgumentListInfo TransArgs;
9367 if (Old->hasExplicitTemplateArgs()) {
9368 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9369 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009370 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9371 Old->getNumTemplateArgs(),
9372 TransArgs))
9373 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009374 }
John McCall38836f02010-01-15 08:34:02 +00009375
9376 // FIXME: to do this check properly, we will need to preserve the
9377 // first-qualifier-in-scope here, just in case we had a dependent
9378 // base (and therefore couldn't do the check) and a
9379 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009380 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009381
John McCallb268a282010-08-23 23:25:46 +00009382 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009383 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009384 Old->getOperatorLoc(),
9385 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009386 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009387 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009388 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009389 R,
9390 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009391 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009392}
9393
9394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009395ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009396TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009398 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9399 if (SubExpr.isInvalid())
9400 return ExprError();
9401
9402 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009403 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009404
9405 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9406}
9407
9408template<typename Derived>
9409ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009410TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009411 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9412 if (Pattern.isInvalid())
9413 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009414
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009415 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009416 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009417
Douglas Gregorb8840002011-01-14 21:20:45 +00009418 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9419 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009420}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009421
9422template<typename Derived>
9423ExprResult
9424TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9425 // If E is not value-dependent, then nothing will change when we transform it.
9426 // Note: This is an instantiation-centric view.
9427 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009428 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009429
9430 // Note: None of the implementations of TryExpandParameterPacks can ever
9431 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009432 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009433 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9434 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009435 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009436 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009437 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009438 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009439 ShouldExpand, RetainExpansion,
9440 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009441 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009442
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009443 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009444 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009445
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009446 NamedDecl *Pack = E->getPack();
9447 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009448 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009449 Pack));
9450 if (!Pack)
9451 return ExprError();
9452 }
9453
Chad Rosier1dcde962012-08-08 18:46:20 +00009454
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009455 // We now know the length of the parameter pack, so build a new expression
9456 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009457 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9458 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009459 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009460}
9461
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009462template<typename Derived>
9463ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009464TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9465 SubstNonTypeTemplateParmPackExpr *E) {
9466 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009467 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009468}
9469
9470template<typename Derived>
9471ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009472TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9473 SubstNonTypeTemplateParmExpr *E) {
9474 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009475 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009476}
9477
9478template<typename Derived>
9479ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009480TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9481 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009482 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009483}
9484
9485template<typename Derived>
9486ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009487TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9488 MaterializeTemporaryExpr *E) {
9489 return getDerived().TransformExpr(E->GetTemporaryExpr());
9490}
Chad Rosier1dcde962012-08-08 18:46:20 +00009491
Douglas Gregorfe314812011-06-21 17:03:29 +00009492template<typename Derived>
9493ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009494TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9495 CXXStdInitializerListExpr *E) {
9496 return getDerived().TransformExpr(E->getSubExpr());
9497}
9498
9499template<typename Derived>
9500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009501TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009502 return SemaRef.MaybeBindToTemporary(E);
9503}
9504
9505template<typename Derived>
9506ExprResult
9507TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009508 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009509}
9510
9511template<typename Derived>
9512ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009513TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9514 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9515 if (SubExpr.isInvalid())
9516 return ExprError();
9517
9518 if (!getDerived().AlwaysRebuild() &&
9519 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009520 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009521
9522 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009523}
9524
9525template<typename Derived>
9526ExprResult
9527TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9528 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009529 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009530 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009531 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009532 /*IsCall=*/false, Elements, &ArgChanged))
9533 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009534
Ted Kremeneke65b0862012-03-06 20:05:56 +00009535 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9536 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009537
Ted Kremeneke65b0862012-03-06 20:05:56 +00009538 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9539 Elements.data(),
9540 Elements.size());
9541}
9542
9543template<typename Derived>
9544ExprResult
9545TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009546 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009547 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009548 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009549 bool ArgChanged = false;
9550 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9551 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009552
Ted Kremeneke65b0862012-03-06 20:05:56 +00009553 if (OrigElement.isPackExpansion()) {
9554 // This key/value element is a pack expansion.
9555 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9556 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9557 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9558 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9559
9560 // Determine whether the set of unexpanded parameter packs can
9561 // and should be expanded.
9562 bool Expand = true;
9563 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009564 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9565 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009566 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9567 OrigElement.Value->getLocEnd());
9568 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9569 PatternRange,
9570 Unexpanded,
9571 Expand, RetainExpansion,
9572 NumExpansions))
9573 return ExprError();
9574
9575 if (!Expand) {
9576 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009577 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009578 // expansion.
9579 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9580 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9581 if (Key.isInvalid())
9582 return ExprError();
9583
9584 if (Key.get() != OrigElement.Key)
9585 ArgChanged = true;
9586
9587 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9588 if (Value.isInvalid())
9589 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009590
Ted Kremeneke65b0862012-03-06 20:05:56 +00009591 if (Value.get() != OrigElement.Value)
9592 ArgChanged = true;
9593
Chad Rosier1dcde962012-08-08 18:46:20 +00009594 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009595 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9596 };
9597 Elements.push_back(Expansion);
9598 continue;
9599 }
9600
9601 // Record right away that the argument was changed. This needs
9602 // to happen even if the array expands to nothing.
9603 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009604
Ted Kremeneke65b0862012-03-06 20:05:56 +00009605 // The transform has determined that we should perform an elementwise
9606 // expansion of the pattern. Do so.
9607 for (unsigned I = 0; I != *NumExpansions; ++I) {
9608 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9609 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9610 if (Key.isInvalid())
9611 return ExprError();
9612
9613 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9614 if (Value.isInvalid())
9615 return ExprError();
9616
Chad Rosier1dcde962012-08-08 18:46:20 +00009617 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009618 Key.get(), Value.get(), SourceLocation(), NumExpansions
9619 };
9620
9621 // If any unexpanded parameter packs remain, we still have a
9622 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009623 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009624 if (Key.get()->containsUnexpandedParameterPack() ||
9625 Value.get()->containsUnexpandedParameterPack())
9626 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009627
Ted Kremeneke65b0862012-03-06 20:05:56 +00009628 Elements.push_back(Element);
9629 }
9630
Richard Smith9467be42014-06-06 17:33:35 +00009631 // FIXME: Retain a pack expansion if RetainExpansion is true.
9632
Ted Kremeneke65b0862012-03-06 20:05:56 +00009633 // We've finished with this pack expansion.
9634 continue;
9635 }
9636
9637 // Transform and check key.
9638 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9639 if (Key.isInvalid())
9640 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009641
Ted Kremeneke65b0862012-03-06 20:05:56 +00009642 if (Key.get() != OrigElement.Key)
9643 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009644
Ted Kremeneke65b0862012-03-06 20:05:56 +00009645 // Transform and check value.
9646 ExprResult Value
9647 = getDerived().TransformExpr(OrigElement.Value);
9648 if (Value.isInvalid())
9649 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009650
Ted Kremeneke65b0862012-03-06 20:05:56 +00009651 if (Value.get() != OrigElement.Value)
9652 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009653
9654 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009655 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009656 };
9657 Elements.push_back(Element);
9658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009659
Ted Kremeneke65b0862012-03-06 20:05:56 +00009660 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9661 return SemaRef.MaybeBindToTemporary(E);
9662
9663 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9664 Elements.data(),
9665 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009666}
9667
Mike Stump11289f42009-09-09 15:08:12 +00009668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009669ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009670TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009671 TypeSourceInfo *EncodedTypeInfo
9672 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9673 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009674 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009675
Douglas Gregora16548e2009-08-11 05:31:07 +00009676 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009677 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009678 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009679
9680 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009681 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009682 E->getRParenLoc());
9683}
Mike Stump11289f42009-09-09 15:08:12 +00009684
Douglas Gregora16548e2009-08-11 05:31:07 +00009685template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009686ExprResult TreeTransform<Derived>::
9687TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009688 // This is a kind of implicit conversion, and it needs to get dropped
9689 // and recomputed for the same general reasons that ImplicitCastExprs
9690 // do, as well a more specific one: this expression is only valid when
9691 // it appears *immediately* as an argument expression.
9692 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009693}
9694
9695template<typename Derived>
9696ExprResult TreeTransform<Derived>::
9697TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009698 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009699 = getDerived().TransformType(E->getTypeInfoAsWritten());
9700 if (!TSInfo)
9701 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009702
John McCall31168b02011-06-15 23:02:42 +00009703 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009704 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009705 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009706
John McCall31168b02011-06-15 23:02:42 +00009707 if (!getDerived().AlwaysRebuild() &&
9708 TSInfo == E->getTypeInfoAsWritten() &&
9709 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009710 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009711
John McCall31168b02011-06-15 23:02:42 +00009712 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009713 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009714 Result.get());
9715}
9716
9717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009718ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009719TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009720 // Transform arguments.
9721 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009722 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009723 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009724 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009725 &ArgChanged))
9726 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009727
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009728 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9729 // Class message: transform the receiver type.
9730 TypeSourceInfo *ReceiverTypeInfo
9731 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9732 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009733 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009734
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009735 // If nothing changed, just retain the existing message send.
9736 if (!getDerived().AlwaysRebuild() &&
9737 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009738 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009739
9740 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009741 SmallVector<SourceLocation, 16> SelLocs;
9742 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009743 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9744 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009745 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009746 E->getMethodDecl(),
9747 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009748 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009749 E->getRightLoc());
9750 }
9751
9752 // Instance message: transform the receiver
9753 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9754 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009755 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009756 = getDerived().TransformExpr(E->getInstanceReceiver());
9757 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009758 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009759
9760 // If nothing changed, just retain the existing message send.
9761 if (!getDerived().AlwaysRebuild() &&
9762 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009763 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009764
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009765 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009766 SmallVector<SourceLocation, 16> SelLocs;
9767 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009768 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009769 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009770 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009771 E->getMethodDecl(),
9772 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009773 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009774 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009775}
9776
Mike Stump11289f42009-09-09 15:08:12 +00009777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009779TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009780 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009781}
9782
Mike Stump11289f42009-09-09 15:08:12 +00009783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009785TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009786 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009787}
9788
Mike Stump11289f42009-09-09 15:08:12 +00009789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009791TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009792 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009793 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009794 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009795 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009796
9797 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009798
Douglas Gregord51d90d2010-04-26 20:11:03 +00009799 // If nothing changed, just retain the existing expression.
9800 if (!getDerived().AlwaysRebuild() &&
9801 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009803
John McCallb268a282010-08-23 23:25:46 +00009804 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009805 E->getLocation(),
9806 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009807}
9808
Mike Stump11289f42009-09-09 15:08:12 +00009809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009811TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009812 // 'super' and types never change. Property never changes. Just
9813 // retain the existing expression.
9814 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009815 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009816
Douglas Gregor9faee212010-04-26 20:47:02 +00009817 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009818 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009819 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009820 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009821
Douglas Gregor9faee212010-04-26 20:47:02 +00009822 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009823
Douglas Gregor9faee212010-04-26 20:47:02 +00009824 // If nothing changed, just retain the existing expression.
9825 if (!getDerived().AlwaysRebuild() &&
9826 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009827 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009828
John McCallb7bd14f2010-12-02 01:19:52 +00009829 if (E->isExplicitProperty())
9830 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9831 E->getExplicitProperty(),
9832 E->getLocation());
9833
9834 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009835 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009836 E->getImplicitPropertyGetter(),
9837 E->getImplicitPropertySetter(),
9838 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009839}
9840
Mike Stump11289f42009-09-09 15:08:12 +00009841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009842ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009843TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9844 // Transform the base expression.
9845 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9846 if (Base.isInvalid())
9847 return ExprError();
9848
9849 // Transform the key expression.
9850 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9851 if (Key.isInvalid())
9852 return ExprError();
9853
9854 // If nothing changed, just retain the existing expression.
9855 if (!getDerived().AlwaysRebuild() &&
9856 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009857 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009858
Chad Rosier1dcde962012-08-08 18:46:20 +00009859 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009860 Base.get(), Key.get(),
9861 E->getAtIndexMethodDecl(),
9862 E->setAtIndexMethodDecl());
9863}
9864
9865template<typename Derived>
9866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009867TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009868 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009869 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009870 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009871 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009872
Douglas Gregord51d90d2010-04-26 20:11:03 +00009873 // If nothing changed, just retain the existing expression.
9874 if (!getDerived().AlwaysRebuild() &&
9875 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009876 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009877
John McCallb268a282010-08-23 23:25:46 +00009878 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009879 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009880 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009881}
9882
Mike Stump11289f42009-09-09 15:08:12 +00009883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009885TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009886 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009887 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009888 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009889 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009890 SubExprs, &ArgumentChanged))
9891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009892
Douglas Gregora16548e2009-08-11 05:31:07 +00009893 if (!getDerived().AlwaysRebuild() &&
9894 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009895 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009896
Douglas Gregora16548e2009-08-11 05:31:07 +00009897 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009898 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009899 E->getRParenLoc());
9900}
9901
Mike Stump11289f42009-09-09 15:08:12 +00009902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009903ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009904TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9905 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9906 if (SrcExpr.isInvalid())
9907 return ExprError();
9908
9909 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9910 if (!Type)
9911 return ExprError();
9912
9913 if (!getDerived().AlwaysRebuild() &&
9914 Type == E->getTypeSourceInfo() &&
9915 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009916 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009917
9918 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9919 SrcExpr.get(), Type,
9920 E->getRParenLoc());
9921}
9922
9923template<typename Derived>
9924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009925TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009926 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009927
Craig Topperc3ec1492014-05-26 06:22:03 +00009928 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009929 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9930
9931 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009932 blockScope->TheDecl->setBlockMissingReturnType(
9933 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009934
Chris Lattner01cf8db2011-07-20 06:58:45 +00009935 SmallVector<ParmVarDecl*, 4> params;
9936 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009937
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009938 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009939 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9940 oldBlock->param_begin(),
9941 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009942 nullptr, paramTypes, &params)) {
9943 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009944 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009945 }
John McCall490112f2011-02-04 18:33:18 +00009946
Jordan Rosea0a86be2013-03-08 22:25:36 +00009947 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009948 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009949 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009950
Jordan Rose5c382722013-03-08 21:51:21 +00009951 QualType functionType =
9952 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009953 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009954 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009955
9956 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009957 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009958 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009959
9960 if (!oldBlock->blockMissingReturnType()) {
9961 blockScope->HasImplicitReturnType = false;
9962 blockScope->ReturnType = exprResultType;
9963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009964
John McCall3882ace2011-01-05 12:14:39 +00009965 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009966 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009967 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009968 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009969 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009970 }
John McCall3882ace2011-01-05 12:14:39 +00009971
John McCall490112f2011-02-04 18:33:18 +00009972#ifndef NDEBUG
9973 // In builds with assertions, make sure that we captured everything we
9974 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009975 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009976 for (const auto &I : oldBlock->captures()) {
9977 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009978
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009979 // Ignore parameter packs.
9980 if (isa<ParmVarDecl>(oldCapture) &&
9981 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9982 continue;
John McCall490112f2011-02-04 18:33:18 +00009983
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009984 VarDecl *newCapture =
9985 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9986 oldCapture));
9987 assert(blockScope->CaptureMap.count(newCapture));
9988 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009989 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009990 }
9991#endif
9992
9993 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009994 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009995}
9996
Mike Stump11289f42009-09-09 15:08:12 +00009997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009998ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009999TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010000 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010001}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010002
10003template<typename Derived>
10004ExprResult
10005TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010006 QualType RetTy = getDerived().TransformType(E->getType());
10007 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010008 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010009 SubExprs.reserve(E->getNumSubExprs());
10010 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10011 SubExprs, &ArgumentChanged))
10012 return ExprError();
10013
10014 if (!getDerived().AlwaysRebuild() &&
10015 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010016 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010017
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010018 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010019 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010020}
Chad Rosier1dcde962012-08-08 18:46:20 +000010021
Douglas Gregora16548e2009-08-11 05:31:07 +000010022//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010023// Type reconstruction
10024//===----------------------------------------------------------------------===//
10025
Mike Stump11289f42009-09-09 15:08:12 +000010026template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010027QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10028 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010029 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010030 getDerived().getBaseEntity());
10031}
10032
Mike Stump11289f42009-09-09 15:08:12 +000010033template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010034QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10035 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010036 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010037 getDerived().getBaseEntity());
10038}
10039
Mike Stump11289f42009-09-09 15:08:12 +000010040template<typename Derived>
10041QualType
John McCall70dd5f62009-10-30 00:06:24 +000010042TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10043 bool WrittenAsLValue,
10044 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010045 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010046 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010047}
10048
10049template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010050QualType
John McCall70dd5f62009-10-30 00:06:24 +000010051TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10052 QualType ClassType,
10053 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010054 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10055 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010056}
10057
10058template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010059QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010060TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10061 ArrayType::ArraySizeModifier SizeMod,
10062 const llvm::APInt *Size,
10063 Expr *SizeExpr,
10064 unsigned IndexTypeQuals,
10065 SourceRange BracketsRange) {
10066 if (SizeExpr || !Size)
10067 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10068 IndexTypeQuals, BracketsRange,
10069 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010070
10071 QualType Types[] = {
10072 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10073 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10074 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010075 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010076 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010077 QualType SizeType;
10078 for (unsigned I = 0; I != NumTypes; ++I)
10079 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10080 SizeType = Types[I];
10081 break;
10082 }
Mike Stump11289f42009-09-09 15:08:12 +000010083
Eli Friedman9562f392012-01-25 23:20:27 +000010084 // Note that we can return a VariableArrayType here in the case where
10085 // the element type was a dependent VariableArrayType.
10086 IntegerLiteral *ArraySize
10087 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10088 /*FIXME*/BracketsRange.getBegin());
10089 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010090 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010091 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010092}
Mike Stump11289f42009-09-09 15:08:12 +000010093
Douglas Gregord6ff3322009-08-04 16:50:30 +000010094template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010095QualType
10096TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010097 ArrayType::ArraySizeModifier SizeMod,
10098 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010099 unsigned IndexTypeQuals,
10100 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010101 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010102 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010103}
10104
10105template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010106QualType
Mike Stump11289f42009-09-09 15:08:12 +000010107TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010108 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010109 unsigned IndexTypeQuals,
10110 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010111 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010112 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010113}
Mike Stump11289f42009-09-09 15:08:12 +000010114
Douglas Gregord6ff3322009-08-04 16:50:30 +000010115template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010116QualType
10117TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010118 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010119 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010120 unsigned IndexTypeQuals,
10121 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010122 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010123 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010124 IndexTypeQuals, BracketsRange);
10125}
10126
10127template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010128QualType
10129TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010130 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010131 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010132 unsigned IndexTypeQuals,
10133 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010134 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010135 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010136 IndexTypeQuals, BracketsRange);
10137}
10138
10139template<typename Derived>
10140QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010141 unsigned NumElements,
10142 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010143 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010144 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010145}
Mike Stump11289f42009-09-09 15:08:12 +000010146
Douglas Gregord6ff3322009-08-04 16:50:30 +000010147template<typename Derived>
10148QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10149 unsigned NumElements,
10150 SourceLocation AttributeLoc) {
10151 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10152 NumElements, true);
10153 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010154 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10155 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010156 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010157}
Mike Stump11289f42009-09-09 15:08:12 +000010158
Douglas Gregord6ff3322009-08-04 16:50:30 +000010159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010160QualType
10161TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010162 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010163 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010164 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010165}
Mike Stump11289f42009-09-09 15:08:12 +000010166
Douglas Gregord6ff3322009-08-04 16:50:30 +000010167template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010168QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10169 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010170 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010171 const FunctionProtoType::ExtProtoInfo &EPI) {
10172 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010173 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010174 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010175 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010176}
Mike Stump11289f42009-09-09 15:08:12 +000010177
Douglas Gregord6ff3322009-08-04 16:50:30 +000010178template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010179QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10180 return SemaRef.Context.getFunctionNoProtoType(T);
10181}
10182
10183template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010184QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10185 assert(D && "no decl found");
10186 if (D->isInvalidDecl()) return QualType();
10187
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010188 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010189 TypeDecl *Ty;
10190 if (isa<UsingDecl>(D)) {
10191 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010192 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010193 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10194
10195 // A valid resolved using typename decl points to exactly one type decl.
10196 assert(++Using->shadow_begin() == Using->shadow_end());
10197 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010198
John McCallb96ec562009-12-04 22:46:56 +000010199 } else {
10200 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10201 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10202 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10203 }
10204
10205 return SemaRef.Context.getTypeDeclType(Ty);
10206}
10207
10208template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010209QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10210 SourceLocation Loc) {
10211 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010212}
10213
10214template<typename Derived>
10215QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10216 return SemaRef.Context.getTypeOfType(Underlying);
10217}
10218
10219template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010220QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10221 SourceLocation Loc) {
10222 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010223}
10224
10225template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010226QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10227 UnaryTransformType::UTTKind UKind,
10228 SourceLocation Loc) {
10229 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10230}
10231
10232template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010233QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010234 TemplateName Template,
10235 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010236 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010237 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010238}
Mike Stump11289f42009-09-09 15:08:12 +000010239
Douglas Gregor1135c352009-08-06 05:28:30 +000010240template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010241QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10242 SourceLocation KWLoc) {
10243 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10244}
10245
10246template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010247TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010248TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010249 bool TemplateKW,
10250 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010251 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010252 Template);
10253}
10254
10255template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010256TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010257TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10258 const IdentifierInfo &Name,
10259 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010260 QualType ObjectType,
10261 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010262 UnqualifiedId TemplateName;
10263 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010264 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010265 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010266 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010267 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010268 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010269 /*EnteringContext=*/false,
10270 Template);
John McCall31f82722010-11-12 08:19:04 +000010271 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010272}
Mike Stump11289f42009-09-09 15:08:12 +000010273
Douglas Gregora16548e2009-08-11 05:31:07 +000010274template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010275TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010276TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010277 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010278 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010279 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010280 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010281 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010282 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010283 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010284 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010285 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010286 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010287 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010288 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010289 /*EnteringContext=*/false,
10290 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010291 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010292}
Chad Rosier1dcde962012-08-08 18:46:20 +000010293
Douglas Gregor71395fa2009-11-04 00:56:37 +000010294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010295ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010296TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10297 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010298 Expr *OrigCallee,
10299 Expr *First,
10300 Expr *Second) {
10301 Expr *Callee = OrigCallee->IgnoreParenCasts();
10302 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010303
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010304 if (First->getObjectKind() == OK_ObjCProperty) {
10305 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10306 if (BinaryOperator::isAssignmentOp(Opc))
10307 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10308 First, Second);
10309 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10310 if (Result.isInvalid())
10311 return ExprError();
10312 First = Result.get();
10313 }
10314
10315 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10316 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10317 if (Result.isInvalid())
10318 return ExprError();
10319 Second = Result.get();
10320 }
10321
Douglas Gregora16548e2009-08-11 05:31:07 +000010322 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010323 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010324 if (!First->getType()->isOverloadableType() &&
10325 !Second->getType()->isOverloadableType())
10326 return getSema().CreateBuiltinArraySubscriptExpr(First,
10327 Callee->getLocStart(),
10328 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010329 } else if (Op == OO_Arrow) {
10330 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010331 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10332 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010333 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010334 // The argument is not of overloadable type, so try to create a
10335 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010336 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010337 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010338
John McCallb268a282010-08-23 23:25:46 +000010339 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010340 }
10341 } else {
John McCallb268a282010-08-23 23:25:46 +000010342 if (!First->getType()->isOverloadableType() &&
10343 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010344 // Neither of the arguments is an overloadable type, so try to
10345 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010346 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010347 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010348 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010349 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010351
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010352 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010353 }
10354 }
Mike Stump11289f42009-09-09 15:08:12 +000010355
10356 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010357 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010358 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010359
John McCallb268a282010-08-23 23:25:46 +000010360 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010361 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010362 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010363 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010364 // If we've resolved this to a particular non-member function, just call
10365 // that function. If we resolved it to a member function,
10366 // CreateOverloaded* will find that function for us.
10367 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10368 if (!isa<CXXMethodDecl>(ND))
10369 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010370 }
Mike Stump11289f42009-09-09 15:08:12 +000010371
Douglas Gregora16548e2009-08-11 05:31:07 +000010372 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010373 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010374 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010375
Douglas Gregora16548e2009-08-11 05:31:07 +000010376 // Create the overloaded operator invocation for unary operators.
10377 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010378 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010379 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010380 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010381 }
Mike Stump11289f42009-09-09 15:08:12 +000010382
Douglas Gregore9d62932011-07-15 16:25:15 +000010383 if (Op == OO_Subscript) {
10384 SourceLocation LBrace;
10385 SourceLocation RBrace;
10386
10387 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10388 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10389 LBrace = SourceLocation::getFromRawEncoding(
10390 NameLoc.CXXOperatorName.BeginOpNameLoc);
10391 RBrace = SourceLocation::getFromRawEncoding(
10392 NameLoc.CXXOperatorName.EndOpNameLoc);
10393 } else {
10394 LBrace = Callee->getLocStart();
10395 RBrace = OpLoc;
10396 }
10397
10398 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10399 First, Second);
10400 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010401
Douglas Gregora16548e2009-08-11 05:31:07 +000010402 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010403 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010404 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010405 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10406 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010408
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010409 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010410}
Mike Stump11289f42009-09-09 15:08:12 +000010411
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010412template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010413ExprResult
John McCallb268a282010-08-23 23:25:46 +000010414TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010415 SourceLocation OperatorLoc,
10416 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010417 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010418 TypeSourceInfo *ScopeType,
10419 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010420 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010421 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010422 QualType BaseType = Base->getType();
10423 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010424 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010425 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010426 !BaseType->getAs<PointerType>()->getPointeeType()
10427 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010428 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010429 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010430 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010431 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010432 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010433 /*FIXME?*/true);
10434 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010435
Douglas Gregor678f90d2010-02-25 01:56:36 +000010436 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010437 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10438 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10439 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10440 NameInfo.setNamedTypeInfo(DestroyedType);
10441
Richard Smith8e4a3862012-05-15 06:15:11 +000010442 // The scope type is now known to be a valid nested name specifier
10443 // component. Tack it on to the end of the nested name specifier.
10444 if (ScopeType)
10445 SS.Extend(SemaRef.Context, SourceLocation(),
10446 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010447
Abramo Bagnara7945c982012-01-27 09:46:47 +000010448 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010449 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010450 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010451 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010452 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010453 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010454 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010455}
10456
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010457template<typename Derived>
10458StmtResult
10459TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010460 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010461 CapturedDecl *CD = S->getCapturedDecl();
10462 unsigned NumParams = CD->getNumParams();
10463 unsigned ContextParamPos = CD->getContextParamPosition();
10464 SmallVector<Sema::CapturedParamNameType, 4> Params;
10465 for (unsigned I = 0; I < NumParams; ++I) {
10466 if (I != ContextParamPos) {
10467 Params.push_back(
10468 std::make_pair(
10469 CD->getParam(I)->getName(),
10470 getDerived().TransformType(CD->getParam(I)->getType())));
10471 } else {
10472 Params.push_back(std::make_pair(StringRef(), QualType()));
10473 }
10474 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010475 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010476 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010477 StmtResult Body;
10478 {
10479 Sema::CompoundScopeRAII CompoundScope(getSema());
10480 Body = getDerived().TransformStmt(S->getCapturedStmt());
10481 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010482
10483 if (Body.isInvalid()) {
10484 getSema().ActOnCapturedRegionError();
10485 return StmtError();
10486 }
10487
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010488 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010489}
10490
Douglas Gregord6ff3322009-08-04 16:50:30 +000010491} // end namespace clang
10492
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010493#endif